Struct egui::Modifiers

source ·
pub struct Modifiers {
    pub alt: bool,
    pub ctrl: bool,
    pub shift: bool,
    pub mac_cmd: bool,
    pub command: bool,
}
Expand description

State of the modifier keys. These must be fed to egui.

The best way to compare Modifiers is by using Modifiers::matches.

NOTE: For cross-platform uses, ALT+SHIFT is a bad combination of modifiers as on mac that is how you type special characters, so those key presses are usually not reported to egui.

Fields§

§alt: bool

Either of the alt keys are down (option ⌥ on Mac).

§ctrl: bool

Either of the control keys are down. When checking for keyboard shortcuts, consider using Self::command instead.

§shift: bool

Either of the shift keys are down.

§mac_cmd: bool

The Mac ⌘ Command key. Should always be set to false on other platforms.

§command: bool

On Windows and Linux, set this to the same value as ctrl. On Mac, this should be set whenever one of the ⌘ Command keys are down (same as mac_cmd). This is so that egui can, for instance, select all text by checking for command + A and it will work on both Mac and Windows.

Implementations§

source§

impl Modifiers

source

pub const NONE: Self = _

source

pub const ALT: Self = _

source

pub const CTRL: Self = _

source

pub const SHIFT: Self = _

source

pub const ALT_SHIFT: Self = _

👎Deprecated: Use Modifiers::ALT | Modifiers::SHIFT instead
source

pub const MAC_CMD: Self = _

The Mac ⌘ Command key

source

pub const COMMAND: Self = _

On Mac: ⌘ Command key, elsewhere: Ctrl key

source

pub const fn plus(self, rhs: Self) -> Self

assert_eq!(
    Modifiers::CTRL | Modifiers::ALT,
    Modifiers { ctrl: true, alt: true, ..Default::default() }
);
assert_eq!(
    Modifiers::ALT.plus(Modifiers::CTRL),
    Modifiers::CTRL.plus(Modifiers::ALT),
);
assert_eq!(
    Modifiers::CTRL | Modifiers::ALT,
    Modifiers::CTRL.plus(Modifiers::ALT),
);
source

pub fn is_none(&self) -> bool

source

pub fn any(&self) -> bool

source

pub fn all(&self) -> bool

source

pub fn shift_only(&self) -> bool

Is shift the only pressed button?

source

pub fn command_only(&self) -> bool

true if only Self::ctrl or only Self::mac_cmd is pressed.

source

pub fn matches(&self, pattern: Modifiers) -> bool

Check for equality but with proper handling of Self::command.

Example:
if current_modifiers.matches(Modifiers::ALT | Modifiers::SHIFT) {
    // Alt and Shift are pressed, and nothing else
}
Behavior:
assert!(Modifiers::CTRL.matches(Modifiers::CTRL));
assert!(!Modifiers::CTRL.matches(Modifiers::CTRL | Modifiers::SHIFT));
assert!(!(Modifiers::CTRL | Modifiers::SHIFT).matches(Modifiers::CTRL));
assert!((Modifiers::CTRL | Modifiers::COMMAND).matches(Modifiers::CTRL));
assert!((Modifiers::CTRL | Modifiers::COMMAND).matches(Modifiers::COMMAND));
assert!((Modifiers::MAC_CMD | Modifiers::COMMAND).matches(Modifiers::COMMAND));
assert!(!Modifiers::COMMAND.matches(Modifiers::MAC_CMD));
source

pub fn contains(&self, query: Modifiers) -> bool

Whether another set of modifiers is contained in this set of modifiers with proper handling of Self::command.

assert!(Modifiers::default().contains(Modifiers::default()));
assert!(Modifiers::CTRL.contains(Modifiers::default()));
assert!(Modifiers::CTRL.contains(Modifiers::CTRL));
assert!(Modifiers::CTRL.contains(Modifiers::COMMAND));
assert!(Modifiers::MAC_CMD.contains(Modifiers::COMMAND));
assert!(Modifiers::COMMAND.contains(Modifiers::MAC_CMD));
assert!(Modifiers::COMMAND.contains(Modifiers::CTRL));
assert!(!(Modifiers::ALT | Modifiers::CTRL).contains(Modifiers::SHIFT));
assert!((Modifiers::CTRL | Modifiers::SHIFT).contains(Modifiers::CTRL));
assert!(!Modifiers::CTRL.contains(Modifiers::CTRL | Modifiers::SHIFT));

Trait Implementations§

source§

impl BitOr for Modifiers

§

type Output = Modifiers

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
source§

impl Clone for Modifiers

source§

fn clone(&self) -> Modifiers

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Modifiers

source§

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

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

impl Default for Modifiers

source§

fn default() -> Modifiers

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

impl<'de> Deserialize<'de> for Modifiers

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Hash for Modifiers

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Modifiers

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Modifiers

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Modifiers

source§

impl Eq for Modifiers

source§

impl StructuralEq for Modifiers

source§

impl StructuralPartialEq for Modifiers

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> SerializableAny for Twhere T: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync,