Most widgets have the width
and height
methods to control their sizes.
The methods accept a parameter Length.
There are four types of Length:
- Shrink: occupy the least space.
- Fill: occupy all the rest of space.
- FillPortion: occupy the space relative to other widgets with FillPortion.
- Fixed: occupy a fixed space.
use iced::{
widget::{button, column, row},
Length, Sandbox, Settings,
};
fn main() -> iced::Result {
MyApp::run(Settings::default())
}
struct MyApp;
impl Sandbox for MyApp {
type Message = ();
fn new() -> Self {
Self
}
fn title(&self) -> String {
String::from("My App")
}
fn update(&mut self, _message: Self::Message) {}
fn view(&self) -> iced::Element<Self::Message> {
column![
button("Shrink").width(Length::Shrink),
button("Fill").width(Length::Fill),
row![
button("FillPortion 2").width(Length::FillPortion(2)),
button("FillPortion 1").width(Length::FillPortion(1)),
]
.spacing(10),
button("Fixed").width(Length::Fixed(100.)),
button("Fill (height)").height(Length::Fill),
]
.spacing(10)
.into()
}
}
➡️ Next: Column
📘 Back: Table of contents