API ReferenceLayout Values
BoxFit
Image sizing policy with every fit mode.
use incular::prelude::*;
fn main() {
let fits = [
BoxFit::Fill,
BoxFit::Contain,
BoxFit::Cover,
BoxFit::FitWidth,
BoxFit::FitHeight,
BoxFit::None,
BoxFit::ScaleDown,
];
println!("fits: {}", fits.len());
}| Variant | Layout |
|---|---|
Fill | Stretch, ignoring aspect |
Contain | Fit inside, full content visible (default) |
Cover | Fill bounds, cropping overflow |
FitWidth | Match width, height follows |
FitHeight | Match height, width follows |
None | Natural size, centered |
ScaleDown | Like None, but shrink if too big |
Used by FittedBox (fit, default
Contain) and Image.
use incular::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let pixels = ImageHandle::from_rgba8(2, 2, vec![255u8; 16]).expect("image");
let app = Application::new(move |_cx| {
Container::builder()
.padding(EdgeInsets::all(24.0))
.alignment(Alignment::CENTER)
.child(
SizedBox::new()
.width(200.0)
.height(120.0)
.child( Image::new(pixels.clone()).fit(BoxFit::Cover)),
)
.build()
.into()
})?;
incular::run(app)?;
Ok(())
}Related: Image.