Skip to main content

rosace_layout/
flexure.rs

1//! [`Flexure`] — ROSACE's constraint-based layout engine.
2
3use rosace_core::types::Size;
4
5use crate::constraints::Constraints;
6use crate::layout_result::LayoutResult;
7
8/// ROSACE's constraint-based layout engine.
9///
10/// Runs a three-pass layout:
11/// 1. **Measure** — top-down constraint propagation (driven by this struct)
12/// 2. **Place** — bottom-up size resolution (driven by this struct)
13/// 3. **Paint** — handled by `rosace-render`
14///
15/// In Phase 1 the engine is invoked manually per-widget; automatic tree
16/// traversal is wired up in a later step.
17pub struct Flexure;
18
19impl Flexure {
20    /// Run a layout pass for a *leaf* node that has no children.
21    ///
22    /// The `natural_size` is clamped to `constraints` and returned inside a
23    /// [`LayoutResult`] with an empty `child_positions` list.
24    pub fn layout_leaf(constraints: Constraints, natural_size: Size) -> LayoutResult {
25        let size = constraints.constrain(natural_size);
26        LayoutResult {
27            size,
28            child_positions: vec![],
29        }
30    }
31}