diff options
author | 2024-06-19 01:53:40 +0200 | |
---|---|---|
committer | 2024-06-19 01:53:40 +0200 | |
commit | 341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b (patch) | |
tree | 6a37f29352b1768911b6d42c220f22ebecc202ee /examples/multi_window | |
parent | 368b15f70896b387ae3f072e807b289b36b2d103 (diff) | |
download | iced-341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b.tar.gz iced-341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b.tar.bz2 iced-341c9a3c12aa9d327ef1d8f168ea0adb9b5ad10b.zip |
Introduce `daemon` API and unify shell runtimes
Diffstat (limited to 'examples/multi_window')
-rw-r--r-- | examples/multi_window/src/main.rs | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index b82ad1f3..dfb816cf 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -1,18 +1,21 @@ -use iced::executor; -use iced::multi_window::{self, Application}; use iced::widget::{ button, center, column, container, horizontal_space, scrollable, text, text_input, }; use iced::window; -use iced::{ - Alignment, Element, Length, Settings, Subscription, Task, Theme, Vector, -}; +use iced::{Alignment, Element, Length, Subscription, Task, Theme, Vector}; use std::collections::BTreeMap; fn main() -> iced::Result { - Example::run(Settings::default()) + 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() } #[derive(Default)] @@ -39,21 +42,7 @@ enum Message { TitleChanged(window::Id, String), } -impl multi_window::Application for Example { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: ()) -> (Self, Task<Message>) { - ( - Example { - windows: BTreeMap::from([(window::Id::MAIN, Window::new(1))]), - }, - Task::none(), - ) - } - +impl Example { fn title(&self, window: window::Id) -> String { self.windows .get(&window) @@ -97,7 +86,11 @@ impl multi_window::Application for Example { Message::WindowClosed(id) => { self.windows.remove(&id); - Task::none() + if self.windows.is_empty() { + iced::exit() + } else { + Task::none() + } } Message::ScaleInputChanged(id, scale) => { if let Some(window) = self.windows.get_mut(&id) { @@ -149,7 +142,7 @@ impl multi_window::Application for Example { .unwrap_or(1.0) } - fn subscription(&self) -> Subscription<Self::Message> { + fn subscription(&self) -> Subscription<Message> { window::close_events().map(Message::WindowClosed) } } |