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