Incular logoIncular
API ReferenceLayout Widgets

FittedBox

Scale and position a child with BoxFit and Alignment.

FittedBox measures the child naturally, then scales/positions it per BoxFit and Alignment. Defaults: fit = Contain, alignment = CENTER.

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(
                SizedBox::new()
                    .width(240.0)
                    .height(120.0)
                    .child(
                        FittedBox::new(Text::new("Fitted"))
                            .fit(BoxFit::Cover)
                            .alignment(Alignment::TOP_LEFT),
                    ),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Methods

pub fn new(child: impl Into<Widget>) -> Self
pub fn fit(mut self, fit: BoxFit) -> Self
pub fn alignment(mut self, alignment: Alignment) -> Self

Related: AspectRatio, BoxFit.

On this page