mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Add Modifiers::matches_any (#7123)
* Part of https://github.com/emilk/egui/issues/7120
This commit is contained in:
@@ -842,6 +842,37 @@ impl Modifiers {
|
||||
self.cmd_ctrl_matches(pattern)
|
||||
}
|
||||
|
||||
/// Check if any of the modifiers match exactly.
|
||||
///
|
||||
/// Returns true if the same modifier is pressed in `self` as in `pattern`,
|
||||
/// for at least one modifier.
|
||||
///
|
||||
/// ## Behavior:
|
||||
/// ```
|
||||
/// # use egui::Modifiers;
|
||||
/// assert!(Modifiers::CTRL.matches_any(Modifiers::CTRL));
|
||||
/// assert!(Modifiers::CTRL.matches_any(Modifiers::CTRL | Modifiers::SHIFT));
|
||||
/// assert!((Modifiers::CTRL | Modifiers::SHIFT).matches_any(Modifiers::CTRL));
|
||||
/// ```
|
||||
pub fn matches_any(&self, pattern: Self) -> bool {
|
||||
if self.alt && pattern.alt {
|
||||
return true;
|
||||
}
|
||||
if self.shift && pattern.shift {
|
||||
return true;
|
||||
}
|
||||
if self.ctrl && pattern.ctrl {
|
||||
return true;
|
||||
}
|
||||
if self.mac_cmd && pattern.mac_cmd {
|
||||
return true;
|
||||
}
|
||||
if (self.mac_cmd || self.command || self.ctrl) && pattern.command {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Checks only cmd/ctrl, not alt/shift.
|
||||
///
|
||||
/// `self` here are the currently pressed modifiers,
|
||||
|
||||
Reference in New Issue
Block a user