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_window::input::mouse::{Mouse, MOUSE_BUTTON_LEFT};
let mouse = Mouse::coalesced().await;
// 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
On some platforms you must create a window before you can get mouse input.
Implementations§
Source§impl Mouse
impl Mouse
Sourcepub async fn coalesced() -> Self
pub async 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_window::input::mouse::Mouse;
let mouse = Mouse::coalesced().await;
// Now you can query mouse stateSourcepub fn window_pos(&self) -> Option<MouseWindowLocation>
pub fn window_pos(&self) -> Option<MouseWindowLocation>
Returns the MouseWindowLocation
§Platform specifics
You may need to create a window first, using APIs in this crate.
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_window::input::mouse::{Mouse, MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT};
let mouse = Mouse::coalesced().await;
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_window::input::mouse::Mouse;
let mut mouse = Mouse::coalesced().await;
// 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§
Auto Trait Implementations§
impl !RefUnwindSafe for Mouse
impl !UnwindSafe for Mouse
impl Freeze for Mouse
impl Send for Mouse
impl Sync for Mouse
impl Unpin for Mouse
impl UnsafeUnpin 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.