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 _: RectF,
56 _: &mut Self::LayoutState,
57 _: &mut Self::PaintState,
58 _: &mut EventContext,
59 ) -> bool {
60 false
61 }
62
63 fn debug(
64 &self,
65 bounds: RectF,
66 _: &Self::LayoutState,
67 _: &Self::PaintState,
68 _: &DebugContext,
69 ) -> serde_json::Value {
70 json!({
71 "type": "Empty",
72 "bounds": bounds.to_json(),
73 })
74 }
75}