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
.
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
sourceimpl Modifiers
impl Modifiers
pub fn new() -> Self
pub const NONE: Self = _
pub const ALT: Self = _
pub const CTRL: Self = _
pub const SHIFT: Self = _
pub const ALT_SHIFT: Self = _
pub fn is_none(&self) -> bool
pub fn any(&self) -> bool
sourcepub fn shift_only(&self) -> bool
pub fn shift_only(&self) -> bool
Is shift the only pressed button?
sourcepub fn command_only(&self) -> bool
pub fn command_only(&self) -> bool
true if only Self::ctrl
or only Self::mac_cmd
is pressed.
sourcepub fn matches(&self, pattern: Modifiers) -> bool
pub fn matches(&self, pattern: Modifiers) -> bool
Check for equality but with proper handling of Self::command
.
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));