pub struct MouseButtonManager { /* private fields */ }Expand description
Tracks click signals for a single mouse button with a configurable strategy.
Call update every frame with the raw button state, frame
delta time, and whether the target region is hovered. Then query
is_clicked.
§Cooldown
The cooldown decrements each update. While cooldown > 0, button presses
are ignored and is_clicked() returns false. After handling a click, call
change_cooldown to debounce subsequent clicks.
Implementations§
Source§impl MouseButtonManager
impl MouseButtonManager
Sourcepub fn new(strategy: MouseClickingStrategy, cooldown: f32) -> MouseButtonManager
pub fn new(strategy: MouseClickingStrategy, cooldown: f32) -> MouseButtonManager
Creates a manager with the given clicking strategy and initial cooldown.
For hold strategies (MouseClickingStrategy::Hold and
MouseClickingStrategy::RisingHold), initialize struct-variant fields
before passing the strategy here, for example:
use cotis_interactivity::mouse::{MouseButtonManager, MouseClickingStrategy};
let strategy = MouseClickingStrategy::Hold { time: 0.0, goal: 0.5 };
let manager = MouseButtonManager::new(strategy, 0.0);Sourcepub fn update(&mut self, button_pressed: bool, delta_time: f32, hovered: bool)
pub fn update(&mut self, button_pressed: bool, delta_time: f32, hovered: bool)
Advances state for one frame.
button_pressed— raw button state from aMouseProvider.delta_time— elapsed seconds since the last frame.hovered— whether the cursor is over the target region.
Sourcepub fn reset_cooldown(&mut self)
pub fn reset_cooldown(&mut self)
Clears the cooldown immediately, allowing the next press to register.
Sourcepub fn change_cooldown(&mut self, cooldown: f32)
pub fn change_cooldown(&mut self, cooldown: f32)
Sets the cooldown to cooldown seconds.
Call this after handling a click to debounce further input.
Sourcepub fn is_clicked(&self) -> bool
pub fn is_clicked(&self) -> bool
Returns whether a click signal is active this frame according to the strategy.
Always returns false while the cooldown is positive.