pub struct MouseEvent {
pub kind: MouseEventKind,
pub column: u16,
pub row: u16,
pub modifiers: KeyModifiers,
}Expand description
A mouse event
§Example
match event {
Event::Mouse(mouse) => {
if mouse.is_left_click() {
println!("Left clicked at ({}, {})", mouse.column, mouse.row);
} else if mouse.is_scroll_up() {
println!("Scrolled up");
}
}
_ => {}
}Fields§
§kind: MouseEventKindThe kind of mouse event
column: u16Column (x coordinate)
row: u16Row (y coordinate)
modifiers: KeyModifiersKey modifiers held during the event
Implementations§
Source§impl MouseEvent
impl MouseEvent
Sourcepub fn new(
kind: MouseEventKind,
column: u16,
row: u16,
modifiers: KeyModifiers,
) -> MouseEvent
pub fn new( kind: MouseEventKind, column: u16, row: u16, modifiers: KeyModifiers, ) -> MouseEvent
Create a new mouse event
Sourcepub fn is_left_click(&self) -> bool
pub fn is_left_click(&self) -> bool
Check if this is a left button click (button down event)
Sourcepub fn is_right_click(&self) -> bool
pub fn is_right_click(&self) -> bool
Check if this is a right button click (button down event)
Sourcepub fn is_middle_click(&self) -> bool
pub fn is_middle_click(&self) -> bool
Check if this is a middle button click (button down event)
Sourcepub fn is_release(&self) -> bool
pub fn is_release(&self) -> bool
Check if this is a button release event
Sourcepub fn is_left_drag(&self) -> bool
pub fn is_left_drag(&self) -> bool
Check if this is a left button drag
Sourcepub fn is_right_drag(&self) -> bool
pub fn is_right_drag(&self) -> bool
Check if this is a right button drag
Sourcepub fn is_middle_drag(&self) -> bool
pub fn is_middle_drag(&self) -> bool
Check if this is a middle button drag
Sourcepub fn is_scroll_up(&self) -> bool
pub fn is_scroll_up(&self) -> bool
Check if this is a scroll up event
Sourcepub fn is_scroll_down(&self) -> bool
pub fn is_scroll_down(&self) -> bool
Check if this is a scroll down event
Sourcepub fn is_scroll_left(&self) -> bool
pub fn is_scroll_left(&self) -> bool
Check if this is a scroll left event
Sourcepub fn is_scroll_right(&self) -> bool
pub fn is_scroll_right(&self) -> bool
Check if this is a scroll right event
Get the button involved in this event, if any
Sourcepub fn is_within(&self, x: u16, y: u16, width: u16, height: u16) -> bool
pub fn is_within(&self, x: u16, y: u16, width: u16, height: u16) -> bool
Check if the mouse event occurred within a rectangular area
§Example
let (x, y, width, height) = (10, 10, 20, 10);
if mouse_event.is_within(x, y, width, height) {
// Mouse event is within the rectangle
}Sourcepub fn is_at(&self, column: u16, row: u16) -> bool
pub fn is_at(&self, column: u16, row: u16) -> bool
Check if the mouse event occurred at a specific position
Sourcepub fn has_modifier(&self, modifier: KeyModifiers) -> bool
pub fn has_modifier(&self, modifier: KeyModifiers) -> bool
Check if a modifier key was held during the event
Sourcepub fn has_modifiers(&self) -> bool
pub fn has_modifiers(&self) -> bool
Check if this mouse event has any modifiers
Sourcepub fn no_modifiers(&self) -> bool
pub fn no_modifiers(&self) -> bool
Check if this mouse event has no modifiers
Trait Implementations§
Source§impl Clone for MouseEvent
impl Clone for MouseEvent
Source§fn clone(&self) -> MouseEvent
fn clone(&self) -> MouseEvent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MouseEvent
impl Debug for MouseEvent
Source§impl From<MouseEvent> for MouseEvent
impl From<MouseEvent> for MouseEvent
Source§fn from(event: MouseEvent) -> MouseEvent
fn from(event: MouseEvent) -> MouseEvent
Source§impl PartialEq for MouseEvent
impl PartialEq for MouseEvent
impl Copy for MouseEvent
impl StructuralPartialEq for MouseEvent
Auto Trait Implementations§
impl Freeze for MouseEvent
impl RefUnwindSafe for MouseEvent
impl Send for MouseEvent
impl Sync for MouseEvent
impl Unpin for MouseEvent
impl UnwindSafe for MouseEvent
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Inspectable for T
impl<T> Inspectable for T
Source§fn inspect_if(self, condition: bool, label: &str) -> Selfwhere
Self: Debug,
fn inspect_if(self, condition: bool, label: &str) -> Selfwhere
Self: Debug,
Source§fn inspect_with<F>(self, label: &str, f: F) -> Self
fn inspect_with<F>(self, label: &str, f: F) -> Self
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more