Skip to main content

Crate ftui_layout

Crate ftui_layout 

Source
Expand description

Layout primitives and solvers.

This crate provides layout components for terminal UIs:

  • Flex - 1D constraint-based layout (rows or columns)
  • Grid - 2D constraint-based layout with cell spanning
  • Constraint - Size constraints (Fixed, Percentage, Min, Max, Ratio, FitContent)
  • debug - Layout constraint debugging and introspection
  • cache - Layout result caching for memoization

§Role in FrankenTUI

ftui-layout is the geometry solver for widgets and screens. It converts constraints into concrete rectangles, with support for intrinsic sizing and caching to keep layout deterministic and fast.

§How it fits in the system

The runtime and widgets call into this crate to split a Rect into nested regions. Those regions are then passed to widgets or custom renderers, which ultimately draw into ftui-render frames.

§Intrinsic Sizing

The layout system supports content-aware sizing via LayoutSizeHint and Flex::split_with_measurer:

use ftui_layout::{Flex, Constraint, LayoutSizeHint};

let flex = Flex::horizontal()
    .constraints([Constraint::FitContent, Constraint::Fill]);

let rects = flex.split_with_measurer(area, |idx, available| {
    match idx {
        0 => LayoutSizeHint { min: 5, preferred: 20, max: None },
        _ => LayoutSizeHint::ZERO,
    }
});

Re-exports§

pub use cache::CoherenceCache;
pub use cache::CoherenceId;
pub use cache::LayoutCache;
pub use cache::LayoutCacheKey;
pub use cache::LayoutCacheStats;
pub use cache::S3FifoLayoutCache;
pub use direction::FlowDirection;
pub use direction::LogicalAlignment;
pub use direction::LogicalSides;
pub use direction::mirror_rects_horizontal;
pub use grid::Grid;
pub use grid::GridArea;
pub use grid::GridLayout;
pub use pane::PANE_DEFAULT_MARGIN_CELLS;
pub use pane::PANE_DEFAULT_PADDING_CELLS;
pub use pane::PANE_DRAG_RESIZE_DEFAULT_HYSTERESIS;
pub use pane::PANE_DRAG_RESIZE_DEFAULT_THRESHOLD;
pub use pane::PANE_EDGE_GRIP_INSET_CELLS;
pub use pane::PANE_MAGNETIC_FIELD_CELLS;
pub use pane::PANE_SEMANTIC_INPUT_EVENT_SCHEMA_VERSION;
pub use pane::PANE_SEMANTIC_INPUT_TRACE_SCHEMA_VERSION;
pub use pane::PANE_SNAP_DEFAULT_HYSTERESIS_BPS;
pub use pane::PANE_SNAP_DEFAULT_STEP_BPS;
pub use pane::PANE_TREE_SCHEMA_VERSION;
pub use pane::PaneCancelReason;
pub use pane::PaneConstraints;
pub use pane::PaneCoordinateNormalizationError;
pub use pane::PaneCoordinateNormalizer;
pub use pane::PaneCoordinateRoundingPolicy;
pub use pane::PaneDockPreview;
pub use pane::PaneDockZone;
pub use pane::PaneDragBehaviorTuning;
pub use pane::PaneDragResizeEffect;
pub use pane::PaneDragResizeMachine;
pub use pane::PaneDragResizeMachineError;
pub use pane::PaneDragResizeNoopReason;
pub use pane::PaneDragResizeState;
pub use pane::PaneDragResizeTransition;
pub use pane::PaneEdgeResizePlan;
pub use pane::PaneEdgeResizePlanError;
pub use pane::PaneGroupTransformPlan;
pub use pane::PaneId;
pub use pane::PaneIdAllocator;
pub use pane::PaneInertialThrow;
pub use pane::PaneInputCoordinate;
pub use pane::PaneInteractionPolicyError;
pub use pane::PaneInteractionTimeline;
pub use pane::PaneInteractionTimelineEntry;
pub use pane::PaneInteractionTimelineError;
pub use pane::PaneInvariantCode;
pub use pane::PaneInvariantIssue;
pub use pane::PaneInvariantReport;
pub use pane::PaneInvariantSeverity;
pub use pane::PaneLayout;
pub use pane::PaneLayoutIntelligenceMode;
pub use pane::PaneLeaf;
pub use pane::PaneModelError;
pub use pane::PaneModifierSnapshot;
pub use pane::PaneMotionVector;
pub use pane::PaneNodeKind;
pub use pane::PaneNodeRecord;
pub use pane::PaneNormalizedCoordinate;
pub use pane::PaneOperation;
pub use pane::PaneOperationError;
pub use pane::PaneOperationFailure;
pub use pane::PaneOperationJournalEntry;
pub use pane::PaneOperationJournalResult;
pub use pane::PaneOperationKind;
pub use pane::PaneOperationOutcome;
pub use pane::PanePlacement;
pub use pane::PanePointerButton;
pub use pane::PanePointerPosition;
pub use pane::PanePrecisionMode;
pub use pane::PanePrecisionPolicy;
pub use pane::PanePressureSnapProfile;
pub use pane::PaneReflowMovePlan;
pub use pane::PaneReflowPlanError;
pub use pane::PaneRepairAction;
pub use pane::PaneRepairError;
pub use pane::PaneRepairFailure;
pub use pane::PaneRepairOutcome;
pub use pane::PaneResizeDirection;
pub use pane::PaneResizeGrip;
pub use pane::PaneResizeTarget;
pub use pane::PaneScaleFactor;
pub use pane::PaneSelectionState;
pub use pane::PaneSemanticInputEvent;
pub use pane::PaneSemanticInputEventError;
pub use pane::PaneSemanticInputEventKind;
pub use pane::PaneSemanticInputTrace;
pub use pane::PaneSemanticInputTraceError;
pub use pane::PaneSemanticInputTraceMetadata;
pub use pane::PaneSemanticReplayConformanceArtifact;
pub use pane::PaneSemanticReplayDiffArtifact;
pub use pane::PaneSemanticReplayDiffKind;
pub use pane::PaneSemanticReplayError;
pub use pane::PaneSemanticReplayFixture;
pub use pane::PaneSemanticReplayOutcome;
pub use pane::PaneSnapDecision;
pub use pane::PaneSnapReason;
pub use pane::PaneSnapTuning;
pub use pane::PaneSplit;
pub use pane::PaneSplitRatio;
pub use pane::PaneTransaction;
pub use pane::PaneTransactionOutcome;
pub use pane::PaneTree;
pub use pane::PaneTreeSnapshot;
pub use pane::SplitAxis;
pub use responsive::Responsive;
pub use responsive_layout::ResponsiveLayout;
pub use responsive_layout::ResponsiveSplit;
pub use visibility::Visibility;
pub use workspace::MigrationResult;
pub use workspace::WORKSPACE_SCHEMA_VERSION;
pub use workspace::WorkspaceMetadata;
pub use workspace::WorkspaceMigrationError;
pub use workspace::WorkspaceSnapshot;
pub use workspace::WorkspaceValidationError;
pub use workspace::migrate_workspace;
pub use workspace::needs_migration;

