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 publishes no node of its own to assistive technology: it is a bare Role::GenericContainer, which the walker prunes, and its child carries all semantic meaning. It is never hidden, which would take the child out of every platform’s tree with it.

§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.