Expand description
§ui_layout
Minimal CSS-like layout engine for UI frameworks. Designed for lightweight, fast, and portable applications (e.g. editors and IDEs).
Provides predictable layout behavior for custom GUI frameworks, editors, and experimental rendering engines.
§Getting Started
Basic usage follows a simple flow:
- Create a layout tree
- Run the layout engine
- Access computed layout results
use ui_layout::*;
let mut root = LayoutNode::new(Style::default());
// Compute layout using a viewport size.
LayoutEngine::layout(&mut root, 800.0, 600.0);§Core Concepts
Layout behavior is configured through Style, which groups
commonly used layout properties into focused categories:
Display— controls layout modeSizeStyle— width and height constraintsSpacing— margin, padding, and bordersItemStyle— item-specific flex behaviorjustify_content/align_items— child alignmentflex_direction,row_gap,column_gap— flex container behavior
This organization keeps layout rules explicit and easy to reason about.
§Observing Layout Results
After layout computation, results are written into each
LayoutNode through its layout_box field.
The resulting LayoutBox describes how the node was laid out:
LayoutBox::None— no layout resultLayoutBox::BlockBox(BoxModel)— standard box layout resultLayoutBox::InlineBox(InlineBox)— inline content that may span multiple lines
BoxModel contains absolute rectangles for different regions:
border_box— outer box including borderspadding_box— inner box including paddingcontent_box— content areachildren_box— area occupied by child content
Inline layouts additionally provide LineSpan information for
observing how a box is split across lines.
§Children
Layout trees contain children represented by LayoutChild:
LayoutChild::Node— a normal layout nodeLayoutChild::Fragment— an inline-level fragmentLayoutChild::Object— a customFlowLayouterobjectLayoutChild::Custom— a custom [BlockLayouter] object
ItemFragment represents the smallest independently positioned
piece of inline content.
Common fragment types:
Fragment— inline content with dimensionsLineBreak— forces a line break
During layout, fragments are wrapped in FragmentNode and assigned
placement information, allowing inline content to be split and
positioned across multiple lines.
§Custom Objects
The FlowLayouter trait allows custom types to participate directly
in layout as inline-level objects. Objects report their intrinsic size
via FlowLayouter::measure and perform inline layout via
FlowLayouter::layout.
The [BlockLayouter] trait allows custom types to participate
as block-level components. Components return their border-box
Rect via [BlockLayouter::layout].
Structs§
- BoxModel
- Represents the layout box model of an element.
- Display
- Full representation of the CSS
displayproperty, split into outer and inner display types. - Edge
Option - Flow
Layout Context - Context passed to
FlowLayouter::layoutfor inline flow participation. - Fragment
- A splittable fragment of inline content.
- Fragment
Node - A fragment with associated layout placement information.
- Inline
Box - An inline box that may be split across multiple lines.
- Item
Style - Layout
BoxInto Iter - Iterator over the
BoxModels represented by an ownedLayoutBox. - Layout
BoxIter - Iterator over the
BoxModels represented by a borrowedLayoutBox. - Layout
Context - Layout context passed to [
FlowLayouter::measure]. - Layout
Engine - Layout
Node - A node in the layout tree.
- Line
Span - A span of an inline box on a single line.
- Measure
Result - The measured size of a
FlowLayouterobject. - Placement
- Layout result for an inline placement.
- Rect
- Size
Style - Spacing
- Style
Enums§
- Align
Items - Axis
- Axis orientation
- BoxSizing
- Flex
Direction - Inner
Display - Represents the inner display type of a box.
- Item
Fragment - An item fragment for inline layout.
- Justify
Content - Layout
Box - Types of BoxModel.
- Layout
Child - A unified layout item used during layout processing.
- Layout
Item - Length
- Length
OrAuto - Outer
Display - Represents the outer display type of a box.
Traits§
- Flow
Layouter - A self-layouting object that participates in layout flows.