Skip to main content

Module scale

Module scale 

Source
Expand description

Scale — wraps a child and animates a uniform 2D scale on its entire subtree when an external Prop<bool> toggles. Drives a progress: Signal<f32> ∈ [0, 1] (0 = invisible, 1 = at rest) and applies it as a centered (or origin-pivoted) scale transform via [BuildContext::set_transform] — the renderer’s transform stack composes it onto the subtree.

let visible = ctx.signal(false);
ctx.add(Scale::new(visible.clone()).child(card));
visible.set(true);   // scale-in around the slot center

§Two layout modes

  • Visual-only (default)reflow=false. The slot stays at the child’s natural size at all scale values; only the visual content shrinks/grows around the chosen origin. Use for: overlay enter/exit, “boop” feedback on a Card, focus emphasis. Pair with Center origin (the default).
  • Reflow.reflow(true). The wrapper’s layout_response returns child_size * progress, so siblings reflow as the child shrinks to nothing. The visual content scales by the same factor, fitting exactly within the shrunken slot. Use for: a Card that disappears by shrinking with surrounding cards filling the gap. Pair with TopLeading origin (so the visual stays anchored at the slot’s top-left as it shrinks — otherwise the visual drifts while the slot shrinks).

§Why this isn’t just Collapse

Collapse animates only one axis (height by default) and “wipes” content via clipping — text inside stays at full size, only the visible portion shrinks. Scale shrinks uniformly on both axes, and text/icons visually get smaller. Different visual vocabulary, different use cases.

§Reduced motion

Honours prefers-reduced-motion: snaps progress to its end value (visible / hidden) instead of tweening.

Structs§

Scale
Wraps a child widget and animates a uniform 2D visual scale on its subtree when an external Prop<bool> toggles between visible and hidden.

Enums§

ScaleOrigin
Pivot point for the scale matrix, expressed relative to the wrapper’s slot rectangle.