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
impl LayoutEngine
Sourcepub fn new() -> LayoutEngine
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.
Sourcepub fn with_measurer(self, measurer: Arc<dyn TextMeasurer>) -> LayoutEngine
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.
Sourcepub fn update(
&mut self,
input_nodes: &[LayoutInputNode],
_dirty_set: &HashSet<NodeId>,
)
pub fn update( &mut self, input_nodes: &[LayoutInputNode], _dirty_set: &HashSet<NodeId>, )
Incrementally updates layout for the given dirty nodes.
Currently a no-op placeholder for future incremental layout support.
Sourcepub fn rebuild(&mut self, input_nodes: &[LayoutInputNode]) -> Result<(), Error>
pub fn rebuild(&mut self, input_nodes: &[LayoutInputNode]) -> Result<(), Error>
Rebuilds internal data structures from the full node list.
Currently a no-op placeholder for future optimization.
Sourcepub fn verify_post_update(
&self,
input_nodes: &[LayoutInputNode],
root: NodeId,
) -> Result<(), Error>
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.
Sourcepub fn compute_layout(
&mut self,
input_nodes: &[LayoutInputNode],
root_node_id: NodeId,
viewport_size: LayoutSize,
scroll_source: &impl ScrollDataSource,
) -> Result<LayoutSnapshot, Error>
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.
Sourcepub fn compute_layout_constraints(
&self,
input_nodes: &[LayoutInputNode],
root_node_id: NodeId,
viewport_size: LayoutSize,
scroll_source: &impl ScrollDataSource,
) -> Result<LayoutSnapshot, Error>
pub fn compute_layout_constraints( &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.
Auto Trait Implementations§
impl Freeze for LayoutEngine
impl !RefUnwindSafe for LayoutEngine
impl Send for LayoutEngine
impl Sync for LayoutEngine
impl Unpin for LayoutEngine
impl UnsafeUnpin for LayoutEngine
impl !UnwindSafe for LayoutEngine
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.