Skip to main content

MouseButton

Enum MouseButton 

Source
pub enum MouseButton {
    Primary,
    Secondary,
    Middle,
    Other(u8),
}
Expand description

Which button a press came from — driver-facing rather than shaped after any one windowing library, so every driver maps its own vocabulary onto this one.

Only MouseButton::Primary drives the pointer model: it presses, drags, places the caret and produces on_click. A MouseButton::Secondary press asks the node under it for a context menu (NodeSpec::on_context_menu) and touches nothing else — not focus, not the caret, not a scrollbar thumb — because a right-click on a selection has to leave that selection alone. Every non-primary button, the secondary one included, reaches a node that claims it with NodeSpec::on_button: its press, the motion while it is held and its release, captured by that node; a claimed secondary press is that node’s instead of a context menu. A non-primary press moves no focus, caret, selection or scrollbar either way.

Variants§

§

Primary

The button that clicks and drags. The OS has already applied a left-handed swap, so this is not necessarily the left one.

§

Secondary

The context-menu button.

§

Middle

§

Other(u8)

A button this vocabulary does not name (back, forward, thumb buttons), by driver index.

Implementations§

Source§

impl MouseButton

Source

pub const NAMED: [MouseButton; 3]

The three buttons that have a name, in code order. Other has no name: a binding that needs one takes a MouseButton::code.

Source

pub fn code(self) -> u32

The number bindings pass buttons as: 0 primary, 1 secondary, 2 middle, 3 + n for Other(n).

Source

pub fn from_code(code: u32) -> Self

Inverse of MouseButton::code; anything past the named three is an Other, saturating rather than wrapping.

Source

pub fn name(self) -> Option<&'static str>

The wire name of a named button ("primary", "secondary", "middle"); None for an Other.

Source

pub fn from_name(name: &str) -> Option<Self>

The three named buttons by name, for bindings that spell them as strings: the inverse of Self::name.

Source

pub fn to_value(self) -> Value

The value a button event carries for this button: its name for a named one, its MouseButton::code for an Other.

Trait Implementations§

Source§

impl Clone for MouseButton

Source§

fn clone(&self) -> Self

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 MouseButton

Source§

impl Debug for MouseButton

Source§

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

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

impl Default for MouseButton

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for MouseButton

Source§

impl PartialEq for MouseButton

Source§

fn eq(&self, other: &Self) -> 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 MouseButton

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.