Skip to main content

Module responsive_layout

Module responsive_layout 

Source
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

  1. The base layout (Xs) always has a value (enforced by constructor).
  2. Breakpoint resolution inherits from smaller tiers (via Responsive).
  3. split() auto-detects breakpoint from area width.
  4. split_for() uses an explicit breakpoint (no auto-detection).
  5. 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::breakpoint to detect changes.

Structs§

ResponsiveLayout
A breakpoint-aware layout that switches Flex configuration at different terminal widths.
ResponsiveSplit
Result of a responsive layout split.