Skip to main content

MouseButtonManager

Struct MouseButtonManager 

Source
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

Source

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);
Source

pub fn update(&mut self, button_pressed: bool, delta_time: f32, hovered: bool)

Advances state for one frame.

  • button_pressed — raw button state from a MouseProvider.
  • delta_time — elapsed seconds since the last frame.
  • hovered — whether the cursor is over the target region.
Source

pub fn reset_cooldown(&mut self)

Clears the cooldown immediately, allowing the next press to register.

Source

pub fn change_cooldown(&mut self, cooldown: f32)

Sets the cooldown to cooldown seconds.

Call this after handling a click to debounce further input.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.