use super::{make_ro_shared, BoxConstraints, LayoutContext, RenderObject, SharedRO};
use crate::id::ElementId;
use crate::paint::{LayerEffect, PaintList};
use crate::{Point, Size};
pub struct ProxyRenderObject {
child: SharedRO,
}
impl ProxyRenderObject {
pub fn new(child: Box<dyn RenderObject>) -> Self {
Self { child: make_ro_shared(child) }
}
}
impl RenderObject for ProxyRenderObject {
fn layout(&mut self, constraints: BoxConstraints, ctx: &mut LayoutContext) -> Size {
self.child.layout_cached(constraints, ctx)
}
fn paint(&self, offset: Point, painter: &mut PaintList) {
self.child.borrow().paint(offset, painter);
}
fn hit_test(&self, position: Point, offset: Point) -> Option<ElementId> {
self.child.borrow().hit_test(position, offset)
}
fn set_element_id(&mut self, _id: ElementId) {
}
fn element_id(&self) -> Option<ElementId> {
self.child.borrow().element_id()
}
fn content_size(&self) -> Size {
self.child.borrow().content_size()
}
fn layer_layout_size(&self) -> Option<Size> {
self.child.borrow().layer_layout_size()
}
fn layer_relayout_constraints(&self, layout_size: Size) -> BoxConstraints {
self.child.borrow().layer_relayout_constraints(layout_size)
}
fn paint_as_layer_root(&self, offset: Point, painter: &mut PaintList) {
self.child.borrow().paint_as_layer_root(offset, painter);
}
fn layer_effect(&self) -> LayerEffect {
self.child.borrow().layer_effect()
}
fn propagate_element_ids(&mut self, child_ids: &[ElementId], stateful_ros: &mut [SharedRO]) {
if let (Some(&cid), Some(new_ro)) = (child_ids.first(), stateful_ros.first_mut()) {
self.child = new_ro.clone();
self.child.borrow_mut().set_element_id(cid);
}
}
fn child_slots(&self) -> Vec<(Point, SharedRO)> {
vec![(Point::ZERO, self.child.clone())]
}
fn for_each_child(&self, f: &mut dyn FnMut(Point, &SharedRO)) {
f(Point::ZERO, &self.child);
}
fn children_count(&self) -> usize {
1
}
}