Implement Program::load to specify startup Command

This commit is contained in:
Héctor Ramón Jiménez 2024-03-16 15:53:03 +01:00
parent 5a986897d2
commit 93ae790da1
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 122 additions and 77 deletions

View file

@ -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 {