aspect-ratio
Builds AspectRatio


The code that drew it
A still frame holds a repeating animation at its first frame and a one-shot at its last, because a still of a moving thing is not reproducible. Run the gallery to review motion.
fn aspect_ratio(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
let filled = |label: &'static str| {
div()
.size_full()
.flex()
.items_center()
.justify_center()
.bg(theme.colors.hover)
.text_color(theme.colors.text_muted)
.child(label)
};
stack(&theme)
.child(caption(&theme, "Width given, height from the ratio"))
.child(
div().w(px(320.0)).child(
AspectRatio::of("scene.aspect.wide", 16.0, 9.0)
.width_driven()
.child(filled("16 by 9")),
),
)
.child(caption(&theme, "Height given, width from the ratio"))
.child(
div().h(px(120.0)).child(
AspectRatio::new("scene.aspect.square", 1.0)
.height_driven()
.child(filled("square")),
),
)
.into_any_element()
}