From 5144337253661163e6341d893576c07243225809 Mon Sep 17 00:00:00 2001 From: StarStarJ <77283933+StarStarJ@users.noreply.github.com> Date: Sat, 1 Jul 2023 17:07:35 +0200 Subject: [PATCH] Implement `PartialOrd`/`Ord` for `KeyCode`/`NativeKeyCode` --- CHANGELOG.md | 3 ++- src/keyboard.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f952a91e0..92c33d8bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- Implement `PartialOrd` and `Ord` for `Key`, `KeyCode`, `NativeKey`, and `NativeKeyCode`. + # 0.29.1-beta - **Breaking:** Bump `ndk` version to `0.8.0-beta.0`, ndk-sys to `v0.5.0-beta.0`, `android-activity` to `0.5.0-beta.1`. @@ -46,7 +48,6 @@ 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 `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. diff --git a/src/keyboard.rs b/src/keyboard.rs index 7f6888a95..40caa476b 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -82,7 +82,7 @@ pub use smol_str::SmolStr; /// /// - Correctly match key press and release events. /// - On non-web platforms, support assigning keybinds to virtually any key through a UI. -#[derive(Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum NativeKeyCode { Unidentified, @@ -196,7 +196,7 @@ impl std::fmt::Debug for NativeKey { /// /// [`KeyboardEvent.code`]: https://w3c.github.io/uievents-code/#code-value-tables #[non_exhaustive] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum KeyCode { /// This variant is used when the key cannot be translated to any other variant.