empty.rs

 1use crate::{
 2    geometry::{
 3        rect::RectF,
 4        vector::{vec2f, Vector2F},
 5    },
 6    json::{json, ToJson},
 7    DebugContext,
 8};
 9use crate::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
10
11pub struct Empty;
12
13impl Empty {
14    pub fn new() -> Self {
15        Self
16    }
17}
18
19impl Element for Empty {
20    type LayoutState = ();
21    type PaintState = ();
22
23    fn layout(
24        &mut self,
25        constraint: SizeConstraint,
26        _: &mut LayoutContext,
27    ) -> (Vector2F, Self::LayoutState) {
28        let x = if constraint.max.x().is_finite() {
29            constraint.max.x()
30        } else {
31            constraint.min.x()
32        };
33        let y = if constraint.max.y().is_finite() {
34            constraint.max.y()
35        } else {
36            constraint.min.y()
37        };
38
39        (vec2f(x, y), ())
40    }
41
42    fn paint(
43        &mut self,
44        _: RectF,
45        _: RectF,
46        _: &mut Self::LayoutState,
47        _: &mut PaintContext,
48    ) -> Self::PaintState {
49    }
50
51    fn dispatch_event(
52        &mut self,
53        _: &Event,
54        _: RectF,
55        _: &mut Self::LayoutState,
56        _: &mut Self::PaintState,
57        _: &mut EventContext,
58    ) -> bool {
59        false
60    }
61
62    fn debug(
63        &self,
64        bounds: RectF,
65        _: &Self::LayoutState,
66        _: &Self::PaintState,
67        _: &DebugContext,
68    ) -> serde_json::Value {
69        json!({
70            "type": "Empty",
71            "bounds": bounds.to_json(),
72        })
73    }
74}