Skip to main content

Module responsive

Module responsive 

Source
Expand description

Responsive value mapping: apply different values based on breakpoint.

Responsive<T> maps Breakpoint tiers to values of any type, with inheritance from smaller breakpoints. If no value is set for a given breakpoint, the value from the next smaller breakpoint is used.

§Usage

use ftui_layout::{Responsive, Breakpoint};

let padding = Responsive::new(1)     // xs: 1
    .at(Breakpoint::Md, 2)           // md: 2
    .at(Breakpoint::Xl, 4);          // xl: 4

// sm inherits from xs → 1
// lg inherits from md → 2
assert_eq!(padding.resolve(Breakpoint::Sm), &1);
assert_eq!(padding.resolve(Breakpoint::Lg), &2);

§Invariants

  1. Xs always has a value (set via new()).
  2. Inheritance follows breakpoint order: a missing tier inherits from the nearest smaller tier that has a value.
  3. resolve() never fails — it always returns a reference.
  4. Setting a value at a tier only affects that tier and tiers that inherit from it (does not affect tiers with explicit values).

§Failure Modes

None — the type system guarantees a base value at Xs.

Structs§

Responsive
A breakpoint-aware value with inheritance from smaller tiers.