Skip to main content

LayoutEngine

Struct LayoutEngine 

Source
pub struct LayoutEngine { /* private fields */ }
Expand description

The constraint-based layout solver.

LayoutEngine walks the node tree top-down, passing BoxConstraints from parent to child, and bottom-up, returning LayoutSize from child to parent. The final result is a LayoutSnapshot that maps every node to its absolute screen-space rectangle.

The engine optionally holds a TextMeasurer for sizing text nodes. Without one, text nodes are treated as zero-sized.

§Example

use fission_layout::*;
use fission_ir::NodeId;
use std::sync::Arc;

let mut engine = LayoutEngine::new();
// engine = engine.with_measurer(my_text_measurer);

// let snapshot = engine.compute_layout(&nodes, root_id, viewport, &|_| 0.0).unwrap();

Implementations§

Source§

impl LayoutEngine

Source

pub fn new() -> LayoutEngine

Creates a new layout engine with no text measurer.

Text nodes will be treated as zero-sized until a measurer is provided via with_measurer.

Source

pub fn with_measurer(self, measurer: Arc<dyn TextMeasurer>) -> LayoutEngine

Returns a new engine with the given text measurer attached.

This is a builder-style method that consumes and returns self.

Source

pub fn update(&mut self, input_nodes: &[LayoutInputNode])

Refreshes the cached graph state after upstream layout edits.

Unchanged nodes keep their cached graph entries while edited topology and fingerprints are synchronized to the latest flattened node list.

Source

pub fn rebuild(&mut self, input_nodes: &[LayoutInputNode]) -> Result<(), Error>

Rebuilds internal data structures from the full node list.

Source

pub fn verify_post_update( &self, input_nodes: &[LayoutInputNode], root: NodeId, ) -> Result<(), Error>

Verifies parent-child consistency and checks for cycles in the node graph.

Call this during development/testing to catch malformed IR before it causes layout panics. Returns Err with a description of the first problem found.

Source

pub fn compute_layout( &mut self, input_nodes: &[LayoutInputNode], root_node_id: NodeId, viewport_size: LayoutSize, scroll_source: &impl ScrollDataSource, ) -> Result<LayoutSnapshot, Error>

Computes layout for the entire node tree and returns a snapshot.

This is the main entry point. It runs the constraint-based layout algorithm starting from root_node_id, using viewport_size as the root constraints, and querying scroll_source for scroll offsets. After layout, it emits scroll diagnostics for debugging.

§Arguments
  • input_nodes – The flat list of all layout nodes.
  • root_node_id – Which node is the root of the tree.
  • viewport_size – The size of the window/screen.
  • scroll_source – Provides scroll offsets for scroll containers.
§Errors

Returns Err if a cycle is detected or a required node is missing.

Source

pub fn compute_layout_constraints( &mut self, input_nodes: &[LayoutInputNode], root_node_id: NodeId, viewport_size: LayoutSize, scroll_source: &impl ScrollDataSource, ) -> Result<LayoutSnapshot, Error>

Lower-level layout that skips scroll diagnostics.

Same as compute_layout but does not emit diagnostic events. Useful when you need the snapshot but not the debug output.

Source

pub fn compute_layout_incremental( &mut self, input_nodes: &[LayoutInputNode], root_node_id: NodeId, viewport_size: LayoutSize, scroll_source: &impl ScrollDataSource, previous_snapshot: &LayoutSnapshot, dirty_nodes: &HashSet<NodeId>, ) -> Result<LayoutSnapshot, Error>

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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.