pub struct LayoutTree<C> { /* private fields */ }Expand description
A layout tree whose measured leaves carry a context C.
Implementations§
Source§impl<C> LayoutTree<C>
impl<C> LayoutTree<C>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty tree.
use ravenrs_core::Size;
use ravenrs_layout::{Axis, LayoutStyle, LayoutTree};
let mut tree = LayoutTree::<()>::new();
let child = tree.node(LayoutStyle { height: Some(20.0), ..LayoutStyle::leaf() }, &[]).unwrap();
let root = tree.node(LayoutStyle { spacing: 8.0, ..LayoutStyle::stack(Axis::Vertical) }, &[child]).unwrap();
tree.compute(root, Size::new(200.0, 100.0), |_, _| Size::ZERO).unwrap();
assert_eq!(tree.frame(child).unwrap().height(), 20.0);Sourcepub fn node(
&mut self,
style: LayoutStyle,
children: &[LayoutId],
) -> Result<LayoutId, LayoutError>
pub fn node( &mut self, style: LayoutStyle, children: &[LayoutId], ) -> Result<LayoutId, LayoutError>
Adds a container (or a fixed-size leaf) with the given children.
Sourcepub fn measured_leaf(
&mut self,
style: LayoutStyle,
context: C,
) -> Result<LayoutId, LayoutError>
pub fn measured_leaf( &mut self, style: LayoutStyle, context: C, ) -> Result<LayoutId, LayoutError>
Adds a leaf whose size comes from the measure callback given to Self::compute.
Sourcepub fn compute(
&mut self,
root: LayoutId,
available: Size,
measure: impl FnMut(&mut C, MeasureInput) -> Size,
) -> Result<(), LayoutError>
pub fn compute( &mut self, root: LayoutId, available: Size, measure: impl FnMut(&mut C, MeasureInput) -> Size, ) -> Result<(), LayoutError>
Computes the layout of root inside available logical pixels.
Sourcepub fn frame(&self, node: LayoutId) -> Result<Rect, LayoutError>
pub fn frame(&self, node: LayoutId) -> Result<Rect, LayoutError>
The node’s frame relative to its parent’s origin.
Sourcepub fn content_box(&self, node: LayoutId) -> Result<Rect, LayoutError>
pub fn content_box(&self, node: LayoutId) -> Result<Rect, LayoutError>
The content box (frame minus padding) relative to the node’s own origin.
Sourcepub fn content_size(&self, node: LayoutId) -> Result<Size, LayoutError>
pub fn content_size(&self, node: LayoutId) -> Result<Size, LayoutError>
The size of the node’s content, which can exceed its frame when it overflows.
Sourcepub fn context_mut(&mut self, node: LayoutId) -> Option<&mut C>
pub fn context_mut(&mut self, node: LayoutId) -> Option<&mut C>
Mutable access to a measured leaf’s context, or None for nodes without one.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Total number of nodes in the tree.
Trait Implementations§
Source§impl<C> Debug for LayoutTree<C>
impl<C> Debug for LayoutTree<C>
Auto Trait Implementations§
impl<C> !Send for LayoutTree<C>
impl<C> !Sync for LayoutTree<C>
impl<C> Freeze for LayoutTree<C>
impl<C> RefUnwindSafe for LayoutTree<C>where
C: RefUnwindSafe,
impl<C> Unpin for LayoutTree<C>where
C: Unpin,
impl<C> UnsafeUnpin for LayoutTree<C>
impl<C> UnwindSafe for LayoutTree<C>where
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more