nuit_core/compose/shape/
shape.rs

1use crate::{Bind, Context, Event, IdPath, Node, ShapeNode, View};
2
3/// A composable shape component.
4pub trait Shape {
5    type Body: Shape = NeverShape;
6
7    fn body(&self) -> Self::Body {
8        panic!("Shape does not have a body!")
9    }
10
11    fn render(&self) -> ShapeNode {
12        Shape::render(&self.body())
13    }
14}
15
16/// A shape type that can never be constructed.
17pub enum NeverShape {}
18
19impl Shape for NeverShape {}
20
21impl<T> Bind for T where T: Shape {}
22
23impl<T> View for T where T: Shape {
24    fn fire(&self, _event: &Event, _id_path: &IdPath, _context: &Context) {}
25
26    fn render(&self, _context: &Context) -> Node {
27        Node::Shape {
28            shape: Shape::render(self)
29        }
30    }
31}