1use crate::{
2 geometry::{rect::RectF, vector::Vector2F},
3 DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
4 SizeConstraint,
5};
6
7pub struct Overlay {
8 child: ElementBox,
9}
10
11impl Overlay {
12 pub fn new(child: ElementBox) -> Self {
13 Self { child }
14 }
15}
16
17impl Element for Overlay {
18 type LayoutState = Vector2F;
19 type PaintState = ();
20
21 fn layout(
22 &mut self,
23 constraint: SizeConstraint,
24 cx: &mut LayoutContext,
25 ) -> (Vector2F, Self::LayoutState) {
26 let size = self.child.layout(constraint, cx);
27 (Vector2F::zero(), size)
28 }
29
30 fn paint(
31 &mut self,
32 bounds: RectF,
33 _: RectF,
34 size: &mut Self::LayoutState,
35 cx: &mut PaintContext,
36 ) {
37 let bounds = RectF::new(bounds.origin(), *size);
38 cx.scene.push_stacking_context(None);
39 self.child.paint(bounds.origin(), bounds, cx);
40 cx.scene.pop_stacking_context();
41 }
42
43 fn dispatch_event(
44 &mut self,
45 event: &Event,
46 _: RectF,
47 _: RectF,
48 _: &mut Self::LayoutState,
49 _: &mut Self::PaintState,
50 cx: &mut EventContext,
51 ) -> bool {
52 self.child.dispatch_event(event, cx)
53 }
54
55 fn debug(
56 &self,
57 _: RectF,
58 _: &Self::LayoutState,
59 _: &Self::PaintState,
60 cx: &DebugContext,
61 ) -> serde_json::Value {
62 self.child.debug(cx)
63 }
64}