1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::{Bind, Context, Event, IdPath, Node, ShapeNode, View};

/// A composable shape component.
pub trait Shape {
    type Body: Shape = NeverShape;

    fn body(&self) -> Self::Body {
        panic!("Shape does not have a body!")
    }

    fn render(&self) -> ShapeNode {
        Shape::render(&self.body())
    }
}

/// A shape type that can never be constructed.
pub enum NeverShape {}

impl Shape for NeverShape {}

impl<T> Bind for T where T: Shape {}

impl<T> View for T where T: Shape {
    fn fire(&self, _event: &Event, _id_path: &IdPath) {}

    fn render(&self, _context: &Context) -> Node {
        Node::Shape {
            shape: Shape::render(self)
        }
    }
}