diff options
author | 2020-03-20 12:10:52 +0100 | |
---|---|---|
committer | 2020-03-20 12:10:52 +0100 | |
commit | f7ec679fec1b69c6dc5bc12d60627629f086bf22 (patch) | |
tree | 58ec4dd11e50f11ef85b972fee211930e7a0e7c0 /core | |
parent | 93f5640a2dc06d8f1bf2b0d033d45c62f8985380 (diff) | |
parent | fb744a338c1b7566a3db9a3d24c03729b4858217 (diff) | |
download | iced-f7ec679fec1b69c6dc5bc12d60627629f086bf22.tar.gz iced-f7ec679fec1b69c6dc5bc12d60627629f086bf22.tar.bz2 iced-f7ec679fec1b69c6dc5bc12d60627629f086bf22.zip |
Merge pull request #224 from hecrj/feature/panes-widget
Pane grid widget
Diffstat (limited to '')
-rw-r--r-- | core/src/keyboard.rs | 6 | ||||
-rw-r--r-- | core/src/keyboard/key_code.rs (renamed from native/src/input/keyboard/key_code.rs) | 0 | ||||
-rw-r--r-- | core/src/keyboard/modifiers_state.rs | 30 | ||||
-rw-r--r-- | core/src/lib.rs | 1 | ||||
-rw-r--r-- | core/src/point.rs | 10 |
5 files changed, 47 insertions, 0 deletions
diff --git a/core/src/keyboard.rs b/core/src/keyboard.rs new file mode 100644 index 00000000..d98b2989 --- /dev/null +++ b/core/src/keyboard.rs @@ -0,0 +1,6 @@ +//! Reuse basic keyboard types. +mod key_code; +mod modifiers_state; + +pub use key_code::KeyCode; +pub use modifiers_state::ModifiersState; diff --git a/native/src/input/keyboard/key_code.rs b/core/src/keyboard/key_code.rs index 26020a57..26020a57 100644 --- a/native/src/input/keyboard/key_code.rs +++ b/core/src/keyboard/key_code.rs diff --git a/core/src/keyboard/modifiers_state.rs b/core/src/keyboard/modifiers_state.rs new file mode 100644 index 00000000..4d24266f --- /dev/null +++ b/core/src/keyboard/modifiers_state.rs @@ -0,0 +1,30 @@ +/// The current state of the keyboard modifiers. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct ModifiersState { + /// Whether a shift key is pressed + pub shift: bool, + + /// Whether a control key is pressed + pub control: bool, + + /// Whether an alt key is pressed + pub alt: bool, + + /// 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 || self.shift; + let control = !modifiers.control || self.control; + let alt = !modifiers.alt || self.alt; + let logo = !modifiers.logo || self.logo; + + shift && control && alt && logo + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index ea5e8b43..c2887a0b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -14,6 +14,7 @@ #![deny(unused_results)] #![forbid(unsafe_code)] #![forbid(rust_2018_idioms)] +pub mod keyboard; mod align; mod background; diff --git a/core/src/point.rs b/core/src/point.rs index b55f5099..43ee2143 100644 --- a/core/src/point.rs +++ b/core/src/point.rs @@ -22,6 +22,16 @@ impl Point { pub const fn new(x: f32, y: f32) -> Self { Self { x, y } } + + /// Computes the distance to another [`Point`]. + /// + /// [`Point`]: struct.Point.html + pub fn distance(&self, to: Point) -> f32 { + let a = self.x - to.x; + let b = self.y - to.y; + + a.hypot(b) + } } impl From<[f32; 2]> for Point { |