
# Objective - Update winit dependency to 0.29 ## Changelog ### KeyCode changes - Removed `ScanCode`, as it was [replaced by KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292). - `ReceivedCharacter.char` is now a `SmolStr`, [relevant doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text). - Changed most `KeyCode` values, and added more. KeyCode has changed meaning. With this PR, it refers to physical position on keyboard rather than the printed letter on keyboard keys. In practice this means: - On QWERTY keyboard layouts, nothing changes - On any other keyboard layout, `KeyCode` no longer reflects the label on key. - This is "good". In bevy 0.12, when you used WASD for movement, users with non-QWERTY keyboards couldn't play your game! This was especially bad for non-latin keyboards. Now, WASD represents the physical keys. A French player will press the ZQSD keys, which are near each other, Kyrgyz players will use "Цфыв". - This is "bad" as well. You can't know in advance what the label of the key for input is. Your UI says "press WASD to move", even if in reality, they should be pressing "ZQSD" or "Цфыв". You also no longer can use `KeyCode` for text inputs. In any case, it was a pretty bad API for text input. You should use `ReceivedCharacter` now instead. ### Other changes - Use `web-time` rather than `instant` crate. (https://github.com/rust-windowing/winit/pull/2836) - winit did split `run_return` in `run_onDemand` and `pump_events`, I did the same change in bevy_winit and used `pump_events`. - Removed `return_from_run` from `WinitSettings` as `winit::run` now returns on supported platforms. - I left the example "return_after_run" as I think it's still useful. - This winit change is done partly to allow to create a new window after quitting all windows: https://github.com/emilk/egui/issues/1918 ; this PR doesn't address. - added `width` and `height` properties in the `canvas` from wasm example (https://github.com/bevyengine/bevy/pull/10702#discussion_r1420567168) ## Known regressions (important follow ups?) - Provide an API for reacting when a specific key from current layout was released. - possible solutions: use winit::Key from winit::KeyEvent ; mapping between KeyCode and Key ; or . - We don't receive characters through alt+numpad (e.g. alt + 151 = "ù") anymore ; reproduced on winit example "ime". maybe related to https://github.com/rust-windowing/winit/issues/2945 - (windows) Window content doesn't refresh at all when resizing. By reading https://github.com/rust-windowing/winit/issues/2900 ; I suspect we should just fire a `window.request_redraw();` from `AboutToWait`, and handle actual redrawing within `RedrawRequested`. I'm not sure how to move all that code so I'd appreciate it to be a follow up. - (windows) unreleased winit fix for using set_control_flow in AboutToWait https://github.com/rust-windowing/winit/issues/3215 ; ⚠️ I'm not sure what the implications are, but that feels bad 🤔 ## Follow up I'd like to avoid bloating this PR, here are a few follow up tasks worthy of a separate PR, or new issue to track them once this PR is closed, as they would either complicate reviews, or at risk of being controversial: - remove CanvasParentResizePlugin (https://github.com/bevyengine/bevy/pull/10702#discussion_r1417068856) - avoid mentionning explicitly winit in docs from bevy_window ? - NamedKey integration on bevy_input: https://github.com/rust-windowing/winit/pull/3143 introduced a new NamedKey variant. I implemented it only on the converters but we'd benefit making the same changes to bevy_input. - Add more info in KeyboardInput https://github.com/bevyengine/bevy/pull/10702#pullrequestreview-1748336313 - https://github.com/bevyengine/bevy/pull/9905 added a workaround on a bug allegedly fixed by winit 0.29. We should check if it's still necessary. - update to raw_window_handle 0.6 - blocked by wgpu - Rename `KeyCode` to `PhysicalKeyCode` https://github.com/bevyengine/bevy/pull/10702#discussion_r1404595015 - remove `instant` dependency, [replaced by](https://github.com/rust-windowing/winit/pull/2836) `web_time`), we'd need to update to : - fastrand >= 2.0 - [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7 - [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0 - Verify license, see [discussion](https://github.com/bevyengine/bevy/pull/8745#discussion_r1402439800) - we might be missing a short notice or description of changes made - Consider using https://github.com/rust-windowing/cursor-icon directly rather than vendoring it in bevy. - investigate [this unwrap](https://github.com/bevyengine/bevy/pull/8745#discussion_r1387044986) (`winit_window.canvas().unwrap();`) - Use more good things about winit's update - https://github.com/bevyengine/bevy/pull/10689#issuecomment-1823560428 ## Migration Guide This PR should have one.
220 lines
8.2 KiB
Rust
220 lines
8.2 KiB
Rust
// This file contains a portion of the CSS Basic User Interface Module Level 3
|
|
// specification. In particular, the names for the cursor from the #cursor
|
|
// section and documentation for some of the variants were taken.
|
|
//
|
|
// The original document is https://www.w3.org/TR/css-ui-3/#cursor.
|
|
// Copyright © 2018 W3C® (MIT, ERCIM, Keio, Beihang)
|
|
//
|
|
// These documents were used under the terms of the following license. This W3C
|
|
// license as well as the W3C short notice apply to the `CursorIcon` enum's
|
|
// variants and documentation attached to them.
|
|
|
|
// --------- BEGGINING OF W3C LICENSE
|
|
// --------------------------------------------------------------
|
|
//
|
|
// License
|
|
//
|
|
// By obtaining and/or copying this work, you (the licensee) agree that you have
|
|
// read, understood, and will comply with the following terms and conditions.
|
|
//
|
|
// Permission to copy, modify, and distribute this work, with or without
|
|
// modification, for any purpose and without fee or royalty is hereby granted,
|
|
// provided that you include the following on ALL copies of the work or portions
|
|
// thereof, including modifications:
|
|
//
|
|
// - The full text of this NOTICE in a location viewable to users of the
|
|
// redistributed or derivative work.
|
|
// - Any pre-existing intellectual property disclaimers, notices, or terms and
|
|
// conditions. If none exist, the W3C Software and Document Short Notice
|
|
// should be included.
|
|
// - Notice of any changes or modifications, through a copyright statement on
|
|
// the new code or document such as "This software or document includes
|
|
// material copied from or derived from [title and URI of the W3C document].
|
|
// Copyright © [YEAR] W3C® (MIT, ERCIM, Keio, Beihang)."
|
|
//
|
|
// Disclaimers
|
|
//
|
|
// THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS
|
|
// OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES
|
|
// OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
|
|
// THE SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD PARTY PATENTS,
|
|
// COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
|
//
|
|
// COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
|
|
// CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT.
|
|
//
|
|
// The name and trademarks of copyright holders may NOT be used in advertising
|
|
// or publicity pertaining to the work without specific, written prior
|
|
// permission. Title to copyright in this work will at all times remain with
|
|
// copyright holders.
|
|
//
|
|
// --------- END OF W3C LICENSE
|
|
// --------------------------------------------------------------------
|
|
|
|
// --------- BEGGINING OF W3C SHORT NOTICE
|
|
// ---------------------------------------------------------
|
|
//
|
|
// winit: https://github.com/rust-windowing/cursor-icon
|
|
//
|
|
// Copyright © 2023 World Wide Web Consortium, (Massachusetts Institute of
|
|
// Technology, European Research Consortium for Informatics and Mathematics,
|
|
// Keio University, Beihang). All Rights Reserved. This work is distributed
|
|
// under the W3C® Software License [1] in the hope that it will be useful, but
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// [1] http://www.w3.org/Consortium/Legal/copyright-software
|
|
//
|
|
// --------- END OF W3C SHORT NOTICE
|
|
// --------------------------------------------------------------
|
|
|
|
use bevy_reflect::{prelude::ReflectDefault, Reflect};
|
|
|
|
#[cfg(feature = "serialize")]
|
|
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
|
|
|
/// The icon to display for a [`Window`](crate::window::Window)'s [`Cursor`](crate::window::Cursor).
|
|
///
|
|
/// Examples of all of these cursors can be found [here](https://www.w3schools.com/cssref/playit.php?filename=playcss_cursor&preval=crosshair).
|
|
/// This `enum` is simply a copy of a similar `enum` found in [`winit`](https://docs.rs/winit/latest/winit/window/enum.CursorIcon.html).
|
|
/// `winit`, in turn, is based upon the [CSS3 UI spec](https://www.w3.org/TR/css-ui-3/#cursor).
|
|
///
|
|
/// See the [`window_settings`] example for usage.
|
|
///
|
|
/// [`window_settings`]: https://github.com/bevyengine/bevy/blob/latest/examples/window/window_settings.rs
|
|
#[derive(Default, Debug, Hash, PartialEq, Eq, Clone, Copy, Reflect)]
|
|
#[cfg_attr(
|
|
feature = "serialize",
|
|
derive(serde::Serialize, serde::Deserialize),
|
|
reflect(Serialize, Deserialize)
|
|
)]
|
|
#[reflect(Debug, PartialEq, Default)]
|
|
pub enum CursorIcon {
|
|
/// The platform-dependent default cursor. Often rendered as arrow.
|
|
#[default]
|
|
Default,
|
|
|
|
/// A context menu is available for the object under the cursor. Often
|
|
/// rendered as an arrow with a small menu-like graphic next to it.
|
|
ContextMenu,
|
|
|
|
/// Help is available for the object under the cursor. Often rendered as a
|
|
/// question mark or a balloon.
|
|
Help,
|
|
|
|
/// The cursor is a pointer that indicates a link. Often rendered as the
|
|
/// backside of a hand with the index finger extended.
|
|
Pointer,
|
|
|
|
/// A progress indicator. The program is performing some processing, but is
|
|
/// different from [`CursorIcon::Wait`] in that the user may still interact
|
|
/// with the program.
|
|
Progress,
|
|
|
|
/// Indicates that the program is busy and the user should wait. Often
|
|
/// rendered as a watch or hourglass.
|
|
Wait,
|
|
|
|
/// Indicates that a cell or set of cells may be selected. Often rendered as
|
|
/// a thick plus-sign with a dot in the middle.
|
|
Cell,
|
|
|
|
/// A simple crosshair (e.g., short line segments resembling a "+" sign).
|
|
/// Often used to indicate a two dimensional bitmap selection mode.
|
|
Crosshair,
|
|
|
|
/// Indicates text that may be selected. Often rendered as an I-beam.
|
|
Text,
|
|
|
|
/// Indicates vertical-text that may be selected. Often rendered as a
|
|
/// horizontal I-beam.
|
|
VerticalText,
|
|
|
|
/// Indicates an alias of/shortcut to something is to be created. Often
|
|
/// rendered as an arrow with a small curved arrow next to it.
|
|
Alias,
|
|
|
|
/// Indicates something is to be copied. Often rendered as an arrow with a
|
|
/// small plus sign next to it.
|
|
Copy,
|
|
|
|
/// Indicates something is to be moved.
|
|
Move,
|
|
|
|
/// Indicates that the dragged item cannot be dropped at the current cursor
|
|
/// location. Often rendered as a hand or pointer with a small circle with a
|
|
/// line through it.
|
|
NoDrop,
|
|
|
|
/// Indicates that the requested action will not be carried out. Often
|
|
/// rendered as a circle with a line through it.
|
|
NotAllowed,
|
|
|
|
/// Indicates that something can be grabbed (dragged to be moved). Often
|
|
/// rendered as the backside of an open hand.
|
|
Grab,
|
|
|
|
/// Indicates that something is being grabbed (dragged to be moved). Often
|
|
/// rendered as the backside of a hand with fingers closed mostly out of
|
|
/// view.
|
|
Grabbing,
|
|
|
|
/// The east border to be moved.
|
|
EResize,
|
|
|
|
/// The north border to be moved.
|
|
NResize,
|
|
|
|
/// The north-east corner to be moved.
|
|
NeResize,
|
|
|
|
/// The north-west corner to be moved.
|
|
NwResize,
|
|
|
|
/// The south border to be moved.
|
|
SResize,
|
|
|
|
/// The south-east corner to be moved.
|
|
SeResize,
|
|
|
|
/// The south-west corner to be moved.
|
|
SwResize,
|
|
|
|
/// The west border to be moved.
|
|
WResize,
|
|
|
|
/// The east and west borders to be moved.
|
|
EwResize,
|
|
|
|
/// The south and north borders to be moved.
|
|
NsResize,
|
|
|
|
/// The north-east and south-west corners to be moved.
|
|
NeswResize,
|
|
|
|
/// The north-west and south-east corners to be moved.
|
|
NwseResize,
|
|
|
|
/// Indicates that the item/column can be resized horizontally. Often
|
|
/// rendered as arrows pointing left and right with a vertical bar
|
|
/// separating them.
|
|
ColResize,
|
|
|
|
/// Indicates that the item/row can be resized vertically. Often rendered as
|
|
/// arrows pointing up and down with a horizontal bar separating them.
|
|
RowResize,
|
|
|
|
/// Indicates that the something can be scrolled in any direction. Often
|
|
/// rendered as arrows pointing up, down, left, and right with a dot in the
|
|
/// middle.
|
|
AllScroll,
|
|
|
|
/// Indicates that something can be zoomed in. Often rendered as a
|
|
/// magnifying glass with a "+" in the center of the glass.
|
|
ZoomIn,
|
|
|
|
/// Indicates that something can be zoomed in. Often rendered as a
|
|
/// magnifying glass with a "-" in the center of the glass.
|
|
ZoomOut,
|
|
}
|