diff options
Diffstat (limited to 'examples/multi_window')
-rw-r--r-- | examples/multi_window/src/main.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index 98e753ab..ab09116e 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -3,22 +3,18 @@ use iced::widget::{ text_input, }; use iced::window; -use iced::{Alignment, Element, Length, Subscription, Task, Theme, Vector}; +use iced::{Center, Element, Fill, Subscription, Task, Theme, Vector}; use std::collections::BTreeMap; fn main() -> iced::Result { iced::daemon(Example::title, Example::update, Example::view) - .load(|| { - window::open(window::Settings::default()).map(Message::WindowOpened) - }) .subscription(Example::subscription) .theme(Example::theme) .scale_factor(Example::scale_factor) - .run() + .run_with(Example::new) } -#[derive(Default)] struct Example { windows: BTreeMap<window::Id, Window>, } @@ -43,6 +39,17 @@ enum Message { } impl Example { + fn new() -> (Self, Task<Message>) { + let (_id, open) = window::open(window::Settings::default()); + + ( + Self { + windows: BTreeMap::new(), + }, + open.map(Message::WindowOpened), + ) + } + fn title(&self, window: window::Id) -> String { self.windows .get(&window) @@ -68,10 +75,12 @@ impl Example { }, ); - window::open(window::Settings { + let (_id, open) = window::open(window::Settings { position, ..window::Settings::default() - }) + }); + + open }) .map(Message::WindowOpened) } @@ -182,8 +191,8 @@ impl Window { let content = scrollable( column![scale_input, title_input, new_window_button] .spacing(50) - .width(Length::Fill) - .align_items(Alignment::Center), + .width(Fill) + .align_x(Center), ); container(content).center_x(200).into() |