Expand description
MinSize — a layout modifier that ensures a child reaches a minimum width and/or height.
The child’s reported size is clamped upward so it never falls below the
configured minimum on each constrained axis. A bounded proposal below the
minimum is raised to it before it is forwarded, so that wrap-aware children
(e.g. a multi-line TextWidget) measure against the width they will
actually be placed into. An unbounded axis stays unbounded: the child
answers with its ideal size, and the minimum applies to that answer, as
SwiftUI’s .frame(minWidth:) does. Axes with no minimum set are passed
through unchanged.
MinSize propagates the child’s flex and shrink weights so that a
Spacer or Expand inside MinSize still participates in stack
slack-distribution; the child’s own compression floor is composed with
the MinSize floor.
For the inverse operation (capping a maximum size) see MaxSize.
§Hit targets: take the floor from the theme
MinSize is the mechanism for a minimum hit box, but the number belongs to
the active density rather than to the call site. Route it through
density_min_size (or
dp(.., TargetRole::Target, ..)), which raises the named axes to
theme.input.target_size — 24 dp at Compact, 32 at Comfortable, 44 at
Touch, and 48 under the Material 3 preset. That is what every shipped
recipe does; see docs/density-and-targets.md.
// The density decides the floor; the call site only says "both axes".
let min = density_min_size(base, TargetAxes::BOTH, &tokens);
let _tap_target = MinSize::new(min.width, min.height)
.child(IconWidget::checkmark(20.0));A hard-coded literal is right only where the number is a design dimension
that must not move with density. Where it is a target, name its bar: 24 dp is
WCAG 2.2 SC 2.5.8 Target Size (Minimum), level AA — the floor
min_target_conformance holds at every density; 44 dp is Apple’s HIG minimum
and SC 2.5.5 Target Size (Enhanced), level AAA, which is what the Touch
ladder aims for. 44 dp is never the AA figure.
Structs§
- MinSize
- Layout modifier that enforces a minimum width and/or height on a single child widget.