Skip to main content

LayoutTree

Struct LayoutTree 

Source
pub struct LayoutTree<C> { /* private fields */ }
Expand description

A layout tree whose measured leaves carry a context C.

Implementations§

Source§

impl<C> LayoutTree<C>

Source

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);
Source

pub fn clear(&mut self)

Removes every node, keeping allocations for the next build.

Source

pub fn node( &mut self, style: LayoutStyle, children: &[LayoutId], ) -> Result<LayoutId, LayoutError>

Adds a container (or a fixed-size leaf) with the given children.

Source

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.

Source

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.

Source

pub fn frame(&self, node: LayoutId) -> Result<Rect, LayoutError>

The node’s frame relative to its parent’s origin.

Source

pub fn content_box(&self, node: LayoutId) -> Result<Rect, LayoutError>

The content box (frame minus padding) relative to the node’s own origin.

Source

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.

Source

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.

Source

pub fn node_count(&self) -> usize

Total number of nodes in the tree.

Trait Implementations§

Source§

impl<C> Debug for LayoutTree<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C> Default for LayoutTree<C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.