Expand description
Responsive layout switching: different Flex configurations per breakpoint.
ResponsiveLayout maps Breakpoint tiers to Flex layouts. When
splitting an area, it auto-detects the current breakpoint from the area
width and resolves the appropriate layout using Responsive inheritance.
§Usage
ⓘ
use ftui_layout::{Flex, Constraint, Breakpoint, Breakpoints, ResponsiveLayout};
// Mobile: single column. Desktop: sidebar + content.
let layout = ResponsiveLayout::new(
Flex::vertical()
.constraints([Constraint::Fill, Constraint::Fill]),
)
.at(Breakpoint::Md,
Flex::horizontal()
.constraints([Constraint::Fixed(30), Constraint::Fill]),
);
let area = ftui_core::geometry::Rect::new(0, 0, 120, 40);
let result = layout.split(area);
assert_eq!(result.breakpoint, Breakpoint::Lg);
assert_eq!(result.rects.len(), 2);§Invariants
- The base layout (
Xs) always has a value (enforced by constructor). - Breakpoint resolution inherits from smaller tiers (via
Responsive). split()auto-detects breakpoint from area width.split_for()uses an explicit breakpoint (no auto-detection).- Result count may differ between breakpoints (caller must handle this).
§Failure Modes
- Empty area: delegates to
Flex::split(returns zero-sized rects). - Breakpoint changes mid-session: caller must handle state transitions
(e.g., re-mapping children). Use
ResponsiveSplit::breakpointto detect changes.
Structs§
- Responsive
Layout - A breakpoint-aware layout that switches
Flexconfiguration at different terminal widths. - Responsive
Split - Result of a responsive layout split.