Expand description
Shrinkable — a layout modifier that allows its child to compress under an over-constraint.
By default every widget is rigid: when a stack runs out of main-axis room, rigid
children keep their wanted size and overflow the bounds. Shrinkable opts a child
into the over-constraint distribution: the stack divides any deficit across all
shrinkable children proportional to their shrink weight,
never below the min_width / min_height
floor set here.
Shrinkable is the shrink counterpart to
Expand: while Expand claims leftover slack
(grow), Shrinkable absorbs excess pressure (shrink). The two are independent
— a child can both grow on surplus and shrink on deficit by wrapping with
Shrinkable and setting a non-zero flex on the inner widget.
§When to use
- A long text label that should ellipsize before a rigid icon/badge loses space.
- A thumbnail image column that may compress while a fixed sidebar stays at full width.
- “Compress A before B”: give A
Shrinkable, leave B rigid (shrink = 0).
// The label shrinks as far as 48 dp; the button stays rigid.
let _row = HStack::new()
.child(Shrinkable::new().min_width(48.0)
.child(TextWidget::new(lit!("A long label that may compress")).single_line()))
.child(TextWidget::new(lit!("Rigid")));Structs§
- Shrinkable
- Layout modifier that lets its child be compressed when a stack is
over-constrained — the shrink counterpart to
Expand.