Rename keyboard::ModifiersState to Modifiers

This commit is contained in:
Héctor Ramón Jiménez 2020-11-25 05:31:45 +01:00
parent 08e0b9ffbd
commit d612bf5678
6 changed files with 22 additions and 31 deletions

View file

@ -1,8 +1,8 @@
//! Reuse basic keyboard types.
mod event;
mod key_code;
mod modifiers_state;
mod modifiers;
pub use event::Event;
pub use key_code::KeyCode;
pub use modifiers_state::ModifiersState;
pub use modifiers::Modifiers;

View file

@ -1,4 +1,4 @@
use super::{KeyCode, ModifiersState};
use super::{KeyCode, Modifiers};
/// A keyboard event.
///
@ -14,7 +14,7 @@ pub enum Event {
key_code: KeyCode,
/// The state of the modifier keys
modifiers: ModifiersState,
modifiers: Modifiers,
},
/// A keyboard key was released.
@ -23,12 +23,12 @@ pub enum Event {
key_code: KeyCode,
/// The state of the modifier keys
modifiers: ModifiersState,
modifiers: Modifiers,
},
/// A unicode character was received.
CharacterReceived(char),
/// The keyboard modifiers have changed.
ModifiersChanged(ModifiersState),
ModifiersChanged(Modifiers),
}

View file

@ -1,6 +1,6 @@
/// The current state of the keyboard modifiers.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct ModifiersState {
pub struct Modifiers {
/// Whether a shift key is pressed
pub shift: bool,
@ -14,17 +14,14 @@ pub struct ModifiersState {
pub logo: bool,
}
impl ModifiersState {
/// Returns true if the current [`ModifiersState`] has a "command key"
/// pressed.
impl Modifiers {
/// Returns true if a "command key" is pressed in the [`Modifiers`].
///
/// The "command key" is the main modifier key used to issue commands in the
/// current platform. Specifically:
///
/// - It is the `logo` or command key (⌘) on macOS
/// - It is the `control` key on other platforms
///
/// [`ModifiersState`]: struct.ModifiersState.html
pub fn is_command_pressed(self) -> bool {
#[cfg(target_os = "macos")]
let is_pressed = self.logo;
@ -35,11 +32,9 @@ impl ModifiersState {
is_pressed
}
/// 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 {
/// Returns true if the current [`Modifiers`] have at least the same
/// keys pressed as the provided ones, and false otherwise.
pub fn matches(&self, modifiers: Self) -> bool {
let shift = !modifiers.shift || self.shift;
let control = !modifiers.control || self.control;
let alt = !modifiers.alt || self.alt;