Skip to main content

Module aspect_ratio

Module aspect_ratio 

Source
Expand description

AspectRatio — a single-child wrapper that constrains layout to a fixed width-to-height ratio.

Given a proposal, AspectRatio computes the largest rectangle that fits within both dimensions while satisfying width / height == ratio. When only one axis is constrained by the parent, the other is derived from the ratio. The child is stretched to the resulting rectangle. The widget is invisible to assistive technology (set_hidden); its child carries all semantic meaning.

§When to use

  • Embedding images, thumbnails, or video placeholders that must stay letter-boxed regardless of the available space.
  • Ensuring a square avatar or tile layout against an unconstrained parent axis.
// 16:9 video placeholder
let _thumbnail = AspectRatio::new(16.0 / 9.0)
    .child(RectWidget::new());

Structs§

AspectRatio
A single-child wrapper that maintains a fixed width/height ratio.