Struct LayoutEngine

Source
pub struct LayoutEngine<'t, A> {
    pub tree: &'t mut ElementTree<A>,
}
Expand description

Recursive retained-tree layout driver with per-element result caching.

The engine exclusively borrows an ElementTree for the traversal. Cache identity includes exact floating-point bit patterns for constraints, DPR, and virtual viewport, the layout pass authority, plus text, element, widget-dependency, and topology revisions. Consequently 0.0 and -0.0 are distinct cache inputs and NaN payloads are compared by their bits.

§Examples

use ailloli_ui_runtime::element::ElementTree;
use ailloli_ui_runtime::layout::LayoutEngine;

let mut tree = ElementTree::<()>::new();
let engine = LayoutEngine::new(&mut tree);
assert!(engine.tree.root().is_none());

Fields§

§tree: &'t mut ElementTree<A>

Retained tree being read and updated by this layout traversal.

Implementations§

Source§

impl<'t, A: 'static> LayoutEngine<'t, A>

Provides the operations defined for LayoutEngine<'t, A>.

Source

pub fn new(tree: &'t mut ElementTree<A>) -> Self

Creates an engine borrowing tree until the engine is dropped.

This performs no layout and does not clear existing caches.

§Examples
use ailloli_ui_runtime::element::ElementTree;
use ailloli_ui_runtime::layout::LayoutEngine;

let mut tree = ElementTree::<()>::new();
let engine = LayoutEngine::new(&mut tree);
assert_eq!(engine.tree.children_of(ailloli_ui_core::ElementId(42)), &[]);
Source

pub fn layout_element( &mut self, ctx: &mut LayoutCtx<'_>, element_id: ElementId, constraints: Constraints, ) -> LayoutResult

Lays out one element and stores or reuses its cached LayoutResult.

A missing ID returns a zero result without recording a cache miss. A clean element with an identical key returns its cloned cached result and records a hit. Otherwise the engine records a miss and layout operation, recursively delegates widgets and transparent components, then stores a cloned result. Components overlay direct children at (0, 0) and use the maximum child size constrained by the parent.

The text revision is zero when ctx.text_system is None. Widget code runs synchronously and may mutate external state or panic; a panic leaves this method before the new cache entry is stored.

§Examples
use ailloli_ui_core::{Constraints, ElementId, Scale, Size};
use ailloli_ui_runtime::element::ElementTree;
use ailloli_ui_runtime::layout::{LayoutCtx, LayoutEngine};

let mut tree = ElementTree::<()>::new();
let mut engine = LayoutEngine::new(&mut tree);
let mut ctx = LayoutCtx::new(Scale::new(1.0));
let result = engine.layout_element(
    &mut ctx, ElementId(404), Constraints::tight(40.0, 20.0),
);
assert_eq!(result.size, Size::default());

Auto Trait Implementations§

§

impl<'t, A> Freeze for LayoutEngine<'t, A>

§

impl<'t, A> !RefUnwindSafe for LayoutEngine<'t, A>

§

impl<'t, A> !Send for LayoutEngine<'t, A>

§

impl<'t, A> !Sync for LayoutEngine<'t, A>

§

impl<'t, A> Unpin for LayoutEngine<'t, A>

§

impl<'t, A> !UnwindSafe for LayoutEngine<'t, A>

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> ErasedDestructor for T
where T: 'static,