Struct comfy_wgpu::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: boolEither of the alt keys are down (option ⌥ on Mac).
ctrl: boolEither of the control keys are down.
When checking for keyboard shortcuts, consider using Self::command instead.
shift: boolEither of the shift keys are down.
mac_cmd: boolThe Mac ⌘ Command key. Should always be set to false on other platforms.
command: boolOn 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
impl Modifiers
pub const NONE: Modifiers = _
pub const ALT: Modifiers = _
pub const CTRL: Modifiers = _
pub const SHIFT: Modifiers = _
pub const ALT_SHIFT: Modifiers = _
Modifiers::ALT | Modifiers::SHIFT insteadsourcepub const fn plus(self, rhs: Modifiers) -> Modifiers
pub const fn plus(self, rhs: Modifiers) -> Modifiers
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),
);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.
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));sourcepub fn contains(&self, query: Modifiers) -> bool
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 PartialEq<Modifiers> for Modifiers
impl PartialEq<Modifiers> for Modifiers
impl Copy for Modifiers
impl Eq for Modifiers
impl StructuralEq for Modifiers
impl StructuralPartialEq for Modifiers
Auto Trait Implementations§
impl RefUnwindSafe for Modifiers
impl Send for Modifiers
impl Sync for Modifiers
impl Unpin for Modifiers
impl UnwindSafe for Modifiers
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.