diff options
author | 2023-01-18 15:01:17 -0800 | |
---|---|---|
committer | 2023-01-18 15:01:17 -0800 | |
commit | 70d487ba20a50c06c73f0ffcd8198f1a7eac7f37 (patch) | |
tree | afb8e161b18236d4440cba8bb0e0ce896858d653 /examples/events | |
parent | 790fa3e7a01a790aa3f07083fe9abf6b68fa7ba1 (diff) | |
parent | 5ef0648bf447aaca8b96782643401e54a2bf7759 (diff) | |
download | iced-70d487ba20a50c06c73f0ffcd8198f1a7eac7f37.tar.gz iced-70d487ba20a50c06c73f0ffcd8198f1a7eac7f37.tar.bz2 iced-70d487ba20a50c06c73f0ffcd8198f1a7eac7f37.zip |
Merge remote-tracking branch 'origin/master' into feat/multi-window-support
# Conflicts:
# examples/events/src/main.rs
# glutin/src/application.rs
# native/src/window.rs
# winit/src/window.rs
Diffstat (limited to 'examples/events')
-rw-r--r-- | examples/events/Cargo.toml | 2 | ||||
-rw-r--r-- | examples/events/src/main.rs | 28 |
2 files changed, 14 insertions, 16 deletions
diff --git a/examples/events/Cargo.toml b/examples/events/Cargo.toml index 8ad04a36..8c56e471 100644 --- a/examples/events/Cargo.toml +++ b/examples/events/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" publish = false [dependencies] -iced = { path = "../.." } +iced = { path = "../..", features = ["debug"] } iced_native = { path = "../../native" } diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index e9709377..f519fc3d 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -1,11 +1,12 @@ use iced::alignment; use iced::executor; use iced::widget::{button, checkbox, container, text, Column}; +use iced::window; use iced::{ Alignment, Application, Command, Element, Length, Settings, Subscription, Theme, }; -use iced_native::{window, Event}; +use iced_native::Event; pub fn main() -> iced::Result { Events::run(Settings { @@ -18,14 +19,13 @@ pub fn main() -> iced::Result { struct Events { last: Vec<iced_native::Event>, enabled: bool, - should_exit: bool, } #[derive(Debug, Clone)] enum Message { EventOccurred(iced_native::Event), Toggled(bool), - Exit, + Exit(window::Id), } impl Application for Events { @@ -50,31 +50,29 @@ impl Application for Events { if self.last.len() > 5 { let _ = self.last.remove(0); } + + Command::none() } Message::EventOccurred(event) => { - if let Event::Window(_, window::Event::CloseRequested) = event { - self.should_exit = true; + if let Event::Window(id, window::Event::CloseRequested) = event { + window::close(id) + } else { + Command::none() } } Message::Toggled(enabled) => { self.enabled = enabled; - } - Message::Exit => { - self.should_exit = true; - } - }; - Command::none() + Command::none() + } + Message::Exit(id) => window::close(id), + } } fn subscription(&self) -> Subscription<Message> { iced_native::subscription::events().map(Message::EventOccurred) } - fn should_exit(&self) -> bool { - self.should_exit - } - fn view(&self) -> Element<Message> { let events = Column::with_children( self.last |