diff options
Diffstat (limited to 'examples/pokedex')
| -rw-r--r-- | examples/pokedex/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/pokedex/src/main.rs | 33 | 
2 files changed, 18 insertions, 17 deletions
| diff --git a/examples/pokedex/Cargo.toml b/examples/pokedex/Cargo.toml index bf7e1e35..1a6d5445 100644 --- a/examples/pokedex/Cargo.toml +++ b/examples/pokedex/Cargo.toml @@ -16,7 +16,7 @@ version = "1.0"  features = ["derive"]  [dependencies.reqwest] -version = "0.11" +version = "0.12"  default-features = false  features = ["json", "rustls-tls"] diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index b22ffe7f..2e972f6b 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -1,20 +1,16 @@  use iced::futures;  use iced::widget::{self, center, column, image, row, text}; -use iced::{Alignment, Element, Length, Task}; +use iced::{Center, Element, Fill, Right, Task};  pub fn main() -> iced::Result {      iced::application(Pokedex::title, Pokedex::update, Pokedex::view) -        .load(Pokedex::search) -        .run() +        .run_with(Pokedex::new)  } -#[derive(Debug, Default)] +#[derive(Debug)]  enum Pokedex { -    #[default]      Loading, -    Loaded { -        pokemon: Pokemon, -    }, +    Loaded { pokemon: Pokemon },      Errored,  } @@ -25,6 +21,10 @@ enum Message {  }  impl Pokedex { +    fn new() -> (Self, Task<Message>) { +        (Self::Loading, Self::search()) +    } +      fn search() -> Task<Message> {          Task::perform(Pokemon::search(), Message::PokemonFound)      } @@ -63,10 +63,9 @@ impl Pokedex {      }      fn view(&self) -> Element<Message> { -        let content = match self { +        let content: Element<_> = match self {              Pokedex::Loading => { -                column![text("Searching for Pokémon...").size(40),] -                    .width(Length::Shrink) +                text("Searching for Pokémon...").size(40).into()              }              Pokedex::Loaded { pokemon } => column![                  pokemon.view(), @@ -74,13 +73,15 @@ impl Pokedex {              ]              .max_width(500)              .spacing(20) -            .align_items(Alignment::End), +            .align_x(Right) +            .into(),              Pokedex::Errored => column![                  text("Whoops! Something went wrong...").size(40),                  button("Try again").on_press(Message::Search)              ]              .spacing(20) -            .align_items(Alignment::End), +            .align_x(Right) +            .into(),          };          center(content).into() @@ -103,17 +104,17 @@ impl Pokemon {              image::viewer(self.image.clone()),              column![                  row![ -                    text(&self.name).size(30).width(Length::Fill), +                    text(&self.name).size(30).width(Fill),                      text!("#{}", self.number).size(20).color([0.5, 0.5, 0.5]),                  ] -                .align_items(Alignment::Center) +                .align_y(Center)                  .spacing(20),                  self.description.as_ref(),              ]              .spacing(20),          ]          .spacing(20) -        .align_items(Alignment::Center) +        .align_y(Center)          .into()      } | 
