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