diff options
author | 2024-03-19 22:09:36 +0900 | |
---|---|---|
committer | 2024-03-19 22:09:36 +0900 | |
commit | f3a1c785b2743e9c48c3d28df0c6772ce579d7c8 (patch) | |
tree | 1b39799f45878d89b4f9e2f9bea8fa8a7ed07150 /examples/stopwatch/src/main.rs | |
parent | c9453cd55d84f0dd2ad0050208863d036c98843f (diff) | |
parent | 8ce16aba6204cb5c02a709cdf79c309f7b7e0196 (diff) | |
download | iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.gz iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.bz2 iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.zip |
Merge branch 'iced-rs:master' into viewer_content_fit
Diffstat (limited to 'examples/stopwatch/src/main.rs')
-rw-r--r-- | examples/stopwatch/src/main.rs | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index 56b7686e..b9eb19cf 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -1,27 +1,31 @@ use iced::alignment; -use iced::executor; use iced::keyboard; use iced::time; use iced::widget::{button, column, container, row, text}; -use iced::{ - Alignment, Application, Command, Element, Length, Settings, Subscription, - Theme, -}; +use iced::{Alignment, Element, Length, Subscription, Theme}; use std::time::{Duration, Instant}; pub fn main() -> iced::Result { - Stopwatch::run(Settings::default()) + iced::program("Stopwatch - Iced", Stopwatch::update, Stopwatch::view) + .subscription(Stopwatch::subscription) + .theme(Stopwatch::theme) + .run() } +#[derive(Default)] struct Stopwatch { duration: Duration, state: State, } +#[derive(Default)] enum State { + #[default] Idle, - Ticking { last_tick: Instant }, + Ticking { + last_tick: Instant, + }, } #[derive(Debug, Clone)] @@ -31,27 +35,8 @@ enum Message { Tick(Instant), } -impl Application for Stopwatch { - type Message = Message; - type Theme = Theme; - type Executor = executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Stopwatch, Command<Message>) { - ( - Stopwatch { - duration: Duration::default(), - state: State::Idle, - }, - Command::none(), - ) - } - - fn title(&self) -> String { - String::from("Stopwatch - Iced") - } - - fn update(&mut self, message: Message) -> Command<Message> { +impl Stopwatch { + fn update(&mut self, message: Message) { match message { Message::Toggle => match self.state { State::Idle => { @@ -73,8 +58,6 @@ impl Application for Stopwatch { self.duration = Duration::default(); } } - - Command::none() } fn subscription(&self) -> Subscription<Message> { |