Incular logoIncular
API ReferenceLayout Widgets

AspectRatio

Size a child to an exact width-to-height ratio.

AspectRatio sizes its child to match the ratio. The ratio clamps to >= f32::EPSILON in both the builder setter and new.

Props

Prop

Type

use incular::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                AspectRatio::new(
                    16.0 / 9.0,
                    Container::new().color(Color::WHITE),
                ),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Methods

pub fn new(aspect_ratio: f32, child: impl Into<Widget>) -> Self

Related: FittedBox, FractionallySizedBox.

On this page