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/exit/src/main.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'examples/exit') diff --git a/examples/exit/src/main.rs b/examples/exit/src/main.rs index ec618dc1..dc78b0bb 100644 --- a/examples/exit/src/main.rs +++ b/examples/exit/src/main.rs @@ -1,10 +1,11 @@ -use iced::executor; use iced::widget::{button, column, container}; use iced::window; -use iced::{Alignment, Application, Command, Element, Length, Settings, Theme}; +use iced::{Alignment, Command, Element, Length}; pub fn main() -> iced::Result { - Exit::run(Settings::default()) + iced::application(Exit::new, Exit::update, Exit::view) + .title("Exit - Iced") + .run() } #[derive(Default)] @@ -18,20 +19,11 @@ enum Message { Exit, } -impl Application for Exit { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: ()) -> (Self, Command) { +impl Exit { + fn new() -> (Self, Command) { (Self::default(), Command::none()) } - fn title(&self) -> String { - String::from("Exit - Iced") - } - fn update(&mut self, message: Message) -> Command { match message { Message::Confirm => window::close(window::Id::MAIN), -- 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/exit/src/main.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'examples/exit') diff --git a/examples/exit/src/main.rs b/examples/exit/src/main.rs index dc78b0bb..4948bd0f 100644 --- a/examples/exit/src/main.rs +++ b/examples/exit/src/main.rs @@ -3,9 +3,7 @@ use iced::window; use iced::{Alignment, Command, Element, Length}; pub fn main() -> iced::Result { - iced::application(Exit::new, Exit::update, Exit::view) - .title("Exit - Iced") - .run() + iced::application("Exit - Iced", Exit::update, Exit::view).run() } #[derive(Default)] @@ -20,10 +18,6 @@ enum Message { } impl Exit { - fn new() -> (Self, Command) { - (Self::default(), Command::none()) - } - fn update(&mut self, message: Message) -> Command { match message { Message::Confirm => window::close(window::Id::MAIN), -- 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/exit/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/exit') diff --git a/examples/exit/src/main.rs b/examples/exit/src/main.rs index 4948bd0f..7bed272d 100644 --- a/examples/exit/src/main.rs +++ b/examples/exit/src/main.rs @@ -3,7 +3,7 @@ use iced::window; use iced::{Alignment, Command, Element, Length}; pub fn main() -> iced::Result { - iced::application("Exit - Iced", Exit::update, Exit::view).run() + iced::program("Exit - Iced", Exit::update, Exit::view).run() } #[derive(Default)] -- cgit