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 _: &mut Self::LayoutState,
46 _: &mut PaintContext,
47 ) -> Self::PaintState {
48 }
49
50 fn dispatch_event(
51 &mut self,
52 _: &Event,
53 _: RectF,
54 _: &mut Self::LayoutState,
55 _: &mut Self::PaintState,
56 _: &mut EventContext,
57 ) -> bool {
58 false
59 }
60
61 fn debug(
62 &self,
63 bounds: RectF,
64 _: &Self::LayoutState,
65 _: &Self::PaintState,
66 _: &DebugContext,
67 ) -> serde_json::Value {
68 json!({
69 "type": "Empty",
70 "bounds": bounds.to_json(),
71 })
72 }
73}