empty.rs

 1use crate::geometry::{
 2    rect::RectF,
 3    vector::{vec2f, Vector2F},
 4};
 5use crate::{
 6    AfterLayoutContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
 7};
 8
 9pub struct Empty;
10
11impl Empty {
12    pub fn new() -> Self {
13        Self
14    }
15}
16
17impl Element for Empty {
18    type LayoutState = ();
19    type PaintState = ();
20
21    fn layout(
22        &mut self,
23        constraint: SizeConstraint,
24        _: &mut LayoutContext,
25    ) -> (Vector2F, Self::LayoutState) {
26        let x = if constraint.max.x().is_finite() {
27            constraint.max.x()
28        } else {
29            constraint.min.x()
30        };
31        let y = if constraint.max.y().is_finite() {
32            constraint.max.y()
33        } else {
34            constraint.min.y()
35        };
36
37        (vec2f(x, y), ())
38    }
39
40    fn after_layout(&mut self, _: Vector2F, _: &mut Self::LayoutState, _: &mut AfterLayoutContext) {
41    }
42
43    fn paint(
44        &mut self,
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}