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/pokedex/src/main.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'examples/pokedex') diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index 193f85f2..099cc710 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -1,9 +1,11 @@ use iced::futures; use iced::widget::{self, column, container, image, row, text}; -use iced::{Alignment, Application, Command, Element, Length, Settings, Theme}; +use iced::{Alignment, Command, Element, Length}; pub fn main() -> iced::Result { - Pokedex::run(Settings::default()) + iced::application(Pokedex::new, Pokedex::update, Pokedex::view) + .title(Pokedex::title) + .run() } #[derive(Debug)] @@ -19,13 +21,8 @@ enum Message { Search, } -impl Application for Pokedex { - type Message = Message; - type Theme = Theme; - type Executor = iced::executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Pokedex, Command) { +impl Pokedex { + fn new() -> (Self, Command) { ( Pokedex::Loading, Command::perform(Pokemon::search(), Message::PokemonFound), -- 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/pokedex/src/main.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'examples/pokedex') diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index 099cc710..882a195d 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -3,15 +3,18 @@ use iced::widget::{self, column, container, image, row, text}; use iced::{Alignment, Command, Element, Length}; pub fn main() -> iced::Result { - iced::application(Pokedex::new, Pokedex::update, Pokedex::view) - .title(Pokedex::title) + iced::application(Pokedex::title, Pokedex::update, Pokedex::view) + .load(Pokedex::load) .run() } -#[derive(Debug)] +#[derive(Debug, Default)] enum Pokedex { + #[default] Loading, - Loaded { pokemon: Pokemon }, + Loaded { + pokemon: Pokemon, + }, Errored, } @@ -22,11 +25,8 @@ enum Message { } impl Pokedex { - fn new() -> (Self, Command) { - ( - Pokedex::Loading, - Command::perform(Pokemon::search(), Message::PokemonFound), - ) + fn load() -> Command { + Command::perform(Pokemon::search(), Message::PokemonFound) } fn title(&self) -> String { -- cgit From 3f81c524ccad2dd3fc4e6144f68b133132b1421b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 15:56:10 +0100 Subject: Reuse `Pokedex` search `Command` in `update` logic --- examples/pokedex/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/pokedex') diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index 882a195d..c737b87e 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -4,7 +4,7 @@ use iced::{Alignment, Command, Element, Length}; pub fn main() -> iced::Result { iced::application(Pokedex::title, Pokedex::update, Pokedex::view) - .load(Pokedex::load) + .load(Pokedex::search) .run() } @@ -25,7 +25,7 @@ enum Message { } impl Pokedex { - fn load() -> Command { + fn search() -> Command { Command::perform(Pokemon::search(), Message::PokemonFound) } @@ -56,7 +56,7 @@ impl Pokedex { _ => { *self = Pokedex::Loading; - Command::perform(Pokemon::search(), Message::PokemonFound) + Self::search() } }, } -- cgit