use super::*;
pub struct LayerProxyRenderObject {
pub child: Option<SharedRO>,
pub element_id: Option<ElementId>,
pub size: Size,
}
impl LayerProxyRenderObject {
pub fn new(child: Box<dyn RenderObject>) -> Self {
Self { child: Some(make_ro_shared(child)), element_id: None, size: Size::ZERO }
}
pub fn empty() -> Self {
Self { child: None, element_id: None, size: Size::ZERO }
}
}
impl RenderObject for LayerProxyRenderObject {
fn layout(&mut self, constraints: BoxConstraints, ctx: &mut LayoutContext) -> Size {
self.size = self.child.as_mut().map(|c| c.layout_cached(constraints, ctx)).unwrap_or(Size::ZERO);
self.size
}
fn paint(&self, offset: Point, painter: &mut PaintList) {
let _ = (offset, painter);
}
fn paint_as_layer_root(&self, offset: Point, painter: &mut PaintList) {
if let Some(child) = &self.child {
child.borrow().paint(offset, painter);
}
}
fn hit_test(&self, position: Point, offset: Point) -> Option<ElementId> {
self.child.as_ref()?.borrow().hit_test(position, offset)
}
fn set_element_id(&mut self, _id: ElementId) {
}
fn child_slots(&self) -> Vec<(Point, SharedRO)> {
self.child.as_ref().map(|c| vec![(Point::ZERO, c.clone())]).unwrap_or_default()
}
fn for_each_child(&self, f: &mut dyn FnMut(Point, &SharedRO)) {
if let Some(c) = &self.child {
f(Point::ZERO, c);
}
}
fn propagate_element_ids(&mut self, child_ids: &[ElementId], stateful_ros: &mut [SharedRO]) {
if let (Some(child_ro), Some(&cid)) = (self.child.as_mut(), child_ids.first()) {
if let Some(new_ro) = stateful_ros.first_mut() {
*child_ro = new_ro.clone();
}
child_ro.borrow_mut().set_element_id(cid);
}
}
fn content_size(&self) -> Size {
self.size
}
fn layer_layout_size(&self) -> Option<Size> {
Some(self.size)
}
fn layer_relayout_constraints(&self, layout_size: Size) -> BoxConstraints {
self.child
.as_ref()
.map(|c| c.borrow().layer_relayout_constraints(layout_size))
.unwrap_or_else(|| BoxConstraints::loose(layout_size))
}
fn push_child(&mut self, _offset: Point, _child: SharedRO) {
}
fn children_count(&self) -> usize {
if self.child.is_some() {
1
} else {
0
}
}
}