From 310efeea3932be8cffc15dfc32ca4f04f0b9a647 Mon Sep 17 00:00:00 2001 From: Andrzej Nestoruk Date: Thu, 21 Nov 2024 23:27:24 +0100 Subject: [PATCH] add reset button --- src/main.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index e2e417d..7888fe7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,6 +43,7 @@ impl Default for TimerApp { #[derive(Debug, Clone)] enum Message { Increment, + Reset, UpdateDelay(String), UpdateText(String), EventHappened, @@ -77,6 +78,10 @@ impl TimerApp { } } + Message::Reset => { + self.counter = 0; + } + Message::UpdateDelay(delay_text) => { self.delay_text = delay_text; match i32::from_str(self.delay_text.as_str()) { @@ -113,22 +118,27 @@ impl TimerApp { text(format!("Next break in {} seconds", self.delay - (self.counter % self.delay))), button(text("Increment")) - .width(200) + .width(Fill) .on_press(Message::Increment), + button(text("Reset")) + .width(Fill) + .on_press(Message::Reset), + text_input("Delay in seconds", &self.delay_text) - .width(200) + .width(Fill) .on_input(Message::UpdateDelay), text_input("Notification text", &self.text) - .width(200) + .width(Fill) .on_input(Message::UpdateText), text(&self.log_message) .size(10) - .width(200) + .width(Fill) .height(100), - ].spacing(20)) + ].width(300).spacing(20) + ) .style(|theme: &Theme| { container::Style::default().border( border::color(theme.extended_palette().primary.weak.color).width(5)