summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-18 07:10:36 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-18 07:10:36 +0100
commit50b02d41a01ad66e08045b320a30a0f5d76ee2f9 (patch)
treeb5e5847cf32d54aeae327828422d13d53b1b56bb
parenteba2ded88a92479bee93b727b31f5f84899339cf (diff)
downloadiced-50b02d41a01ad66e08045b320a30a0f5d76ee2f9.tar.gz
iced-50b02d41a01ad66e08045b320a30a0f5d76ee2f9.tar.bz2
iced-50b02d41a01ad66e08045b320a30a0f5d76ee2f9.zip
Check only for partial match of modifier keys
-rw-r--r--core/src/keyboard/modifiers_state.rs17
-rw-r--r--native/src/widget/pane_grid.rs8
2 files changed, 21 insertions, 4 deletions
diff --git a/core/src/keyboard/modifiers_state.rs b/core/src/keyboard/modifiers_state.rs
index 3058c065..0cfc6d69 100644
--- a/core/src/keyboard/modifiers_state.rs
+++ b/core/src/keyboard/modifiers_state.rs
@@ -1,5 +1,5 @@
/// The current state of the keyboard modifiers.
-#[derive(Debug, Clone, Copy, PartialEq, Default)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct ModifiersState {
/// Whether a shift key is pressed
pub shift: bool,
@@ -13,3 +13,18 @@ pub struct ModifiersState {
/// Whether a logo key is pressed (e.g. windows key, command key...)
pub logo: bool,
}
+
+impl ModifiersState {
+ /// Returns true if the current [`ModifiersState`] has at least the same
+ /// modifiers enabled as the given value, and false otherwise.
+ ///
+ /// [`ModifiersState`]: struct.ModifiersState.html
+ pub fn matches(&self, modifiers: ModifiersState) -> bool {
+ let shift = !modifiers.shift || modifiers.shift && self.shift;
+ let control = !modifiers.control || modifiers.control && self.control;
+ let alt = !modifiers.alt || modifiers.alt && self.alt;
+ let logo = !modifiers.logo || modifiers.logo && self.logo;
+
+ shift && control && alt && logo
+ }
+}
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index 5212a147..a2e4ebaa 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -260,7 +260,9 @@ where
if let Some(((pane, _), _)) = clicked_region.next() {
match &self.on_drag {
Some(on_drag)
- if *self.modifiers == self.modifier_keys =>
+ if self
+ .modifiers
+ .matches(self.modifier_keys) =>
{
self.state.pick_pane(pane);
@@ -309,7 +311,7 @@ where
state: ButtonState::Pressed,
}) if self.on_resize.is_some()
&& self.state.picked_pane().is_none()
- && *self.modifiers == self.modifier_keys =>
+ && self.modifiers.matches(self.modifier_keys) =>
{
let bounds = layout.bounds();
let relative_cursor = Point::new(
@@ -374,7 +376,7 @@ where
// TODO: Discard when event is captured
if state == ButtonState::Pressed {
if let Some(_) = self.state.idle_pane() {
- if modifiers == self.modifier_keys {
+ if modifiers.matches(self.modifier_keys) {
if let Some(message) =
on_key_press(KeyPressEvent {
key_code,