mgui_core/render_object/
clip_rrect.rs1use super::*;
2
3pub struct ClipRRectRenderObject {
5 pub child: Option<SharedRO>,
6 pub element_id: Option<ElementId>,
7 pub size: Size,
8 pub radius: f32,
10}
11
12impl ClipRRectRenderObject {
13 pub fn new(child: Box<dyn RenderObject>, radius: f32) -> Self {
14 Self { child: Some(make_ro_shared(child)), element_id: None, size: Size::ZERO, radius }
15 }
16 pub fn empty(radius: f32) -> Self {
17 Self { child: None, element_id: None, size: Size::ZERO, radius }
18 }
19}
20
21impl RenderObject for ClipRRectRenderObject {
22 fn layout(&mut self, constraints: BoxConstraints, ctx: &mut LayoutContext) -> Size {
23 self.size = self.child.as_mut().map(|c| c.layout_cached(constraints, ctx)).unwrap_or(Size::ZERO);
24 self.size
25 }
26 fn paint(&self, _offset: Point, _painter: &mut PaintList) {
27 }
29 fn paint_as_layer_root(&self, offset: Point, painter: &mut PaintList) {
30 if let Some(c) = &self.child {
33 c.borrow().paint(offset, painter);
34 }
35 }
36 fn hit_test(&self, position: Point, offset: Point) -> Option<ElementId> {
37 if !point_in_rrect(position, offset, self.size, self.radius) {
39 return None;
40 }
41 self.child.as_ref()?.borrow().hit_test(position, offset)
42 }
43 fn set_element_id(&mut self, _id: ElementId) {
44 }
46 fn child_slots(&self) -> Vec<(Point, SharedRO)> {
48 self.child.as_ref().map(|c| vec![(Point::ZERO, c.clone())]).unwrap_or_default()
49 }
50
51 fn for_each_child(&self, f: &mut dyn FnMut(Point, &SharedRO)) {
52 if let Some(c) = &self.child {
53 f(Point::ZERO, c);
54 }
55 }
56 fn propagate_element_ids(&mut self, child_ids: &[ElementId], stateful_ros: &mut [SharedRO]) {
57 if let (Some(child_ro), Some(&cid)) = (self.child.as_mut(), child_ids.first()) {
58 if let Some(new_ro) = stateful_ros.first_mut() {
59 *child_ro = new_ro.clone();
60 }
61 child_ro.borrow_mut().set_element_id(cid);
62 }
63 }
64 fn content_size(&self) -> Size {
65 self.size
66 }
67 fn layer_layout_size(&self) -> Option<Size> {
68 Some(self.size)
69 }
70 fn push_child(&mut self, _offset: Point, _child: SharedRO) {
71 }
73 fn children_count(&self) -> usize {
74 if self.child.is_some() {
75 1
76 } else {
77 0
78 }
79 }
80 fn layer_effect(&self) -> crate::paint::LayerEffect {
81 crate::LayerEffect::ClipRRect(crate::RRectDef::new(self.radius))
82 }
83}