From c22269bff3085012d326a0df77bf27ad5bcb41b7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 05:33:47 +0100 Subject: Introduce `Program` API --- examples/events/src/main.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'examples/events/src/main.rs') diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index d5d496c7..4ac57fc6 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -1,21 +1,15 @@ use iced::alignment; use iced::event::{self, Event}; -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::{Alignment, Command, Element, Length, Subscription}; pub fn main() -> iced::Result { - Events::run(Settings { - window: window::Settings { - exit_on_close_request: false, - ..window::Settings::default() - }, - ..Settings::default() - }) + iced::application(Events::new, Events::update, Events::view) + .title("Events - Iced") + .subscription(Events::subscription) + .ignore_close_request() + .run() } #[derive(Debug, Default)] @@ -31,20 +25,11 @@ enum Message { Exit, } -impl Application for Events { - type Message = Message; - type Theme = Theme; - type Executor = executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Events, Command) { +impl Events { + fn new() -> (Events, Command) { (Events::default(), Command::none()) } - fn title(&self) -> String { - String::from("Events - Iced") - } - fn update(&mut self, message: Message) -> Command { match message { Message::EventOccurred(event) if self.enabled => { -- cgit From 93ae790da14544667176ecdbdd6a4eaaa98a248a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 15:53:03 +0100 Subject: Implement `Program::load` to specify startup `Command` --- examples/events/src/main.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'examples/events/src/main.rs') diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index 4ac57fc6..6eb11cb8 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -5,8 +5,7 @@ use iced::window; use iced::{Alignment, Command, Element, Length, Subscription}; pub fn main() -> iced::Result { - iced::application(Events::new, Events::update, Events::view) - .title("Events - Iced") + iced::application("Events - Iced", Events::update, Events::view) .subscription(Events::subscription) .ignore_close_request() .run() @@ -26,10 +25,6 @@ enum Message { } impl Events { - fn new() -> (Events, Command) { - (Events::default(), Command::none()) - } - fn update(&mut self, message: Message) -> Command { match message { Message::EventOccurred(event) if self.enabled => { -- cgit From 846d76cd3f3f2faae5efbb3fda2a2bcb3b064481 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 17 Mar 2024 13:46:52 +0100 Subject: Remove `Sandbox` trait :tada: --- examples/events/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/events/src/main.rs') diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index 6eb11cb8..e18fe299 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -7,7 +7,7 @@ use iced::{Alignment, Command, Element, Length, Subscription}; pub fn main() -> iced::Result { iced::application("Events - Iced", Events::update, Events::view) .subscription(Events::subscription) - .ignore_close_request() + .exit_on_close_request(false) .run() } -- cgit From 54f44754eb216d4b2c08cd2a7c3582f1dc295205 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 17 Mar 2024 14:16:38 +0100 Subject: Move `Program` to `application` module --- examples/events/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/events/src/main.rs') diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index e18fe299..bf568c94 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -5,7 +5,7 @@ use iced::window; use iced::{Alignment, Command, Element, Length, Subscription}; pub fn main() -> iced::Result { - iced::application("Events - Iced", Events::update, Events::view) + iced::program("Events - Iced", Events::update, Events::view) .subscription(Events::subscription) .exit_on_close_request(false) .run() -- cgit