summaryrefslogtreecommitdiffstats
path: root/examples/pokedex/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pokedex/src/main.rs')
-rw-r--r--examples/pokedex/src/main.rs33
1 files changed, 17 insertions, 16 deletions
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()
}