From 41311e6ad7836b7354b602bd324ac6636ed0545d Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Wed, 9 Oct 2024 17:11:53 -0400 Subject: [PATCH 01/10] feature: Add window move resize example. --- Cargo.toml | 12 ++++ crates/bevy_window/src/window.rs | 3 +- examples/window/window_drag_move.rs | 100 ++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 examples/window/window_drag_move.rs diff --git a/Cargo.toml b/Cargo.toml index 1f548f505c294..567632489b332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2934,6 +2934,7 @@ name = "window_fallthrough" path = "examples/ui/window_fallthrough.rs" doc-scrape-examples = true + [package.metadata.example.window_fallthrough] name = "Window Fallthrough" description = "Illustrates how to access `winit::window::Window`'s `hittest` functionality." @@ -3271,6 +3272,17 @@ description = "Demonstrates customizing default window settings" category = "Window" wasm = true +[[example]] +name = "window_drag_move" +path = "examples/window/window_drag_move.rs" +doc-scrape-examples = true + +[package.metadata.example.window_drag_move] +name = "Window Drag Move" +description = "Demonstrates moving window via API" +category = "Window" +wasm = false + [[example]] name = "ambiguity_detection" path = "tests/ecs/ambiguity_detection.rs" diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index 34781501e65a8..d591a60ca2f0d 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -914,7 +914,7 @@ pub enum CursorGrabMode { } /// Defines the orientation in which a window resize will be performed. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Reflect)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Reflect, Hash, Default)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -929,6 +929,7 @@ pub enum ResizeDirection { East, /// Resize the window to the south. South, + #[default] /// Resize the window to the northwest. Northwest, /// Resize the window to the northeast. diff --git a/examples/window/window_drag_move.rs b/examples/window/window_drag_move.rs new file mode 100644 index 0000000000000..e7ab771b0c4aa --- /dev/null +++ b/examples/window/window_drag_move.rs @@ -0,0 +1,100 @@ +use bevy::{ + prelude::*, + window::ResizeDirection, +}; + +#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash, States)] +enum LeftClickAction { + Nothing, + Drag, + Resize, +} + +#[derive(Resource, Default)] +struct ResizeDir(ResizeDirection); + +fn main() { + App::new() + .add_plugins(DefaultPlugins.set(WindowPlugin { + primary_window: Some(Window { + decorations: false, + ..default() + }), + ..default() + })) + .init_resource::() + .insert_state(LeftClickAction::Drag) + .add_systems(Startup, setup) + .add_systems(Update, (change_state, move_windows)) + .run(); +} + +fn setup(mut commands: Commands) { + + // camera + commands.spawn(( + Camera3d::default(), + // Transform::from_xyz(-1.0, 1.0, 1.0).looking_at(Vec3::new(-1.0, 1.0, 0.0), Vec3::Y), + // CameraController::default(), + )); + + let style = TextStyle::default(); + commands + .spawn(( + NodeBundle { + style: Style { + position_type: PositionType::Absolute, + padding: UiRect::all(Val::Px(5.0)), + ..default() + }, + background_color: Color::BLACK.with_alpha(0.75).into(), + ..default() + }, + GlobalZIndex(i32::MAX), + )) + .with_children(|c| { + c.spawn(TextBundle::from_sections([ + TextSection::new("Controls:\n", style.clone()), + TextSection::new("A - change left click action [", style.clone()), + TextSection::new("Drag", style.clone()), + TextSection::new("]\n", style.clone()), + + TextSection::new("D - change resize direction [", style.clone()), + TextSection::new("NorthWest", style.clone()), + TextSection::new("]\n", style.clone()), + ])); + }); +} + +fn change_state(input: Res>, + state: Res>, + mut next_state: ResMut>, + mut example_text: Query<&mut Text>) { + use LeftClickAction::*; + if input.just_pressed(KeyCode::KeyA) { + let s = match state.get() { + Drag => Resize, + Resize => Nothing, + Nothing => Drag, + }; + next_state.set(s); + let mut example_text = example_text.single_mut(); + example_text.sections[2].value = format!("{:?}", s); + } +} + + +fn move_windows(mut windows: Query<&mut Window>, + state: Res>, + input: Res>, + dir: Res) { + if input.just_pressed(MouseButton::Left) { + for mut window in windows.iter_mut() { + match state.get() { + LeftClickAction::Nothing => (), + LeftClickAction::Drag => window.start_drag_move(), + LeftClickAction::Resize => window.start_drag_resize(dir.0), + } + } + } +} From e39fc925941df813a8334c911de63356e7018cb5 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Thu, 10 Oct 2024 03:47:37 -0400 Subject: [PATCH 02/10] refactor: Use CompassOctant not ResizeDirection. Add docs. --- crates/bevy_window/src/window.rs | 35 +-------- crates/bevy_winit/src/converters.rs | 24 +++--- examples/window/window_drag_move.rs | 110 +++++++++++++++++++--------- 3 files changed, 91 insertions(+), 78 deletions(-) diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index d591a60ca2f0d..5bbe983ebf716 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -4,7 +4,7 @@ use bevy_ecs::{ entity::{Entity, VisitEntities, VisitEntitiesMut}, prelude::{Component, ReflectComponent}, }; -use bevy_math::{DVec2, IVec2, UVec2, Vec2}; +use bevy_math::{CompassOctant, DVec2, IVec2, UVec2, Vec2}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; #[cfg(feature = "serialize")] @@ -379,7 +379,7 @@ impl Window { /// /// There is no guarantee that this will work unless the left mouse button was /// pressed immediately before this function was called. - pub fn start_drag_resize(&mut self, direction: ResizeDirection) { + pub fn start_drag_resize(&mut self, direction: CompassOctant) { self.internal.drag_resize_request = Some(direction); } @@ -913,33 +913,6 @@ pub enum CursorGrabMode { Locked, } -/// Defines the orientation in which a window resize will be performed. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Reflect, Hash, Default)] -#[cfg_attr( - feature = "serialize", - derive(serde::Serialize, serde::Deserialize), - reflect(Serialize, Deserialize) -)] -pub enum ResizeDirection { - /// Resize the window to the west. - West, - /// Resize the window to the north. - North, - /// Resize the window to the east. - East, - /// Resize the window to the south. - South, - #[default] - /// Resize the window to the northwest. - Northwest, - /// Resize the window to the northeast. - Northeast, - /// Resize the window to the southwest. - Southwest, - /// Resize the window to the southeast. - Southeast, -} - /// Stores internal [`Window`] state that isn't directly accessible. #[derive(Default, Debug, Copy, Clone, PartialEq, Reflect)] #[cfg_attr( @@ -956,7 +929,7 @@ pub struct InternalWindowState { /// If this is true then next frame we will ask to drag-move the window. drag_move_request: bool, /// If this is `Some` then the next frame we will ask to drag-resize the window. - drag_resize_request: Option, + drag_resize_request: Option, /// Unscaled cursor position. physical_cursor_position: Option, } @@ -978,7 +951,7 @@ impl InternalWindowState { } /// Consumes the current resize request, if it exists. This should only be called by window backends. - pub fn take_resize_request(&mut self) -> Option { + pub fn take_resize_request(&mut self) -> Option { self.drag_resize_request.take() } } diff --git a/crates/bevy_winit/src/converters.rs b/crates/bevy_winit/src/converters.rs index fc5ff5c29a10d..9a9c33ef36442 100644 --- a/crates/bevy_winit/src/converters.rs +++ b/crates/bevy_winit/src/converters.rs @@ -5,10 +5,10 @@ use bevy_input::{ touch::{ForceTouch, TouchInput, TouchPhase}, ButtonState, }; -use bevy_math::Vec2; +use bevy_math::{CompassOctant, Vec2}; #[cfg(feature = "custom_cursor")] use bevy_window::SystemCursorIcon; -use bevy_window::{EnabledButtons, ResizeDirection, WindowLevel, WindowTheme}; +use bevy_window::{EnabledButtons, WindowLevel, WindowTheme}; use winit::keyboard::{Key, NamedKey, NativeKey}; pub fn convert_keyboard_input( @@ -707,17 +707,15 @@ pub fn convert_enabled_buttons(enabled_buttons: EnabledButtons) -> winit::window window_buttons } -pub fn convert_resize_direction( - resize_direction: ResizeDirection, -) -> winit::window::ResizeDirection { +pub fn convert_resize_direction(resize_direction: CompassOctant) -> winit::window::ResizeDirection { match resize_direction { - ResizeDirection::West => winit::window::ResizeDirection::West, - ResizeDirection::North => winit::window::ResizeDirection::North, - ResizeDirection::East => winit::window::ResizeDirection::East, - ResizeDirection::South => winit::window::ResizeDirection::South, - ResizeDirection::Northwest => winit::window::ResizeDirection::NorthWest, - ResizeDirection::Northeast => winit::window::ResizeDirection::NorthEast, - ResizeDirection::Southwest => winit::window::ResizeDirection::SouthWest, - ResizeDirection::Southeast => winit::window::ResizeDirection::SouthEast, + CompassOctant::West => winit::window::ResizeDirection::West, + CompassOctant::North => winit::window::ResizeDirection::North, + CompassOctant::East => winit::window::ResizeDirection::East, + CompassOctant::South => winit::window::ResizeDirection::South, + CompassOctant::NorthWest => winit::window::ResizeDirection::NorthWest, + CompassOctant::NorthEast => winit::window::ResizeDirection::NorthEast, + CompassOctant::SouthWest => winit::window::ResizeDirection::SouthWest, + CompassOctant::SouthEast => winit::window::ResizeDirection::SouthEast, } } diff --git a/examples/window/window_drag_move.rs b/examples/window/window_drag_move.rs index e7ab771b0c4aa..b9e5fac504544 100644 --- a/examples/window/window_drag_move.rs +++ b/examples/window/window_drag_move.rs @@ -1,17 +1,37 @@ -use bevy::{ - prelude::*, - window::ResizeDirection, -}; +//! This example illustrates drag and drag resize without window decorations. +//! +//! When window decorations are not present, the user cannot drag the window. +//! The `start_drag_move()` function will permit the application to make the +//! window draggable. It does require that the left mouse button was pressed +//! when it is called. +use bevy::{math::CompassOctant, prelude::*}; -#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash, States)] +/// Determine what do on left click. +#[derive(Resource, Debug)] enum LeftClickAction { + /// Do nothing. Nothing, + /// Drag the window on left click. Drag, + /// Resize the window on left click. Resize, } -#[derive(Resource, Default)] -struct ResizeDir(ResizeDirection); +/// What direction index should the window resize toward. +#[derive(Resource)] +struct ResizeDir(usize); + +/// Directions that the drag resizes the window toward. +const DIRECTIONS: [CompassOctant; 8] = [ + CompassOctant::North, + CompassOctant::NorthEast, + CompassOctant::East, + CompassOctant::SouthEast, + CompassOctant::South, + CompassOctant::SouthWest, + CompassOctant::West, + CompassOctant::NorthWest, +]; fn main() { App::new() @@ -22,22 +42,18 @@ fn main() { }), ..default() })) - .init_resource::() - .insert_state(LeftClickAction::Drag) + .insert_resource(ResizeDir(7)) + .insert_resource(LeftClickAction::Drag) .add_systems(Startup, setup) - .add_systems(Update, (change_state, move_windows)) + .add_systems(Update, (handle_input, move_windows)) .run(); } fn setup(mut commands: Commands) { + // Camera + commands.spawn(Camera3d::default()); - // camera - commands.spawn(( - Camera3d::default(), - // Transform::from_xyz(-1.0, 1.0, 1.0).looking_at(Vec3::new(-1.0, 1.0, 0.0), Vec3::Y), - // CameraController::default(), - )); - + // UI let style = TextStyle::default(); commands .spawn(( @@ -54,46 +70,72 @@ fn setup(mut commands: Commands) { )) .with_children(|c| { c.spawn(TextBundle::from_sections([ - TextSection::new("Controls:\n", style.clone()), + TextSection::new( + "Demonstrate drag and drag resize without window decorations.\n\nControls:\n", + style.clone(), + ), TextSection::new("A - change left click action [", style.clone()), TextSection::new("Drag", style.clone()), TextSection::new("]\n", style.clone()), - - TextSection::new("D - change resize direction [", style.clone()), + TextSection::new("S / D - change resize direction [", style.clone()), TextSection::new("NorthWest", style.clone()), TextSection::new("]\n", style.clone()), ])); }); } -fn change_state(input: Res>, - state: Res>, - mut next_state: ResMut>, - mut example_text: Query<&mut Text>) { +fn handle_input( + input: Res>, + mut action: ResMut, + mut dir: ResMut, + mut example_text: Query<&mut Text>, +) { use LeftClickAction::*; if input.just_pressed(KeyCode::KeyA) { - let s = match state.get() { + *action = match *action { Drag => Resize, Resize => Nothing, Nothing => Drag, }; - next_state.set(s); let mut example_text = example_text.single_mut(); - example_text.sections[2].value = format!("{:?}", s); + example_text.sections[2].value = format!("{:?}", *action); + } + + if input.just_pressed(KeyCode::KeyS) { + dir.0 = dir + .0 + .checked_sub(1) + .unwrap_or(DIRECTIONS.len().saturating_sub(1)); + let mut example_text = example_text.single_mut(); + example_text.sections[5].value = format!("{:?}", DIRECTIONS[dir.0]); } -} + if input.just_pressed(KeyCode::KeyD) { + dir.0 = (dir.0 + 1) % DIRECTIONS.len(); + let mut example_text = example_text.single_mut(); + example_text.sections[5].value = format!("{:?}", DIRECTIONS[dir.0]); + } +} -fn move_windows(mut windows: Query<&mut Window>, - state: Res>, - input: Res>, - dir: Res) { +fn move_windows( + mut windows: Query<&mut Window>, + action: Res, + input: Res>, + dir: Res, +) { + // Both `start_drag_move()` and `start_drag_resize()` must be called after a + // left mouse button press. + // + // winit 0.30.5 may panic when initiated without a left mouse button press. if input.just_pressed(MouseButton::Left) { for mut window in windows.iter_mut() { - match state.get() { + match *action { LeftClickAction::Nothing => (), LeftClickAction::Drag => window.start_drag_move(), - LeftClickAction::Resize => window.start_drag_resize(dir.0), + LeftClickAction::Resize => { + let d = DIRECTIONS[dir.0]; + window.start_drag_resize(d); + } } } } From 8a2eb5824948b536d2e6fde7b80559f400777909 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Thu, 10 Oct 2024 04:00:20 -0400 Subject: [PATCH 03/10] refactor: Use new text span and writer APIs. --- examples/window/window_drag_move.rs | 35 +++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/examples/window/window_drag_move.rs b/examples/window/window_drag_move.rs index b9e5fac504544..b2b5e61d1fde3 100644 --- a/examples/window/window_drag_move.rs +++ b/examples/window/window_drag_move.rs @@ -68,19 +68,16 @@ fn setup(mut commands: Commands) { }, GlobalZIndex(i32::MAX), )) - .with_children(|c| { - c.spawn(TextBundle::from_sections([ - TextSection::new( - "Demonstrate drag and drag resize without window decorations.\n\nControls:\n", - style.clone(), - ), - TextSection::new("A - change left click action [", style.clone()), - TextSection::new("Drag", style.clone()), - TextSection::new("]\n", style.clone()), - TextSection::new("S / D - change resize direction [", style.clone()), - TextSection::new("NorthWest", style.clone()), - TextSection::new("]\n", style.clone()), - ])); + .with_children(|p| { + p.spawn(Text::default()).with_children(|p| { + p.spawn(TextSpan::new("Demonstrate drag and drag resize without window decorations.\n\nControls:\n")); + p.spawn(TextSpan::new("A - change left click action [")); + p.spawn(TextSpan::new("Drag")); + p.spawn(TextSpan::new("]\n")); + p.spawn(TextSpan::new("S / D - change resize direction [")); + p.spawn(TextSpan::new("NorthWest")); + p.spawn(TextSpan::new("]\n")); + }); }); } @@ -88,7 +85,8 @@ fn handle_input( input: Res>, mut action: ResMut, mut dir: ResMut, - mut example_text: Query<&mut Text>, + example_text: Query>, + mut writer: UiTextWriter, ) { use LeftClickAction::*; if input.just_pressed(KeyCode::KeyA) { @@ -97,8 +95,7 @@ fn handle_input( Resize => Nothing, Nothing => Drag, }; - let mut example_text = example_text.single_mut(); - example_text.sections[2].value = format!("{:?}", *action); + *writer.text(example_text.single(), 3) = format!("{:?}", *action); } if input.just_pressed(KeyCode::KeyS) { @@ -106,14 +103,12 @@ fn handle_input( .0 .checked_sub(1) .unwrap_or(DIRECTIONS.len().saturating_sub(1)); - let mut example_text = example_text.single_mut(); - example_text.sections[5].value = format!("{:?}", DIRECTIONS[dir.0]); + *writer.text(example_text.single(), 6) = format!("{:?}", DIRECTIONS[dir.0]); } if input.just_pressed(KeyCode::KeyD) { dir.0 = (dir.0 + 1) % DIRECTIONS.len(); - let mut example_text = example_text.single_mut(); - example_text.sections[5].value = format!("{:?}", DIRECTIONS[dir.0]); + *writer.text(example_text.single(), 6) = format!("{:?}", DIRECTIONS[dir.0]); } } From 5f4f0eb52b88215267b4cc38237a39967fc7069f Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Thu, 10 Oct 2024 04:06:12 -0400 Subject: [PATCH 04/10] chore: Removed unused variable. --- examples/window/window_drag_move.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/window/window_drag_move.rs b/examples/window/window_drag_move.rs index b2b5e61d1fde3..63ea692d2c1a0 100644 --- a/examples/window/window_drag_move.rs +++ b/examples/window/window_drag_move.rs @@ -54,7 +54,6 @@ fn setup(mut commands: Commands) { commands.spawn(Camera3d::default()); // UI - let style = TextStyle::default(); commands .spawn(( NodeBundle { @@ -70,7 +69,9 @@ fn setup(mut commands: Commands) { )) .with_children(|p| { p.spawn(Text::default()).with_children(|p| { - p.spawn(TextSpan::new("Demonstrate drag and drag resize without window decorations.\n\nControls:\n")); + p.spawn(TextSpan::new( + "Demonstrate drag and drag resize without window decorations.\n\nControls:\n", + )); p.spawn(TextSpan::new("A - change left click action [")); p.spawn(TextSpan::new("Drag")); p.spawn(TextSpan::new("]\n")); @@ -119,7 +120,7 @@ fn move_windows( dir: Res, ) { // Both `start_drag_move()` and `start_drag_resize()` must be called after a - // left mouse button press. + // left mouse button press as done here. // // winit 0.30.5 may panic when initiated without a left mouse button press. if input.just_pressed(MouseButton::Left) { From 853dcefdd300a0d116616e9f4a00ef2b9f7c0926 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Thu, 10 Oct 2024 04:09:37 -0400 Subject: [PATCH 05/10] doc: Fix wording. --- examples/window/window_drag_move.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/window/window_drag_move.rs b/examples/window/window_drag_move.rs index 63ea692d2c1a0..0a187c25c02b8 100644 --- a/examples/window/window_drag_move.rs +++ b/examples/window/window_drag_move.rs @@ -1,4 +1,5 @@ -//! This example illustrates drag and drag resize without window decorations. +//! This example illustrates drag move and drag resize without window +//! decorations. //! //! When window decorations are not present, the user cannot drag the window. //! The `start_drag_move()` function will permit the application to make the @@ -70,8 +71,9 @@ fn setup(mut commands: Commands) { .with_children(|p| { p.spawn(Text::default()).with_children(|p| { p.spawn(TextSpan::new( - "Demonstrate drag and drag resize without window decorations.\n\nControls:\n", + "Demonstrate drag move and drag resize without window decorations.\n\n", )); + p.spawn(TextSpan::new("Controls:\n")); p.spawn(TextSpan::new("A - change left click action [")); p.spawn(TextSpan::new("Drag")); p.spawn(TextSpan::new("]\n")); @@ -96,7 +98,7 @@ fn handle_input( Resize => Nothing, Nothing => Drag, }; - *writer.text(example_text.single(), 3) = format!("{:?}", *action); + *writer.text(example_text.single(), 4) = format!("{:?}", *action); } if input.just_pressed(KeyCode::KeyS) { @@ -104,12 +106,12 @@ fn handle_input( .0 .checked_sub(1) .unwrap_or(DIRECTIONS.len().saturating_sub(1)); - *writer.text(example_text.single(), 6) = format!("{:?}", DIRECTIONS[dir.0]); + *writer.text(example_text.single(), 7) = format!("{:?}", DIRECTIONS[dir.0]); } if input.just_pressed(KeyCode::KeyD) { dir.0 = (dir.0 + 1) % DIRECTIONS.len(); - *writer.text(example_text.single(), 6) = format!("{:?}", DIRECTIONS[dir.0]); + *writer.text(example_text.single(), 7) = format!("{:?}", DIRECTIONS[dir.0]); } } From 9e8c89192c477ccbd189de924712191cbb69398f Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Thu, 10 Oct 2024 04:14:04 -0400 Subject: [PATCH 06/10] doc: Better description in cargo.toml. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 567632489b332..855f02114a4bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3279,7 +3279,7 @@ doc-scrape-examples = true [package.metadata.example.window_drag_move] name = "Window Drag Move" -description = "Demonstrates moving window via API" +description = "Demonstrates drag move and drag resize without window decoration" category = "Window" wasm = false From 5f4952a5217e7b9119915cfdfe0f941568a7abcc Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Thu, 10 Oct 2024 04:31:44 -0400 Subject: [PATCH 07/10] doc: Build templated pages for examples. --- examples/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/README.md b/examples/README.md index b794bffad72cf..2e86ab866cc1e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -536,6 +536,7 @@ Example | Description [Scale Factor Override](../examples/window/scale_factor_override.rs) | Illustrates how to customize the default window settings [Screenshot](../examples/window/screenshot.rs) | Shows how to save screenshots to disk [Transparent Window](../examples/window/transparent_window.rs) | Illustrates making the window transparent and hiding the window decoration +[Window Drag Move](../examples/window/window_drag_move.rs) | Demonstrates drag move and drag resize without window decoration [Window Resizing](../examples/window/window_resizing.rs) | Demonstrates resizing and responding to resizing a window [Window Settings](../examples/window/window_settings.rs) | Demonstrates customizing default window settings From c08e2177ea049bab3e91c50b64f4ee8da76fbf0f Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Fri, 11 Oct 2024 19:06:30 -0400 Subject: [PATCH 08/10] excise: Remove errant newline. --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 855f02114a4bf..3e42f1231afeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2934,7 +2934,6 @@ name = "window_fallthrough" path = "examples/ui/window_fallthrough.rs" doc-scrape-examples = true - [package.metadata.example.window_fallthrough] name = "Window Fallthrough" description = "Illustrates how to access `winit::window::Window`'s `hittest` functionality." From 0c37250bd66f3e58df6302356b24c66a9b8778f6 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Mon, 14 Oct 2024 23:56:41 -0700 Subject: [PATCH 09/10] doc: Take into account feedback. Some refactoring from feedback too. --- examples/window/window_drag_move.rs | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/window/window_drag_move.rs b/examples/window/window_drag_move.rs index 0a187c25c02b8..d966a36b304a8 100644 --- a/examples/window/window_drag_move.rs +++ b/examples/window/window_drag_move.rs @@ -1,10 +1,15 @@ //! This example illustrates drag move and drag resize without window //! decorations. //! -//! When window decorations are not present, the user cannot drag the window. -//! The `start_drag_move()` function will permit the application to make the -//! window draggable. It does require that the left mouse button was pressed -//! when it is called. +//! When window decorations are not present, the user cannot drag a window by +//! its titlebar to change its position. The `start_drag_move()` function +//! permits a users to drag a window by left clicking anywhere in the window; +//! left click must be pressed and other constraints can be imposed. For +//! instance an application could require a user to hold down alt and left click +//! to drag a window. +//! +//! The `start_drag_resize()` function behaves similarly but permits a window to +//! be resized. use bevy::{math::CompassOctant, prelude::*}; /// Determine what do on left click. @@ -12,8 +17,8 @@ use bevy::{math::CompassOctant, prelude::*}; enum LeftClickAction { /// Do nothing. Nothing, - /// Drag the window on left click. - Drag, + /// Move the window on left click. + Move, /// Resize the window on left click. Resize, } @@ -44,9 +49,9 @@ fn main() { ..default() })) .insert_resource(ResizeDir(7)) - .insert_resource(LeftClickAction::Drag) + .insert_resource(LeftClickAction::Move) .add_systems(Startup, setup) - .add_systems(Update, (handle_input, move_windows)) + .add_systems(Update, (handle_input, move_or_resize_windows)) .run(); } @@ -75,7 +80,7 @@ fn setup(mut commands: Commands) { )); p.spawn(TextSpan::new("Controls:\n")); p.spawn(TextSpan::new("A - change left click action [")); - p.spawn(TextSpan::new("Drag")); + p.spawn(TextSpan::new("Move")); p.spawn(TextSpan::new("]\n")); p.spawn(TextSpan::new("S / D - change resize direction [")); p.spawn(TextSpan::new("NorthWest")); @@ -94,9 +99,9 @@ fn handle_input( use LeftClickAction::*; if input.just_pressed(KeyCode::KeyA) { *action = match *action { - Drag => Resize, + Move => Resize, Resize => Nothing, - Nothing => Drag, + Nothing => Move, }; *writer.text(example_text.single(), 4) = format!("{:?}", *action); } @@ -115,7 +120,7 @@ fn handle_input( } } -fn move_windows( +fn move_or_resize_windows( mut windows: Query<&mut Window>, action: Res, input: Res>, @@ -129,7 +134,7 @@ fn move_windows( for mut window in windows.iter_mut() { match *action { LeftClickAction::Nothing => (), - LeftClickAction::Drag => window.start_drag_move(), + LeftClickAction::Move => window.start_drag_move(), LeftClickAction::Resize => { let d = DIRECTIONS[dir.0]; window.start_drag_resize(d); From e78bb497891f6935e5f3ab99dbee4c2bb4adeca6 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Tue, 15 Oct 2024 16:23:24 -0700 Subject: [PATCH 10/10] refactor: Use TextUiWriter. --- examples/window/window_drag_move.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/window/window_drag_move.rs b/examples/window/window_drag_move.rs index d966a36b304a8..54f904707cce3 100644 --- a/examples/window/window_drag_move.rs +++ b/examples/window/window_drag_move.rs @@ -94,7 +94,7 @@ fn handle_input( mut action: ResMut, mut dir: ResMut, example_text: Query>, - mut writer: UiTextWriter, + mut writer: TextUiWriter, ) { use LeftClickAction::*; if input.just_pressed(KeyCode::KeyA) {