Rename `keyboard::ModifiersState` to `Modifiers`
This commit is contained in:
parent
08e0b9ffbd
commit
d612bf5678
|
@ -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;
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -570,7 +570,7 @@ where
|
|||
self.state.is_pasting = None;
|
||||
|
||||
self.state.keyboard_modifiers =
|
||||
keyboard::ModifiersState::default();
|
||||
keyboard::Modifiers::default();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -734,7 +734,7 @@ pub struct State {
|
|||
is_pasting: Option<Value>,
|
||||
last_click: Option<mouse::Click>,
|
||||
cursor: Cursor,
|
||||
keyboard_modifiers: keyboard::ModifiersState,
|
||||
keyboard_modifiers: keyboard::Modifiers,
|
||||
// TODO: Add stateful horizontal scrolling offset
|
||||
}
|
||||
|
||||
|
@ -756,7 +756,7 @@ impl State {
|
|||
is_pasting: None,
|
||||
last_click: None,
|
||||
cursor: Cursor::default(),
|
||||
keyboard_modifiers: keyboard::ModifiersState::default(),
|
||||
keyboard_modifiers: keyboard::Modifiers::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -873,9 +873,7 @@ fn find_cursor_position<Renderer: self::Renderer>(
|
|||
mod platform {
|
||||
use crate::keyboard;
|
||||
|
||||
pub fn is_jump_modifier_pressed(
|
||||
modifiers: keyboard::ModifiersState,
|
||||
) -> bool {
|
||||
pub fn is_jump_modifier_pressed(modifiers: keyboard::Modifiers) -> bool {
|
||||
if cfg!(target_os = "macos") {
|
||||
modifiers.alt
|
||||
} else {
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
//! Listen and react to keyboard events.
|
||||
pub use crate::runtime::keyboard::{Event, KeyCode, ModifiersState};
|
||||
pub use crate::runtime::keyboard::{Event, KeyCode, Modifiers};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//! [`winit`]: https://github.com/rust-windowing/winit
|
||||
//! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
|
||||
use crate::{
|
||||
keyboard::{self, KeyCode, ModifiersState},
|
||||
keyboard::{self, KeyCode, Modifiers},
|
||||
mouse, window, Event, Mode, Point,
|
||||
};
|
||||
|
||||
|
@ -89,7 +89,7 @@ pub fn window_event(
|
|||
..
|
||||
} => Some(Event::Keyboard({
|
||||
let key_code = key_code(*virtual_keycode);
|
||||
let modifiers = modifiers_state(modifiers);
|
||||
let modifiers = self::modifiers(modifiers);
|
||||
|
||||
match state {
|
||||
winit::event::ElementState::Pressed => {
|
||||
|
@ -107,7 +107,7 @@ pub fn window_event(
|
|||
}
|
||||
})),
|
||||
WindowEvent::ModifiersChanged(new_modifiers) => Some(Event::Keyboard(
|
||||
keyboard::Event::ModifiersChanged(modifiers_state(*new_modifiers)),
|
||||
keyboard::Event::ModifiersChanged(self::modifiers(*new_modifiers)),
|
||||
)),
|
||||
WindowEvent::HoveredFile(path) => {
|
||||
Some(Event::Window(window::Event::FileHovered(path.clone())))
|
||||
|
@ -180,10 +180,8 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
|
|||
///
|
||||
/// [`winit`]: https://github.com/rust-windowing/winit
|
||||
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
|
||||
pub fn modifiers_state(
|
||||
modifiers: winit::event::ModifiersState,
|
||||
) -> ModifiersState {
|
||||
ModifiersState {
|
||||
pub fn modifiers(modifiers: winit::event::ModifiersState) -> Modifiers {
|
||||
Modifiers {
|
||||
shift: modifiers.shift(),
|
||||
control: modifiers.ctrl(),
|
||||
alt: modifiers.alt(),
|
||||
|
|
Loading…
Reference in New Issue