bevy/crates/bevy_window/src/system_cursor.rs
Gino Valente 9b32e09551
bevy_reflect: Add clone registrations project-wide (#18307)
# Objective

Now that #13432 has been merged, it's important we update our reflected
types to properly opt into this feature. If we do not, then this could
cause issues for users downstream who want to make use of
reflection-based cloning.

## Solution

This PR is broken into 4 commits:

1. Add `#[reflect(Clone)]` on all types marked `#[reflect(opaque)]` that
are also `Clone`. This is mandatory as these types would otherwise cause
the cloning operation to fail for any type that contains it at any
depth.
2. Update the reflection example to suggest adding `#[reflect(Clone)]`
on opaque types.
3. Add `#[reflect(clone)]` attributes on all fields marked
`#[reflect(ignore)]` that are also `Clone`. This prevents the ignored
field from causing the cloning operation to fail.
   
Note that some of the types that contain these fields are also `Clone`,
and thus can be marked `#[reflect(Clone)]`. This makes the
`#[reflect(clone)]` attribute redundant. However, I think it's safer to
keep it marked in the case that the `Clone` impl/derive is ever removed.
I'm open to removing them, though, if people disagree.
4. Finally, I added `#[reflect(Clone)]` on all types that are also
`Clone`. While not strictly necessary, it enables us to reduce the
generated output since we can just call `Clone::clone` directly instead
of calling `PartialReflect::reflect_clone` on each variant/field. It
also means we benefit from any optimizations or customizations made in
the `Clone` impl, including directly dereferencing `Copy` values and
increasing reference counters.

Along with that change I also took the liberty of adding any missing
registrations that I saw could be applied to the type as well, such as
`Default`, `PartialEq`, and `Hash`. There were hundreds of these to
edit, though, so it's possible I missed quite a few.

That last commit is **_massive_**. There were nearly 700 types to
update. So it's recommended to review the first three before moving onto
that last one.

Additionally, I can break the last commit off into its own PR or into
smaller PRs, but I figured this would be the easiest way of doing it
(and in a timely manner since I unfortunately don't have as much time as
I used to for code contributions).

## Testing

You can test locally with a `cargo check`:

```
cargo check --workspace --all-features
```
2025-03-17 18:32:35 +00:00

225 lines
8.3 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.
// --------- BEGINNING 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
// --------------------------------------------------------------------
// --------- BEGINNING 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
// --------------------------------------------------------------
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::{prelude::ReflectDefault, Reflect};
#[cfg(feature = "serialize")]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
/// The icon to display for a window.
///
/// 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)]
#[cfg_attr(
feature = "bevy_reflect",
derive(Reflect),
reflect(Debug, PartialEq, Hash, Default, Clone)
)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
all(feature = "serialize", feature = "bevy_reflect"),
reflect(Serialize, Deserialize)
)]
pub enum SystemCursorIcon {
/// 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 [`SystemCursorIcon::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,
}