bevy/crates/bevy_window/src/cursor.rs

94 lines
3.6 KiB
Rust
Raw Normal View History

use bevy_reflect::{prelude::ReflectDefault, FromReflect, Reflect, ReflectFromReflect};
Windows as Entities (#5589) # Objective Fix https://github.com/bevyengine/bevy/issues/4530 - Make it easier to open/close/modify windows by setting them up as `Entity`s with a `Window` component. - Make multiple windows very simple to set up. (just add a `Window` component to an entity and it should open) ## Solution - Move all properties of window descriptor to ~components~ a component. - Replace `WindowId` with `Entity`. - ~Use change detection for components to update backend rather than events/commands. (The `CursorMoved`/`WindowResized`/... events are kept for user convenience.~ Check each field individually to see what we need to update, events are still kept for user convenience. --- ## Changelog - `WindowDescriptor` renamed to `Window`. - Width/height consolidated into a `WindowResolution` component. - Requesting maximization/minimization is done on the [`Window::state`] field. - `WindowId` is now `Entity`. ## Migration Guide - Replace `WindowDescriptor` with `Window`. - Change `width` and `height` fields in a `WindowResolution`, either by doing ```rust WindowResolution::new(width, height) // Explicitly // or using From<_> for tuples for convenience (1920., 1080.).into() ``` - Replace any `WindowCommand` code to just modify the `Window`'s fields directly and creating/closing windows is now by spawning/despawning an entity with a `Window` component like so: ```rust let window = commands.spawn(Window { ... }).id(); // open window commands.entity(window).despawn(); // close window ``` ## Unresolved - ~How do we tell when a window is minimized by a user?~ ~Currently using the `Resize(0, 0)` as an indicator of minimization.~ No longer attempting to tell given how finnicky this was across platforms, now the user can only request that a window be maximized/minimized. ## Future work - Move `exit_on_close` functionality out from windowing and into app(?) - https://github.com/bevyengine/bevy/issues/5621 - https://github.com/bevyengine/bevy/issues/7099 - https://github.com/bevyengine/bevy/issues/7098 Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2023-01-19 00:38:28 +00:00
#[cfg(feature = "serialize")]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
Update and improve Window Documentation (#8858) # Objective Improve the documentation relating to windows, and update the parts that have not been updated since version 0.8. Version 0.9 introduced `Window` as a component, before that `WindowDescriptor` (which would become `Window` later) was used to store information about how a window will be created. Since version 0.9, from my understanding, this information will also be synchronised with the current state of the window, and can be used to modify this state. However, some of the documentation has not been updated to reflect that, here is an example: https://docs.rs/bevy/0.8.0/bevy/window/enum.WindowMode.html / https://docs.rs/bevy/latest/bevy/window/enum.WindowMode.html (notice that the verb "Creates" is still there). This PR aims at improving the documentation relating to windows. ## Solution - Change "will" for "should" when relevant, "should" implies that the information should in both direction (from the window state to the `Window` component and vice-versa) and can be used to get and set, will implies it is only used to set a state. - Remove references to "creation" or be more clear about it. - Reference back the `Window` component for most of its sub-structs. - Clarify what needs to be clarified - A lot of other minor changes, including fixing the link to W3schools in `bevy_winit` ## Warning Please note that my knowledge about how winit and bevy_winit work is limited and some of the informations I added in the doc may be inaccurate. A person who knows better how it works should review some of my claims, in particular: - How fullscreen works: https://github.com/bevyengine/bevy/pull/8858#discussion_r1232413155 - How WindowResolution / sizes work: https://github.com/bevyengine/bevy/pull/8858#discussion_r1233010719 - What happens when `WindowPosition` is set to `Centered` or `Automatic`. From my understanding of the code, it should always be set back to `At`, but is it really the case? For example [when creating the window](https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/winit_windows.rs#L74), or when [a `WindowEvent::Moved` is triggered](https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/lib.rs#L602) or when [Centered/Automatic by the code after the window is created](https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/system.rs#L243), am I missing some cases and do the codes I linked do that in all of them? - Are there any field in the `Window` component that can't be used to modify the state of the window, only at creation? --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Jerome Humbert <djeedai@gmail.com>
2023-06-22 03:00:40 +00:00
/// The icon to display for a [`Window`](crate::window::Window)'s [`Cursor`](crate::window::Cursor).
///
Update and improve Window Documentation (#8858) # Objective Improve the documentation relating to windows, and update the parts that have not been updated since version 0.8. Version 0.9 introduced `Window` as a component, before that `WindowDescriptor` (which would become `Window` later) was used to store information about how a window will be created. Since version 0.9, from my understanding, this information will also be synchronised with the current state of the window, and can be used to modify this state. However, some of the documentation has not been updated to reflect that, here is an example: https://docs.rs/bevy/0.8.0/bevy/window/enum.WindowMode.html / https://docs.rs/bevy/latest/bevy/window/enum.WindowMode.html (notice that the verb "Creates" is still there). This PR aims at improving the documentation relating to windows. ## Solution - Change "will" for "should" when relevant, "should" implies that the information should in both direction (from the window state to the `Window` component and vice-versa) and can be used to get and set, will implies it is only used to set a state. - Remove references to "creation" or be more clear about it. - Reference back the `Window` component for most of its sub-structs. - Clarify what needs to be clarified - A lot of other minor changes, including fixing the link to W3schools in `bevy_winit` ## Warning Please note that my knowledge about how winit and bevy_winit work is limited and some of the informations I added in the doc may be inaccurate. A person who knows better how it works should review some of my claims, in particular: - How fullscreen works: https://github.com/bevyengine/bevy/pull/8858#discussion_r1232413155 - How WindowResolution / sizes work: https://github.com/bevyengine/bevy/pull/8858#discussion_r1233010719 - What happens when `WindowPosition` is set to `Centered` or `Automatic`. From my understanding of the code, it should always be set back to `At`, but is it really the case? For example [when creating the window](https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/winit_windows.rs#L74), or when [a `WindowEvent::Moved` is triggered](https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/lib.rs#L602) or when [Centered/Automatic by the code after the window is created](https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/system.rs#L243), am I missing some cases and do the codes I linked do that in all of them? - Are there any field in the `Window` component that can't be used to modify the state of the window, only at creation? --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Jerome Humbert <djeedai@gmail.com>
2023-06-22 03:00:40 +00:00
/// 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, mostly copied cursor types available in the browser.
Windows as Entities (#5589) # Objective Fix https://github.com/bevyengine/bevy/issues/4530 - Make it easier to open/close/modify windows by setting them up as `Entity`s with a `Window` component. - Make multiple windows very simple to set up. (just add a `Window` component to an entity and it should open) ## Solution - Move all properties of window descriptor to ~components~ a component. - Replace `WindowId` with `Entity`. - ~Use change detection for components to update backend rather than events/commands. (The `CursorMoved`/`WindowResized`/... events are kept for user convenience.~ Check each field individually to see what we need to update, events are still kept for user convenience. --- ## Changelog - `WindowDescriptor` renamed to `Window`. - Width/height consolidated into a `WindowResolution` component. - Requesting maximization/minimization is done on the [`Window::state`] field. - `WindowId` is now `Entity`. ## Migration Guide - Replace `WindowDescriptor` with `Window`. - Change `width` and `height` fields in a `WindowResolution`, either by doing ```rust WindowResolution::new(width, height) // Explicitly // or using From<_> for tuples for convenience (1920., 1080.).into() ``` - Replace any `WindowCommand` code to just modify the `Window`'s fields directly and creating/closing windows is now by spawning/despawning an entity with a `Window` component like so: ```rust let window = commands.spawn(Window { ... }).id(); // open window commands.entity(window).despawn(); // close window ``` ## Unresolved - ~How do we tell when a window is minimized by a user?~ ~Currently using the `Resize(0, 0)` as an indicator of minimization.~ No longer attempting to tell given how finnicky this was across platforms, now the user can only request that a window be maximized/minimized. ## Future work - Move `exit_on_close` functionality out from windowing and into app(?) - https://github.com/bevyengine/bevy/issues/5621 - https://github.com/bevyengine/bevy/issues/7099 - https://github.com/bevyengine/bevy/issues/7098 Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2023-01-19 00:38:28 +00:00
#[derive(Default, Debug, Hash, PartialEq, Eq, Clone, Copy, Reflect, FromReflect)]
#[cfg_attr(
feature = "serialize",
derive(serde::Serialize, serde::Deserialize),
reflect(Serialize, Deserialize)
)]
#[reflect(Debug, PartialEq, Default, FromReflect)]
pub enum CursorIcon {
/// The platform-dependent default cursor.
Windows as Entities (#5589) # Objective Fix https://github.com/bevyengine/bevy/issues/4530 - Make it easier to open/close/modify windows by setting them up as `Entity`s with a `Window` component. - Make multiple windows very simple to set up. (just add a `Window` component to an entity and it should open) ## Solution - Move all properties of window descriptor to ~components~ a component. - Replace `WindowId` with `Entity`. - ~Use change detection for components to update backend rather than events/commands. (The `CursorMoved`/`WindowResized`/... events are kept for user convenience.~ Check each field individually to see what we need to update, events are still kept for user convenience. --- ## Changelog - `WindowDescriptor` renamed to `Window`. - Width/height consolidated into a `WindowResolution` component. - Requesting maximization/minimization is done on the [`Window::state`] field. - `WindowId` is now `Entity`. ## Migration Guide - Replace `WindowDescriptor` with `Window`. - Change `width` and `height` fields in a `WindowResolution`, either by doing ```rust WindowResolution::new(width, height) // Explicitly // or using From<_> for tuples for convenience (1920., 1080.).into() ``` - Replace any `WindowCommand` code to just modify the `Window`'s fields directly and creating/closing windows is now by spawning/despawning an entity with a `Window` component like so: ```rust let window = commands.spawn(Window { ... }).id(); // open window commands.entity(window).despawn(); // close window ``` ## Unresolved - ~How do we tell when a window is minimized by a user?~ ~Currently using the `Resize(0, 0)` as an indicator of minimization.~ No longer attempting to tell given how finnicky this was across platforms, now the user can only request that a window be maximized/minimized. ## Future work - Move `exit_on_close` functionality out from windowing and into app(?) - https://github.com/bevyengine/bevy/issues/5621 - https://github.com/bevyengine/bevy/issues/7099 - https://github.com/bevyengine/bevy/issues/7098 Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2023-01-19 00:38:28 +00:00
#[default]
Default,
/// A simple crosshair.
Crosshair,
/// A hand (often used to indicate links in web browsers).
Hand,
/// An arrow. This is the default cursor on most systems.
Arrow,
/// Indicates something is to be moved.
Move,
/// Indicates text that may be selected or edited.
Text,
/// Program busy indicator.
Wait,
/// Help indicator (often rendered as a "?")
Help,
/// Progress indicator. Shows that processing is being done.
///
/// But in contrast with "Wait" the user may still interact with the program.
/// Often rendered as a spinning beach ball, or an arrow with a watch or hourglass.
Progress,
/// Cursor showing that something cannot be done.
NotAllowed,
/// Indicates that a context menu is available.
ContextMenu,
/// Indicates that a cell (or set of cells) may be selected.
Cell,
/// Indicates vertical text that may be selected or edited.
VerticalText,
/// Indicates that an alias of something is to be created.
Alias,
/// Indicates something is to be copied.
Copy,
/// Indicates that the dragged item cannot be dropped here.
NoDrop,
/// Indicates that something can be grabbed.
Grab,
/// Indicates that something is grabbed.
Grabbing,
/// Indicates that the user can scroll by dragging the mouse.
AllScroll,
/// Indicates that the user can zoom in.
ZoomIn,
/// Indicates that the user can zoom out.
ZoomOut,
/// Indicates that an edge of a box is to be moved right (east).
EResize,
/// Indicates that an edge of a box is to be moved up (north).
NResize,
/// Indicates that an edge of a box is to be moved up and right (north/east).
NeResize,
/// indicates that an edge of a box is to be moved up and left (north/west).
NwResize,
/// Indicates that an edge of a box is to be moved down (south).
SResize,
/// The cursor indicates that an edge of a box is to be moved down and right (south/east).
SeResize,
/// The cursor indicates that an edge of a box is to be moved down and left (south/west).
SwResize,
/// Indicates that an edge of a box is to be moved left (west).
WResize,
/// Indicates a bidirectional resize cursor.
EwResize,
/// Indicates a bidirectional resize cursor.
NsResize,
/// Indicates a bidirectional resize cursor.
NeswResize,
/// Indicates a bidirectional resize cursor.
NwseResize,
/// Indicates that a column can be resized horizontally.
ColResize,
/// Indicates that the row can be resized vertically.
RowResize,
}