Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 2.1 KB

File metadata and controls

42 lines (31 loc) · 2.1 KB

Customizing The Window On Launch

By using the window function of Application, we can pass a window::Settings struct to change the properties of the window (such as position and size).

Other useful functions in Application are window_size, which is a syntactic sugar for window that only changes the size of the window, centered, which centers the window on the screen, and position, which allows us to specify the position of the window.

use iced::{Point, Size, window};

fn main() -> iced::Result {
    iced::application("My App", MyApp::update, MyApp::view)
        .window(window::Settings {
            size: Size {
                width: 70.,
                height: 30.,
            },
            position: window::Position::Specific(Point { x: 50., y: 60. }),
            ..window::Settings::default()
        })
        .run()
}

#[derive(Debug, Clone)]
enum Message {}

#[derive(Default)]
struct MyApp;

impl MyApp {
    fn update(&mut self, _message: Message) {}

    fn view(&self) -> iced::Element<Message> {
        "Hello".into()
    }
}

Customizing The Window On Launch

➡️ Next: Changing The Window Dynamically

📘 Back: Table of contents