Function absolute_paint_bounds

Source
pub fn absolute_paint_bounds<A>(
    tree: &ElementTree<A>,
    target: ElementId,
) -> Option<Rect>
Expand description

Resolves one element’s retained bounds in tree-global logical pixels.

The root uses its own paint_bounds. Descendants use the positional crate::layout::ChildLayout entry stored by each parent, accumulating its offset and size; parent links are not consulted. None means the tree has no root, a traversed element has no layout, the target is absent, or a child lacks a matching positional layout entry.

§Examples

use ailloli_ui_core::{Offset, Rect, Size};
use ailloli_ui_runtime::{element::{ElementKind, ElementTree}, input::absolute_paint_bounds, layout::{ChildLayout, LayoutResult}};
let mut tree = ElementTree::<()>::new();
let root = tree.create_element(ElementKind::Empty, None, None);
let child = tree.create_element(ElementKind::Empty, None, Some(root));
tree.set_children(root, vec![child]);
let mut root_layout = LayoutResult::empty();
root_layout.paint_bounds = Rect::new(10.0, 20.0, 100.0, 80.0);
root_layout.children.push(ChildLayout {
    offset: Offset::new(4.0, 6.0), size: Size::new(30.0, 12.0),
    paint_bounds: Rect::new(4.0, 6.0, 30.0, 12.0),
    visual_bounds: Rect::new(4.0, 6.0, 30.0, 12.0),
});
tree.get_mut(root).unwrap().layout = Some(root_layout);
tree.get_mut(child).unwrap().layout = Some(LayoutResult::empty());
assert_eq!(absolute_paint_bounds(&tree, child), Some(Rect::new(14.0, 26.0, 30.0, 12.0)));