Modules§

cache
Layout cache for memoizing layout computation results.
debug
Layout constraint debugging utilities.
dep_graph
Dependency graph for incremental layout invalidation (bd-3p4y1.1).
direction
RTL layout mirroring and logical direction support (bd-ic6i.3).
grid
2D Grid layout system for dashboard-style positioning.
incremental
Incremental layout engine (bd-3p4y1.3).
pane
Canonical pane split-tree schema and validation.
responsive
Responsive value mapping: apply different values based on breakpoint.
responsive_layout
Responsive layout switching: different Flex configurations per breakpoint.
visibility
Breakpoint-based visibility helpers.
workspace
Persisted workspace schema v1 with versioning and migration scaffolding.

Structs§

Breakpoints
Breakpoint thresholds for responsive layouts.
Flex
A flexible layout container.
LayoutSizeHint
Size hint returned by measurer callbacks for intrinsic sizing.
Measurement
Size negotiation hints for layout.
Rect
A rectangle for scissor regions, layout bounds, and hit testing.
Sides
Sides for padding/margin.
Size
A 2D size in terminal cells.

Enums§

Alignment
Alignment of items within the layout.
Breakpoint
Responsive breakpoint tiers for terminal widths.
Constraint
A constraint on the size of a layout area.
Direction
The direction to layout items.

Functions§

round_layout_stable
Round real-valued layout targets to integer cells with exact sum conservation.

Type Aliases§

PreviousAllocation
Previous frame’s allocation, used as tie-breaker for temporal stability.