Export smol_str and impl Ord for Key

Fixes #2996.
This commit is contained in:
Diggory Hardy 2023-08-03 17:12:48 +01:00 committed by GitHub
parent b5aa96bea4
commit 189a0080a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -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.

View file

@ -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

View file

@ -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<Str = SmolStr> {
/// A key string that corresponds to the character typed by the user, taking into account the