Skip to content

Commit

Permalink
add reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
anestoruk committed Nov 21, 2024
1 parent 439d64c commit 310efee
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl Default for TimerApp {
#[derive(Debug, Clone)]
enum Message {
Increment,
Reset,
UpdateDelay(String),
UpdateText(String),
EventHappened,
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 310efee

Please sign in to comment.