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() -> Self
pub fn new() -> Self
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>) -> Self
pub fn with_measurer(self, measurer: Arc<dyn TextMeasurer>) -> Self
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<()>
pub fn rebuild(&mut self, input_nodes: &[LayoutInputNode]) -> Result<()>
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<()>
pub fn verify_post_update( &self, input_nodes: &[LayoutInputNode], root: NodeId, ) -> Result<()>
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>
pub fn compute_layout( &mut self, input_nodes: &[LayoutInputNode], root_node_id: NodeId, viewport_size: LayoutSize, scroll_source: &impl ScrollDataSource, ) -> Result<LayoutSnapshot>
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>
pub fn compute_layout_constraints( &self, input_nodes: &[LayoutInputNode], root_node_id: NodeId, viewport_size: LayoutSize, scroll_source: &impl ScrollDataSource, ) -> Result<LayoutSnapshot>
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.