summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/keyboard.rs4
-rw-r--r--core/src/keyboard/event.rs8
-rw-r--r--core/src/keyboard/modifiers.rs (renamed from core/src/keyboard/modifiers_state.rs)17
-rw-r--r--native/src/widget/text_input.rs10
-rw-r--r--src/keyboard.rs2
-rw-r--r--winit/src/conversion.rs12
6 files changed, 22 insertions, 31 deletions
diff --git a/core/src/keyboard.rs b/core/src/keyboard.rs
index b26bdb3d..61e017ad 100644
--- a/core/src/keyboard.rs
+++ b/core/src/keyboard.rs
@@ -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;
diff --git a/core/src/keyboard/event.rs b/core/src/keyboard/event.rs
index d142c3bc..0564c171 100644
--- a/core/src/keyboard/event.rs
+++ b/core/src/keyboard/event.rs
@@ -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),
}
diff --git a/core/src/keyboard/modifiers_state.rs b/core/src/keyboard/modifiers.rs
index 254013c3..d2a0500e 100644
--- a/core/src/keyboard/modifiers_state.rs
+++ b/core/src/keyboard/modifiers.rs
@@ -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;
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index a302e483..e67ea365 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -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 {
diff --git a/src/keyboard.rs b/src/keyboard.rs
index 0b3e894d..2134a66b 100644
--- a/src/keyboard.rs
+++ b/src/keyboard.rs
@@ -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};
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index de38f246..a9fa2ffc 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -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(),