input_mode_during

This commit is contained in:
2026-06-15 11:44:18 -05:00
parent 439fc44106
commit f2dc7861d9
4 changed files with 20 additions and 11 deletions
+9 -4
View File
@@ -2,10 +2,12 @@
//! //!
//! An animation encapsulates a time-bounded visual effect: it advances via //! An animation encapsulates a time-bounded visual effect: it advances via
//! [`update`](Animation::update), renders via [`draw`](Animation::draw), and //! [`update`](Animation::update), renders via [`draw`](Animation::draw), and
//! reports its layer and which [`InputMode`] to enter when it finishes. //! reports its layer, which [`InputMode`] is active while it runs
//! //! ([`input_mode_during`](Animation::input_mode_during)), and which mode to
//! **While any animation is running, all input is ignored.** The front-end checks //! enter when it finishes ([`input_mode_after`](Animation::input_mode_after)).
//! [`Ui::active_animation`](crate::ui::Ui::active_animation) before dispatching events. //! Most animations use the default `input_mode_during` ([`InputMode::Ignore`]),
//! but open animations may advertise an interactive mode so the overlay is
//! responsive before the animation completes.
use ratatui::buffer::Buffer; use ratatui::buffer::Buffer;
use ratatui::layout::Rect; use ratatui::layout::Rect;
@@ -28,6 +30,9 @@ pub trait Animation {
fn draw(&self, area: Rect, buf: &mut Buffer); fn draw(&self, area: Rect, buf: &mut Buffer);
/// Which region this animation draws to (board area vs. full overlay). /// Which region this animation draws to (board area vs. full overlay).
fn layer(&self) -> AnimationLayer; fn layer(&self) -> AnimationLayer;
/// Which [`InputMode`] is active while this animation is running.
/// Defaults to [`InputMode::Ignore`] (all input discarded).
fn input_mode_during(&self) -> InputMode { InputMode::Ignore }
/// Which [`InputMode`] to enter when the animation finishes. /// Which [`InputMode`] to enter when the animation finishes.
fn input_mode_after(&self) -> InputMode; fn input_mode_after(&self) -> InputMode;
} }
+6 -5
View File
@@ -25,8 +25,8 @@ pub enum InputMode {
Scroll, Scroll,
/// A menu overlay is active; all input is captured for menu navigation. /// A menu overlay is active; all input is captured for menu navigation.
Menu, Menu,
/// An animation is running; all input is discarded. /// An animation is running and has not claimed any input mode; all input is discarded.
Animating, Ignore,
/// Reserved for a post-transition freeze; nothing currently produces this mode. /// Reserved for a post-transition freeze; nothing currently produces this mode.
#[allow(dead_code)] #[allow(dead_code)]
Frozen, Frozen,
@@ -34,10 +34,11 @@ pub enum InputMode {
/// Determines the current input mode from game and UI state. /// Determines the current input mode from game and UI state.
pub(crate) fn current_input_mode(game: &GameState, ui: &Ui) -> InputMode { pub(crate) fn current_input_mode(game: &GameState, ui: &Ui) -> InputMode {
// Any active animation (or a pending transition waiting for its area) blocks input. // An active animation declares its own input mode; pending transitions ignore input.
if ui.active_animation.is_some() || ui.pending_transition.is_some() { if let Some(anim) = &ui.active_animation {
return InputMode::Animating; return anim.input_mode_during();
} }
if ui.pending_transition.is_some() { return InputMode::Ignore; }
if ui.menu.is_some() { return InputMode::Menu; } if ui.menu.is_some() { return InputMode::Menu; }
if game.active_scroll.is_some() { InputMode::Scroll } else { InputMode::Board } if game.active_scroll.is_some() { InputMode::Scroll } else { InputMode::Board }
} }
+2 -2
View File
@@ -138,8 +138,8 @@ fn run(
} }
InputMode::Menu => handle_menu_input(event, game, ui), InputMode::Menu => handle_menu_input(event, game, ui),
InputMode::Scroll => handle_scroll_input(event, game, ui), InputMode::Scroll => handle_scroll_input(event, game, ui),
// Animation running — discard all events. // Animation running and claiming no input mode — discard all events.
InputMode::Animating => {} InputMode::Ignore => {}
} }
} }
+3
View File
@@ -144,6 +144,9 @@ impl Animation for MenuOpenAnimation {
fn layer(&self) -> AnimationLayer { AnimationLayer::Overlay } fn layer(&self) -> AnimationLayer { AnimationLayer::Overlay }
/// The menu is interactive from the first frame of the open animation.
fn input_mode_during(&self) -> InputMode { InputMode::Menu }
fn input_mode_after(&self) -> InputMode { InputMode::Menu } fn input_mode_after(&self) -> InputMode { InputMode::Menu }
} }