Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 1.87 KB

width_and_height.md

File metadata and controls

59 lines (46 loc) · 1.87 KB

Width And Height

Most widgets have the width and height methods to control their sizes. The methods accept a parameter Length. There are four types of Length:

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()
    }
}

Width And Height

➡️ Next: Column

📘 Back: Table of contents