Skip to main content

MouseEvent

Struct MouseEvent 

Source
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: MouseEventKind

The kind of mouse event

§column: u16

Column (x coordinate)

§row: u16

Row (y coordinate)

§modifiers: KeyModifiers

Key modifiers held during the event

Implementations§

Source§

impl MouseEvent

Source

pub fn new( kind: MouseEventKind, column: u16, row: u16, modifiers: KeyModifiers, ) -> MouseEvent

Create a new mouse event

Source

pub fn is_left_click(&self) -> bool

Check if this is a left button click (button down event)

Source

pub fn is_right_click(&self) -> bool

Check if this is a right button click (button down event)

Source

pub fn is_middle_click(&self) -> bool

Check if this is a middle button click (button down event)

Source

pub fn is_click(&self) -> bool

Check if this is any button click (button down event)

Source

pub fn is_release(&self) -> bool

Check if this is a button release event

Source

pub fn is_drag(&self) -> bool

Check if this is a drag event (mouse moved while button pressed)

Source

pub fn is_left_drag(&self) -> bool

Check if this is a left button drag

Source

pub fn is_right_drag(&self) -> bool

Check if this is a right button drag

Source

pub fn is_middle_drag(&self) -> bool

Check if this is a middle button drag

Source

pub fn is_scroll_up(&self) -> bool

Check if this is a scroll up event

Source

pub fn is_scroll_down(&self) -> bool

Check if this is a scroll down event

Source

pub fn is_scroll_left(&self) -> bool

Check if this is a scroll left event

Source

pub fn is_scroll_right(&self) -> bool

Check if this is a scroll right event

Source

pub fn is_scroll(&self) -> bool

Check if this is any scroll event

Source

pub fn is_move(&self) -> bool

Check if this is a mouse move event (without button pressed)

Source

pub fn button(&self) -> Option<MouseButton>

Get the button involved in this event, if any

Source

pub fn position(&self) -> (u16, u16)

Get the position as a tuple (column, row)

Source

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
}
Source

pub fn is_at(&self, column: u16, row: u16) -> bool

Check if the mouse event occurred at a specific position

Source

pub fn has_modifier(&self, modifier: KeyModifiers) -> bool

Check if a modifier key was held during the event

Source

pub fn is_ctrl(&self) -> bool

Check if control key is held

Source

pub fn is_alt(&self) -> bool

Check if alt key is held

Source

pub fn is_shift(&self) -> bool

Check if shift key is held

Source

pub fn has_modifiers(&self) -> bool

Check if this mouse event has any modifiers

Source

pub fn no_modifiers(&self) -> bool

Check if this mouse event has no modifiers

Trait Implementations§

Source§

impl Clone for MouseEvent

Source§

fn clone(&self) -> MouseEvent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MouseEvent

Source§

impl Debug for MouseEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<MouseEvent> for MouseEvent

Source§

fn from(event: MouseEvent) -> MouseEvent

Converts to this type from the input type.
Source§

impl PartialEq for MouseEvent

Source§

fn eq(&self, other: &MouseEvent) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MouseEvent

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Inspectable for T

Source§

fn inspect(self, label: &str) -> Self
where Self: Debug,

Inspect this value with a label
Source§

fn inspect_if(self, condition: bool, label: &str) -> Self
where Self: Debug,

Conditionally inspect this value
Source§

fn inspect_with<F>(self, label: &str, f: F) -> Self
where F: FnOnce(&Self) -> String,

Inspect with a custom formatter
Source§

fn tap<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Tap into the value for side effects
Source§

fn tap_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&Self),

Conditionally tap into the value
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> Message for T
where T: Send + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.