From 189a0080a6df9169b549c405e73328d74e83fcbb Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 3 Aug 2023 17:12:48 +0100 Subject: [PATCH] Export smol_str and impl Ord for Key Fixes #2996. --- CHANGELOG.md | 3 ++- src/event.rs | 7 +++++++ src/keyboard.rs | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 576d63a1..1846321a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,8 @@ And please only add new entries to the top of this list, right below the `# Unre - On macOS, add tabbing APIs on `WindowExtMacOS` and `EventLoopWindowTargetExtMacOS`. - **Breaking:** Rename `Window::set_inner_size` to `Window::request_inner_size` and indicate if the size was applied immediately. - On X11, fix false positive flagging of key repeats when pressing different keys with no release between presses. -- Implement `PartialOrd` and `Ord` for `KeyCode` and `NativeKeyCode`. +- Implement `PartialOrd` and `Ord` for `Key`, `KeyCode`, `NativeKey`, and `NativeKeyCode`. +- Add `ElementState::is_pressed`. - On Web, implement `WindowEvent::Occluded`. - On Web, fix touch location to be as accurate as mouse position. - On Web, account for CSS `padding`, `border`, and `margin` when getting or setting the canvas position. diff --git a/src/event.rs b/src/event.rs index e0afca44..e24b0a9c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1019,6 +1019,13 @@ pub enum ElementState { Released, } +impl ElementState { + /// True if `self == Pressed`. + pub fn is_pressed(self) -> bool { + self == ElementState::Pressed + } +} + /// Describes a button of a mouse controller. /// /// ## Platform-specific diff --git a/src/keyboard.rs b/src/keyboard.rs index 7e9b81fc..40caa476 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -69,7 +69,7 @@ // // --------- END OF W3C SHORT NOTICE --------------------------------------------------------------- -use smol_str::SmolStr; +pub use smol_str::SmolStr; /// Contains the platform-native physical key identifier /// @@ -135,7 +135,7 @@ impl std::fmt::Debug for NativeKeyCode { /// This enum is primarily used to store raw keysym when Winit doesn't map a given native logical /// key identifier to a meaningful [`Key`] variant. This lets you use [`Key`], and let the user /// define keybinds which work in the presence of identifiers we haven't mapped for you yet. -#[derive(Clone, PartialEq, Eq, Hash)] +#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum NativeKey { Unidentified, @@ -662,7 +662,7 @@ pub enum KeyCode { /// /// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/ #[non_exhaustive] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Key { /// A key string that corresponds to the character typed by the user, taking into account the