diff options
author | 2024-03-17 18:06:37 +0100 | |
---|---|---|
committer | 2024-03-17 18:06:37 +0100 | |
commit | c4be7efce55ba8c2e11f3da70c41c91dab2698fa (patch) | |
tree | e22c7a165857257342c4892275d3509f255015a8 /examples/game_of_life | |
parent | 2eb3333623e227f9a74a67f562880b7dc1eecdd0 (diff) | |
download | iced-c4be7efce55ba8c2e11f3da70c41c91dab2698fa.tar.gz iced-c4be7efce55ba8c2e11f3da70c41c91dab2698fa.tar.bz2 iced-c4be7efce55ba8c2e11f3da70c41c91dab2698fa.zip |
Use `Program` API in `game_of_life` example
Diffstat (limited to 'examples/game_of_life')
-rw-r--r-- | examples/game_of_life/src/main.rs | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 5ec1a11c..2b0fae0b 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -5,32 +5,24 @@ mod preset; use grid::Grid; use preset::Preset; -use iced::executor; use iced::time; use iced::widget::{ button, checkbox, column, container, pick_list, row, slider, text, }; -use iced::window; -use iced::{ - Alignment, Application, Command, Element, Length, Settings, Subscription, - Theme, -}; +use iced::{Alignment, Command, Element, Length, Subscription, Theme}; use std::time::Duration; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - GameOfLife::run(Settings { - antialiasing: true, - window: window::Settings { - position: window::Position::Centered, - ..window::Settings::default() - }, - ..Settings::default() - }) + iced::program("Game of Life - Iced", GameOfLife::update, GameOfLife::view) + .subscription(GameOfLife::subscription) + .theme(|_| Theme::Dark) + .antialiasing(true) + .centered() + .run() } -#[derive(Default)] struct GameOfLife { grid: Grid, is_playing: bool, @@ -52,24 +44,16 @@ enum Message { PresetPicked(Preset), } -impl Application for GameOfLife { - type Message = Message; - type Theme = Theme; - type Executor = executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Self, Command<Message>) { - ( - Self { - speed: 5, - ..Self::default() - }, - Command::none(), - ) - } - - fn title(&self) -> String { - String::from("Game of Life - Iced") +impl GameOfLife { + fn new() -> Self { + Self { + grid: Grid::default(), + is_playing: false, + queued_ticks: 0, + speed: 5, + next_speed: None, + version: 0, + } } fn update(&mut self, message: Message) -> Command<Message> { @@ -154,9 +138,11 @@ impl Application for GameOfLife { .height(Length::Fill) .into() } +} - fn theme(&self) -> Theme { - Theme::Dark +impl Default for GameOfLife { + fn default() -> Self { + Self::new() } } |