mgui_core/render_object/
proxy.rs1use super::{make_ro_shared, BoxConstraints, LayoutContext, RenderObject, SharedRO};
10use crate::id::ElementId;
11use crate::paint::{LayerEffect, PaintList};
12use crate::{Point, Size};
13
14pub struct ProxyRenderObject {
16 child: SharedRO,
17}
18
19impl ProxyRenderObject {
20 pub fn new(child: Box<dyn RenderObject>) -> Self {
21 Self { child: make_ro_shared(child) }
22 }
23}
24
25impl RenderObject for ProxyRenderObject {
26 fn layout(&mut self, constraints: BoxConstraints, ctx: &mut LayoutContext) -> Size {
27 self.child.layout_cached(constraints, ctx)
28 }
29
30 fn paint(&self, offset: Point, painter: &mut PaintList) {
31 self.child.borrow().paint(offset, painter);
32 }
33
34 fn hit_test(&self, position: Point, offset: Point) -> Option<ElementId> {
35 self.child.borrow().hit_test(position, offset)
36 }
37
38 fn set_element_id(&mut self, id: ElementId) {
39 self.child.borrow_mut().set_element_id(id);
40 }
41
42 fn element_id(&self) -> Option<ElementId> {
43 self.child.borrow().element_id()
44 }
45
46 fn content_size(&self) -> Size {
47 self.child.borrow().content_size()
48 }
49
50 fn layer_layout_size(&self) -> Option<Size> {
51 self.child.borrow().layer_layout_size()
52 }
53
54 fn layer_relayout_constraints(&self, layout_size: Size) -> BoxConstraints {
55 self.child.borrow().layer_relayout_constraints(layout_size)
56 }
57
58 fn paint_as_layer_root(&self, offset: Point, painter: &mut PaintList) {
59 self.child.borrow().paint_as_layer_root(offset, painter);
60 }
61
62 fn layer_effect(&self) -> LayerEffect {
63 self.child.borrow().layer_effect()
64 }
65
66 fn propagate_element_ids(&mut self, child_ids: &[ElementId], stateful_ros: &mut [SharedRO]) {
69 if let (Some(&cid), Some(new_ro)) = (child_ids.first(), stateful_ros.first_mut()) {
70 self.child = new_ro.clone();
71 self.child.borrow_mut().set_element_id(cid);
72 }
73 }
74
75 fn child_slots(&self) -> Vec<(Point, SharedRO)> {
76 vec![(Point::ZERO, self.child.clone())]
77 }
78
79 fn for_each_child(&self, f: &mut dyn FnMut(Point, &SharedRO)) {
80 f(Point::ZERO, &self.child);
81 }
82
83 fn children_count(&self) -> usize {
84 1
85 }
86}