summaryrefslogtreecommitdiffstats
path: root/examples/pokedex
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-16 15:53:03 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-16 15:54:37 +0100
commit93ae790da14544667176ecdbdd6a4eaaa98a248a (patch)
tree4af03301f9a16049d29be305c48b4054a3afee99 /examples/pokedex
parent5a986897d22f6d79a7a1fbaa4f3d1aaa1f9ca3bb (diff)
downloadiced-93ae790da14544667176ecdbdd6a4eaaa98a248a.tar.gz
iced-93ae790da14544667176ecdbdd6a4eaaa98a248a.tar.bz2
iced-93ae790da14544667176ecdbdd6a4eaaa98a248a.zip
Implement `Program::load` to specify startup `Command`
Diffstat (limited to 'examples/pokedex')
-rw-r--r--examples/pokedex/src/main.rs18
1 files changed, 9 insertions, 9 deletions
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<Message>) {
- (
- Pokedex::Loading,
- Command::perform(Pokemon::search(), Message::PokemonFound),
- )
+ fn load() -> Command<Message> {
+ Command::perform(Pokemon::search(), Message::PokemonFound)
}
fn title(&self) -> String {