Skip to main content

Module smooth_size

Module smooth_size 

Source
Expand description

SmoothSize — auto-sizes the slot to fit the child’s intrinsic size, but tweens the change instead of jumping. The “empty panel that suddenly must grow gracefully to accept new content” pattern.

ctx.add(
    SmoothSize::new()
        .axes(SmoothSizeAxes::Both)
        .child(Panel::new().child(content_signal)),
);

For explicit size animation (target is a numeric signal you already drive, e.g. a sidebar width), use the existing FixedSize::new().width(animated_signal) + Signal::animate_to pattern instead — that path doesn’t need to measure the child every frame.

§Layout semantics

  • The wrapper measures the child’s natural size at the proposal each layout pass.
  • When the natural size differs from the current animation target (above 0.5 px), kicks off a new tween.
  • size_that_fits returns the current animated value — what the wrapper actually occupies right now, not the target.
  • The child is always laid out at its full natural size and clipped to the wrapper’s smaller animated bounds. Same trick as Collapse — the child’s own internal layout doesn’t reflow each frame, only the clip rect changes.

§Reduced motion

Honours prefers-reduced-motion: snaps to the natural size each layout pass instead of tweening.

Structs§

SmoothSize
Wraps a child widget and animates the wrapper’s reported size toward the child’s current natural size whenever that size changes.

Enums§

SmoothSizeAxes
Which axes participate in the size tween. Use Width or Height to leave the other axis tracking the child’s natural size instantly.