pub struct Mouse { /* private fields */ }Expand description
Provides access to mouse input from all mice on the system.
This type coalesces input from all connected mice into a single interface. It provides access to:
- Mouse position within windows
- Button states (left, right, middle, and others)
- Accumulated scroll deltas
§Examples
use app_input::mouse::{Mouse, MOUSE_BUTTON_LEFT};
let mouse = Mouse::coalesced();
// Check if left button is pressed
if mouse.button_state(MOUSE_BUTTON_LEFT) {
println!("Left button is pressed");
}
// Get mouse position
if let Some(pos) = mouse.window_pos() {
println!("Mouse at ({}, {})", pos.pos_x(), pos.pos_y());
}§Platform-specific behavior
Different platforms require different integration:
- macOS and wasm: Work out of the box
- Windows: You must call
window_procfrom your window procedure - Linux: You must call the appropriate wayland event handlers
Implementations§
Source§impl Mouse
impl Mouse
Sourcepub fn coalesced() -> Self
pub fn coalesced() -> Self
Creates a new Mouse instance that coalesces input from all mice on the system.
This is the primary way to create a Mouse instance. The returned object
will aggregate input from all connected mice.
§Examples
use app_input::mouse::Mouse;
let mouse = Mouse::coalesced();
// Now you can query mouse stateSourcepub fn window_pos(&self) -> Option<MouseWindowLocation>
pub fn window_pos(&self) -> Option<MouseWindowLocation>
Returns the MouseWindowLocation
§Platform specifics
- macOS and wasm require no special considerations.
- On windows, you must call [crate::window_proc] from your window.
-
- On Linux,you must call from appropriate wayland events:
Determines if the specified mouse button is currently pressed.
§Arguments
button- The button to check. Use constants likeMOUSE_BUTTON_LEFT,MOUSE_BUTTON_RIGHT, orMOUSE_BUTTON_MIDDLE. Other button values (e.g., for mice with additional buttons) may be supported on a best-effort basis.
§Returns
true if the button is currently pressed, false otherwise.
§Examples
use app_input::mouse::{Mouse, MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT};
let mouse = Mouse::coalesced();
if mouse.button_state(MOUSE_BUTTON_LEFT) {
println!("Left button is pressed");
}
if mouse.button_state(MOUSE_BUTTON_RIGHT) {
println!("Right button is pressed");
}Sourcepub fn load_clear_scroll_delta(&mut self) -> (f64, f64)
pub fn load_clear_scroll_delta(&mut self) -> (f64, f64)
Returns the accumulated scroll delta and resets it to zero.
This method is useful for implementing scroll handling in your application. The scroll delta accumulates between calls, so you should call this periodically (e.g., once per frame) to process scroll events.
§Returns
A tuple (delta_x, delta_y) containing the horizontal and vertical
scroll amounts since the last call to this method.
§Examples
use app_input::mouse::Mouse;
let mut mouse = Mouse::coalesced();
// In your update loop:
let (scroll_x, scroll_y) = mouse.load_clear_scroll_delta();
if scroll_y != 0.0 {
println!("Scrolled vertically by {}", scroll_y);
}Trait Implementations§
Source§impl Default for Mouse
impl Default for Mouse
Source§fn default() -> Self
fn default() -> Self
Creates a default Mouse instance using Mouse::coalesced().
§Examples
use app_input::mouse::Mouse;
let mouse = Mouse::default();
// Equivalent to Mouse::coalesced()impl Eq for Mouse
Auto Trait Implementations§
impl Freeze for Mouse
impl !RefUnwindSafe for Mouse
impl Send for Mouse
impl Sync for Mouse
impl Unpin for Mouse
impl UnsafeUnpin for Mouse
impl !UnwindSafe for Mouse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.