LayoutEngine class Layout
The engine responsible for measuring and positioning components in the terminal UI.
A LayoutEngine recursively measures components starting from the root ComponentInstance, assigns bounds, and produces a list of PositionedComponentInstances ready for rendering.
Responsibilities
- Measure components using their ComponentInstance.measure method.
- Apply layout direction (Axis.horizontal or Axis.vertical).
- Account for padding, gaps, and absolute positioning.
- Record which component renders each child.
Lifecycle
- Created by the application’s renderer before layout computation.
compute
is called to produce layout results.- Internal
_layoutRecursiveCompute
is called recursively to measure and assign bounds to all child components.
See also
- ParentComponentInstance — For components that can contain children.
- PositionedComponentInstance — Holds final position data.
- Axis — Layout direction.
- Rect — Defines positions and sizes.
Example
final engine = LayoutEngine(
rootInstance: myRoot,
children: myRoot.childrenInstance,
direction: Axis.vertical,
bounds: Rect(x: 0, y: 0, width: 80, height: 24),
childGap: 1,
);
final positioned = engine.compute(Size(width: 80, height: 24));
Constructors
-
LayoutEngine.new({required ComponentInstance rootInstance, required List<
ComponentInstance> children, required Axis direction, required Rect bounds, int childGap = 0}) - Creates a layout engine with the given configuration.
Properties
- bounds → Rect
-
The total bounds available for layout.
final
- childGap → int
-
Gap between children in the specified layout direction.
final
-
children
→ List<
ComponentInstance> -
Direct children of the root instance.
final
- direction → Axis
-
Layout direction for children.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
result
→ List<
PositionedComponentInstance> -
Stores the final positioned results after computation.
final
- rootInstance → ComponentInstance
-
The root component in the layout hierarchy.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
compute(
Size maxSize) → List< PositionedComponentInstance> - Computes the layout starting from rootInstance.
-
fitHeight(
) → int - Computes the total height needed to fit all children based on direction and childGap.
-
fitWidth(
) → int - Computes the total width needed to fit all children based on direction and childGap.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited