1
0
Fork 0
baseview/src/keyboard.rs
2020-09-11 10:21:05 -05:00

26 lines
852 B
Rust

// TODO: Add a method to the Window that returns the
// current modifier state.
/// The current state of the keyboard modifiers.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct ModifiersState {
pub shift: bool,
pub control: bool,
pub alt: bool,
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_atleast(&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
}
}