diff --git a/async/ratatui-counter/src/action.rs b/async/ratatui-counter/src/action.rs index 8db5e1d..251d5d1 100644 --- a/async/ratatui-counter/src/action.rs +++ b/async/ratatui-counter/src/action.rs @@ -28,6 +28,8 @@ pub enum Action { EnterInsert, EnterProcessing, ExitProcessing, + EnterHomeInput, + EnterHomeNormal, Update, } //// ANCHOR_END: action_enum diff --git a/async/ratatui-counter/src/app.rs b/async/ratatui-counter/src/app.rs index da0cd81..fb60330 100644 --- a/async/ratatui-counter/src/app.rs +++ b/async/ratatui-counter/src/app.rs @@ -104,6 +104,8 @@ impl App { Action::Quit => self.should_quit = true, Action::Suspend => self.should_suspend = true, Action::Resume => self.should_suspend = false, + Action::EnterHomeInput => self.mode = Mode::HomeInput, + Action::EnterHomeNormal => self.mode = Mode::Home, Action::Resize(w, h) => { tui.resize(Rect::new(0, 0, w, h))?; tui.draw(|f| { diff --git a/async/ratatui-counter/src/components/home.rs b/async/ratatui-counter/src/components/home.rs index 607fb28..4713aab 100644 --- a/async/ratatui-counter/src/components/home.rs +++ b/async/ratatui-counter/src/components/home.rs @@ -265,9 +265,11 @@ impl Component for Home { Action::CompleteInput(s) => self.add(s), Action::EnterNormal => { self.mode = Mode::Normal; + return Ok(Some(Action::EnterHomeNormal)); }, Action::EnterInsert => { self.mode = Mode::Insert; + return Ok(Some(Action::EnterHomeInput)); }, Action::EnterProcessing => { self.mode = Mode::Processing; @@ -281,38 +283,37 @@ impl Component for Home { Ok(None) } - fn handle_events(&mut self, event: Option) -> Result> { - if let Some(Event::Mouse(MouseEvent { kind, column, row, modifiers })) = event { - // TODO: simulate better button clicks - self.increment_btn_state = ButtonState::Normal; - self.decrement_btn_state = ButtonState::Normal; - if column >= self.increment_rect.left() - && column <= self.increment_rect.right() - && row >= self.increment_rect.top() - && row <= self.increment_rect.bottom() - { - if kind == MouseEventKind::Moved { - self.increment_btn_state = ButtonState::Hover; - } else if kind == MouseEventKind::Down(MouseButton::Left) { - self.increment_btn_state = ButtonState::Clicked; - return Ok(Some(Action::ScheduleIncrement)); - } else if kind == MouseEventKind::Up(MouseButton::Left) { - self.increment_btn_state = ButtonState::Hover; - } - }; - if column >= self.decrement_rect.left() - && column <= self.decrement_rect.right() - && row >= self.decrement_rect.top() - && row <= self.decrement_rect.bottom() - { - if kind == MouseEventKind::Moved { - self.decrement_btn_state = ButtonState::Hover; - } else if kind == MouseEventKind::Down(MouseButton::Left) { - self.decrement_btn_state = ButtonState::Clicked; - return Ok(Some(Action::ScheduleDecrement)); - } else if kind == MouseEventKind::Up(MouseButton::Left) { - self.decrement_btn_state = ButtonState::Hover; - } + fn handle_mouse_events(&mut self, event: MouseEvent) -> Result> { + let MouseEvent { kind, column, row, modifiers } = event; + // TODO: simulate better button clicks + self.increment_btn_state = ButtonState::Normal; + self.decrement_btn_state = ButtonState::Normal; + if column >= self.increment_rect.left() + && column <= self.increment_rect.right() + && row >= self.increment_rect.top() + && row <= self.increment_rect.bottom() + { + if kind == MouseEventKind::Moved { + self.increment_btn_state = ButtonState::Hover; + } else if kind == MouseEventKind::Down(MouseButton::Left) { + self.increment_btn_state = ButtonState::Clicked; + return Ok(Some(Action::ScheduleIncrement)); + } else if kind == MouseEventKind::Up(MouseButton::Left) { + self.increment_btn_state = ButtonState::Hover; + } + }; + if column >= self.decrement_rect.left() + && column <= self.decrement_rect.right() + && row >= self.decrement_rect.top() + && row <= self.decrement_rect.bottom() + { + if kind == MouseEventKind::Moved { + self.decrement_btn_state = ButtonState::Hover; + } else if kind == MouseEventKind::Down(MouseButton::Left) { + self.decrement_btn_state = ButtonState::Clicked; + return Ok(Some(Action::ScheduleDecrement)); + } else if kind == MouseEventKind::Up(MouseButton::Left) { + self.decrement_btn_state = ButtonState::Hover; } } Ok(None) diff --git a/async/ratatui-counter/src/mode.rs b/async/ratatui-counter/src/mode.rs index dde06b1..42a1002 100644 --- a/async/ratatui-counter/src/mode.rs +++ b/async/ratatui-counter/src/mode.rs @@ -4,4 +4,5 @@ use serde::{Deserialize, Serialize}; pub enum Mode { #[default] Home, + HomeInput, }