From 1f97717a3d350cbbf52941d419aad3889dabb4b2 Mon Sep 17 00:00:00 2001 From: Mateusz Wachowiak Date: Wed, 6 Dec 2023 21:32:34 +0100 Subject: [PATCH] Rename `Input` to `ButtonInput` (#10859) # Objective - Resolves #10853 ## Solution - ~~Changed the name of `Input` struct to `PressableInput`.~~ - Changed the name of `Input` struct to `ButtonInput`. ## Migration Guide - Breaking Change: Users need to rename `Input` to `ButtonInput` in their projects. --- .../src/{input.rs => button_input.rs} | 74 +++++++++---------- crates/bevy_input/src/common_conditions.rs | 29 ++++---- crates/bevy_input/src/gamepad.rs | 18 ++--- crates/bevy_input/src/keyboard.rs | 18 ++--- crates/bevy_input/src/lib.rs | 14 ++-- crates/bevy_input/src/mouse.rs | 14 ++-- crates/bevy_ui/src/focus.rs | 4 +- crates/bevy_window/src/system.rs | 4 +- examples/2d/2d_gizmos.rs | 6 +- examples/2d/bloom_2d.rs | 2 +- examples/2d/rotation.rs | 2 +- examples/3d/3d_gizmos.rs | 6 +- examples/3d/anti_aliasing.rs | 4 +- examples/3d/atmospheric_fog.rs | 2 +- examples/3d/blend_modes.rs | 2 +- examples/3d/bloom_3d.rs | 2 +- examples/3d/deferred_rendering.rs | 2 +- examples/3d/fog.rs | 2 +- examples/3d/generate_custom_mesh.rs | 2 +- examples/3d/lighting.rs | 2 +- examples/3d/parallax_mapping.rs | 8 +- examples/3d/shadow_biases.rs | 12 +-- examples/3d/shadow_caster_receiver.rs | 4 +- examples/3d/skybox.rs | 4 +- examples/3d/spotlight.rs | 2 +- examples/3d/ssao.rs | 2 +- examples/3d/tonemapping.rs | 8 +- examples/3d/transmission.rs | 2 +- examples/3d/wireframe.rs | 2 +- examples/animation/animated_fox.rs | 2 +- examples/audio/audio_control.rs | 10 ++- examples/audio/pitch.rs | 2 +- examples/audio/spatial_audio_2d.rs | 4 +- examples/audio/spatial_audio_3d.rs | 4 +- examples/ecs/generic_system.rs | 2 +- examples/ecs/run_conditions.rs | 4 +- examples/ecs/state.rs | 2 +- examples/games/alien_cake_addict.rs | 4 +- examples/games/breakout.rs | 2 +- examples/input/gamepad_input.rs | 2 +- examples/input/gamepad_rumble.rs | 2 +- examples/input/keyboard_input.rs | 2 +- examples/input/keyboard_modifiers.rs | 2 +- examples/input/mouse_grab.rs | 4 +- examples/input/mouse_input.rs | 2 +- examples/input/text_input.rs | 2 +- examples/shader/shader_prepass.rs | 2 +- examples/stress_tests/bevymark.rs | 2 +- examples/stress_tests/many_foxes.rs | 2 +- examples/stress_tests/many_gizmos.rs | 2 +- examples/tools/gamepad_viewer.rs | 2 +- .../tools/scene_viewer/animation_plugin.rs | 2 +- .../scene_viewer/camera_controller_plugin.rs | 4 +- .../tools/scene_viewer/morph_viewer_plugin.rs | 4 +- .../tools/scene_viewer/scene_viewer_plugin.rs | 4 +- examples/ui/overflow_debug.rs | 9 ++- examples/ui/ui_scaling.rs | 2 +- examples/ui/ui_texture_atlas.rs | 2 +- examples/ui/window_fallthrough.rs | 5 +- examples/window/clear_color.rs | 2 +- examples/window/low_power.rs | 2 +- examples/window/scale_factor_override.rs | 4 +- examples/window/screenshot.rs | 2 +- examples/window/window_resizing.rs | 2 +- examples/window/window_settings.rs | 12 +-- tests/how_to_test_systems.rs | 6 +- 66 files changed, 200 insertions(+), 177 deletions(-) rename crates/bevy_input/src/{input.rs => button_input.rs} (86%) diff --git a/crates/bevy_input/src/input.rs b/crates/bevy_input/src/button_input.rs similarity index 86% rename from crates/bevy_input/src/input.rs rename to crates/bevy_input/src/button_input.rs index bfcf8e9558..189f714355 100644 --- a/crates/bevy_input/src/input.rs +++ b/crates/bevy_input/src/button_input.rs @@ -16,26 +16,26 @@ use bevy_ecs::schedule::State; /// This type can be used as a resource to keep the current state of an input, by reacting to /// events from the input. For a given input value: /// -/// * [`Input::pressed`] will return `true` between a press and a release event. -/// * [`Input::just_pressed`] will return `true` for one frame after a press event. -/// * [`Input::just_released`] will return `true` for one frame after a release event. +/// * [`ButtonInput::pressed`] will return `true` between a press and a release event. +/// * [`ButtonInput::just_pressed`] will return `true` for one frame after a press event. +/// * [`ButtonInput::just_released`] will return `true` for one frame after a release event. /// /// ## Multiple systems /// -/// In case multiple systems are checking for [`Input::just_pressed`] or [`Input::just_released`] +/// In case multiple systems are checking for [`ButtonInput::just_pressed`] or [`ButtonInput::just_released`] /// but only one should react, for example in the case of triggering /// [`State`] change, you should consider clearing the input state, either by: /// -/// * Using [`Input::clear_just_pressed`] or [`Input::clear_just_released`] instead. -/// * Calling [`Input::clear`] or [`Input::reset`] immediately after the state change. +/// * Using [`ButtonInput::clear_just_pressed`] or [`ButtonInput::clear_just_released`] instead. +/// * Calling [`ButtonInput::clear`] or [`ButtonInput::reset`] immediately after the state change. /// /// ## Note /// /// When adding this resource for a new input type, you should: /// -/// * Call the [`Input::press`] method for each press event. -/// * Call the [`Input::release`] method for each release event. -/// * Call the [`Input::clear`] method at each frame start, before processing events. +/// * Call the [`ButtonInput::press`] method for each press event. +/// * Call the [`ButtonInput::release`] method for each release event. +/// * Call the [`ButtonInput::clear`] method at each frame start, before processing events. /// /// Note: Calling `clear` from a [`ResMut`] will trigger change detection. /// It may be preferable to use [`DetectChangesMut::bypass_change_detection`] @@ -45,7 +45,7 @@ use bevy_ecs::schedule::State; ///[`DetectChangesMut::bypass_change_detection`]: bevy_ecs::change_detection::DetectChangesMut::bypass_change_detection #[derive(Debug, Clone, Resource, Reflect)] #[reflect(Default)] -pub struct Input { +pub struct ButtonInput { /// A collection of every button that is currently being pressed. pressed: HashSet, /// A collection of every button that has just been pressed. @@ -54,7 +54,7 @@ pub struct Input { just_released: HashSet, } -impl Default for Input { +impl Default for ButtonInput { fn default() -> Self { Self { pressed: Default::default(), @@ -64,7 +64,7 @@ impl Default for Input { } } -impl Input +impl ButtonInput where T: Copy + Eq + Hash + Send + Sync + 'static, { @@ -112,7 +112,7 @@ where /// Clears the `just_pressed` state of the `input` and returns `true` if the `input` has just been pressed. /// - /// Future calls to [`Input::just_pressed`] for the given input will return false until a new press event occurs. + /// Future calls to [`ButtonInput::just_pressed`] for the given input will return false until a new press event occurs. pub fn clear_just_pressed(&mut self, input: T) -> bool { self.just_pressed.remove(&input) } @@ -129,7 +129,7 @@ where /// Clears the `just_released` state of the `input` and returns `true` if the `input` has just been released. /// - /// Future calls to [`Input::just_released`] for the given input will return false until a new release event occurs. + /// Future calls to [`ButtonInput::just_released`] for the given input will return false until a new release event occurs. pub fn clear_just_released(&mut self, input: T) -> bool { self.just_released.remove(&input) } @@ -143,7 +143,7 @@ where /// Clears the `pressed`, `just_pressed`, and `just_released` data for every input. /// - /// See also [`Input::clear`] for simulating elapsed time steps. + /// See also [`ButtonInput::clear`] for simulating elapsed time steps. pub fn reset_all(&mut self) { self.pressed.clear(); self.just_pressed.clear(); @@ -152,7 +152,7 @@ where /// Clears the `just pressed` and `just released` data for every input. /// - /// See also [`Input::reset_all`] for a full reset. + /// See also [`ButtonInput::reset_all`] for a full reset. pub fn clear(&mut self) { self.just_pressed.clear(); self.just_released.clear(); @@ -178,9 +178,9 @@ where mod test { use bevy_reflect::TypePath; - use crate::Input; + use crate::ButtonInput; - /// Used for testing the functionality of [`Input`]. + /// Used for testing the functionality of [`ButtonInput`]. #[derive(TypePath, Copy, Clone, Eq, PartialEq, Hash)] enum DummyInput { Input1, @@ -189,7 +189,7 @@ mod test { #[test] fn test_press() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); assert!(!input.pressed.contains(&DummyInput::Input1)); assert!(!input.just_pressed.contains(&DummyInput::Input1)); input.press(DummyInput::Input1); @@ -199,7 +199,7 @@ mod test { #[test] fn test_pressed() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); assert!(!input.pressed(DummyInput::Input1)); input.press(DummyInput::Input1); assert!(input.pressed(DummyInput::Input1)); @@ -207,7 +207,7 @@ mod test { #[test] fn test_any_pressed() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); assert!(!input.any_pressed([DummyInput::Input1])); assert!(!input.any_pressed([DummyInput::Input2])); assert!(!input.any_pressed([DummyInput::Input1, DummyInput::Input2])); @@ -219,7 +219,7 @@ mod test { #[test] fn test_release() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); assert!(input.pressed.contains(&DummyInput::Input1)); assert!(!input.just_released.contains(&DummyInput::Input1)); @@ -230,7 +230,7 @@ mod test { #[test] fn test_release_all() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); input.press(DummyInput::Input2); input.release_all(); @@ -241,7 +241,7 @@ mod test { #[test] fn test_just_pressed() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); assert!(!input.just_pressed(DummyInput::Input1)); input.press(DummyInput::Input1); assert!(input.just_pressed(DummyInput::Input1)); @@ -249,7 +249,7 @@ mod test { #[test] fn test_any_just_pressed() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); assert!(!input.any_just_pressed([DummyInput::Input1])); assert!(!input.any_just_pressed([DummyInput::Input2])); assert!(!input.any_just_pressed([DummyInput::Input1, DummyInput::Input2])); @@ -261,7 +261,7 @@ mod test { #[test] fn test_clear_just_pressed() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); assert!(input.just_pressed(DummyInput::Input1)); input.clear_just_pressed(DummyInput::Input1); @@ -270,7 +270,7 @@ mod test { #[test] fn test_just_released() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); assert!(!input.just_released(DummyInput::Input1)); input.release(DummyInput::Input1); @@ -279,7 +279,7 @@ mod test { #[test] fn test_any_just_released() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); assert!(!input.any_just_released([DummyInput::Input1])); assert!(!input.any_just_released([DummyInput::Input2])); @@ -292,7 +292,7 @@ mod test { #[test] fn test_clear_just_released() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); input.release(DummyInput::Input1); assert!(input.just_released(DummyInput::Input1)); @@ -302,7 +302,7 @@ mod test { #[test] fn test_reset() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); // Pressed input.press(DummyInput::Input1); @@ -328,7 +328,7 @@ mod test { #[test] fn test_reset_all() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); input.press(DummyInput::Input2); @@ -344,7 +344,7 @@ mod test { #[test] fn test_clear() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); // Pressed input.press(DummyInput::Input1); @@ -370,7 +370,7 @@ mod test { #[test] fn test_get_pressed() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); input.press(DummyInput::Input2); let pressed = input.get_pressed(); @@ -382,7 +382,7 @@ mod test { #[test] fn test_get_just_pressed() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); input.press(DummyInput::Input2); let just_pressed = input.get_just_pressed(); @@ -394,7 +394,7 @@ mod test { #[test] fn test_get_just_released() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); input.press(DummyInput::Input2); input.release(DummyInput::Input1); @@ -408,7 +408,7 @@ mod test { #[test] fn test_general_input_handling() { - let mut input = Input::default(); + let mut input = ButtonInput::default(); // Test pressing input.press(DummyInput::Input1); @@ -453,7 +453,7 @@ mod test { assert!(!input.just_released(DummyInput::Input2)); // Set up an `Input` to test resetting - let mut input = Input::default(); + let mut input = ButtonInput::default(); input.press(DummyInput::Input1); input.release(DummyInput::Input2); diff --git a/crates/bevy_input/src/common_conditions.rs b/crates/bevy_input/src/common_conditions.rs index 06043a0ae9..502ded76e8 100644 --- a/crates/bevy_input/src/common_conditions.rs +++ b/crates/bevy_input/src/common_conditions.rs @@ -1,8 +1,8 @@ -use crate::Input; +use crate::ButtonInput; use bevy_ecs::system::Res; use std::hash::Hash; -/// Stateful run condition that can be toggled via a input press using [`Input::just_pressed`]. +/// Stateful run condition that can be toggled via a input press using [`ButtonInput::just_pressed`]. /// /// ```rust,no_run /// use bevy::prelude::*; @@ -47,26 +47,29 @@ use std::hash::Hash; /// } /// /// ``` -pub fn input_toggle_active(default: bool, input: T) -> impl FnMut(Res>) -> bool + Clone +pub fn input_toggle_active( + default: bool, + input: T, +) -> impl FnMut(Res>) -> bool + Clone where T: Copy + Eq + Hash + Send + Sync + 'static, { let mut active = default; - move |inputs: Res>| { + move |inputs: Res>| { active ^= inputs.just_pressed(input); active } } -/// Run condition that is active if [`Input::pressed`] is true for the given input. -pub fn input_pressed(input: T) -> impl FnMut(Res>) -> bool + Clone +/// Run condition that is active if [`ButtonInput::pressed`] is true for the given input. +pub fn input_pressed(input: T) -> impl FnMut(Res>) -> bool + Clone where T: Copy + Eq + Hash + Send + Sync + 'static, { - move |inputs: Res>| inputs.pressed(input) + move |inputs: Res>| inputs.pressed(input) } -/// Run condition that is active if [`Input::just_pressed`] is true for the given input. +/// Run condition that is active if [`ButtonInput::just_pressed`] is true for the given input. /// /// ```rust,no_run /// use bevy::prelude::*; @@ -80,19 +83,19 @@ where /// /// # fn jump() {} /// ``` -pub fn input_just_pressed(input: T) -> impl FnMut(Res>) -> bool + Clone +pub fn input_just_pressed(input: T) -> impl FnMut(Res>) -> bool + Clone where T: Copy + Eq + Hash + Send + Sync + 'static, { - move |inputs: Res>| inputs.just_pressed(input) + move |inputs: Res>| inputs.just_pressed(input) } -/// Run condition that is active if [`Input::just_released`] is true for the given input. -pub fn input_just_released(input: T) -> impl FnMut(Res>) -> bool + Clone +/// Run condition that is active if [`ButtonInput::just_released`] is true for the given input. +pub fn input_just_released(input: T) -> impl FnMut(Res>) -> bool + Clone where T: Copy + Eq + Hash + Send + Sync + 'static, { - move |inputs: Res>| inputs.just_released(input) + move |inputs: Res>| inputs.just_released(input) } #[cfg(test)] diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index 338458605e..dc45cc41fb 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -1,6 +1,6 @@ //! The gamepad input functionality. -use crate::{Axis, ButtonState, Input}; +use crate::{Axis, ButtonInput, ButtonState}; use bevy_ecs::event::{Event, EventReader, EventWriter}; use bevy_ecs::{ change_detection::DetectChangesMut, @@ -165,7 +165,7 @@ impl Gamepads { /// /// This is used to determine which button has changed its value when receiving a /// [`GamepadButtonChangedEvent`]. It is also used in the [`GamepadButton`] -/// which in turn is used to create the [`Input`] or +/// which in turn is used to create the [`ButtonInput`] or /// [`Axis`] `bevy` resources. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Reflect)] #[reflect(Debug, Hash, PartialEq)] @@ -226,7 +226,7 @@ pub enum GamepadButtonType { /// /// ## Usage /// -/// It is used as the generic `T` value of an [`Input`] and [`Axis`] to create `bevy` resources. These +/// It is used as the generic `T` value of an [`ButtonInput`] and [`Axis`] to create `bevy` resources. These /// resources store the data of the buttons of a gamepad and can be accessed inside of a system. /// /// ## Updating @@ -1011,7 +1011,7 @@ impl ButtonAxisSettings { /// Handles [`GamepadConnectionEvent`]s and updates gamepad resources. /// /// Updates the [`Gamepads`] resource and resets and/or initializes -/// the [`Axis`] and [`Input`] resources. +/// the [`Axis`] and [`ButtonInput`] resources. /// /// ## Note /// @@ -1021,7 +1021,7 @@ pub fn gamepad_connection_system( mut connection_events: EventReader, mut axis: ResMut>, mut button_axis: ResMut>, - mut button_input: ResMut>, + mut button_input: ResMut>, ) { for connection_event in connection_events.read() { let gamepad = connection_event.gamepad; @@ -1163,7 +1163,7 @@ impl GamepadButtonChangedEvent { } } -/// Uses [`GamepadAxisChangedEvent`]s to update the relevant [`Input`] and [`Axis`] values. +/// Uses [`GamepadAxisChangedEvent`]s to update the relevant [`ButtonInput`] and [`Axis`] values. pub fn gamepad_axis_event_system( mut gamepad_axis: ResMut>, mut axis_events: EventReader, @@ -1174,10 +1174,10 @@ pub fn gamepad_axis_event_system( } } -/// Uses [`GamepadButtonChangedEvent`]s to update the relevant [`Input`] and [`Axis`] values. +/// Uses [`GamepadButtonChangedEvent`]s to update the relevant [`ButtonInput`] and [`Axis`] values. pub fn gamepad_button_event_system( mut button_changed_events: EventReader, - mut button_input: ResMut>, + mut button_input: ResMut>, mut button_input_events: EventWriter, settings: Res, ) { @@ -1255,7 +1255,7 @@ pub fn gamepad_event_system( mut connection_events: EventWriter, mut button_events: EventWriter, mut axis_events: EventWriter, - mut button_input: ResMut>, + mut button_input: ResMut>, ) { button_input.bypass_change_detection().clear(); for gamepad_event in gamepad_events.read() { diff --git a/crates/bevy_input/src/keyboard.rs b/crates/bevy_input/src/keyboard.rs index 72abfc4d9d..383a750a5e 100644 --- a/crates/bevy_input/src/keyboard.rs +++ b/crates/bevy_input/src/keyboard.rs @@ -1,6 +1,6 @@ //! The keyboard input functionality. -use crate::{ButtonState, Input}; +use crate::{ButtonInput, ButtonState}; use bevy_ecs::entity::Entity; use bevy_ecs::{ change_detection::DetectChangesMut, @@ -20,7 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// ## Usage /// /// The event is consumed inside of the [`keyboard_input_system`] -/// to update the [`Input`](Input) resource. +/// to update the [`Input`](ButtonInput) resource. #[derive(Event, Debug, Clone, Copy, PartialEq, Eq, Reflect)] #[reflect(Debug, PartialEq)] #[cfg_attr( @@ -39,15 +39,15 @@ pub struct KeyboardInput { pub window: Entity, } -/// Updates the [`Input`] resource with the latest [`KeyboardInput`] events. +/// Updates the [`ButtonInput`] resource with the latest [`KeyboardInput`] events. /// /// ## Differences /// -/// The main difference between the [`KeyboardInput`] event and the [`Input`] or [`Input`] resources is that -/// the latter have convenient functions such as [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`]. +/// The main difference between the [`KeyboardInput`] event and the [`ButtonInput`] or [`ButtonInput`] resources is that +/// the latter have convenient functions such as [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`]. pub fn keyboard_input_system( - mut scan_input: ResMut>, - mut key_input: ResMut>, + mut scan_input: ResMut>, + mut key_input: ResMut>, mut keyboard_input_events: EventReader, ) { // Avoid clearing if it's not empty to ensure change detection is not triggered. @@ -74,7 +74,7 @@ pub fn keyboard_input_system( /// /// ## Usage /// -/// It is used as the generic `T` value of an [`Input`] to create a `Res>`. +/// It is used as the generic `T` value of an [`ButtonInput`] to create a `Res>`. /// The resource values are mapped to the current layout of the keyboard and correlate to an [`ScanCode`]. /// /// ## Updating @@ -447,7 +447,7 @@ pub enum KeyCode { /// /// ## Usage /// -/// It is used as the generic `` value of an [`Input`] to create a `Res>`. +/// It is used as the generic `` value of an [`ButtonInput`] to create a `Res>`. /// The resource values are mapped to the physical location of a key on the keyboard and correlate to an [`KeyCode`] /// /// ## Updating diff --git a/crates/bevy_input/src/lib.rs b/crates/bevy_input/src/lib.rs index 259b1623f1..ae22786f30 100644 --- a/crates/bevy_input/src/lib.rs +++ b/crates/bevy_input/src/lib.rs @@ -7,17 +7,17 @@ //! `bevy` currently supports keyboard, mouse, gamepad, and touch inputs. mod axis; +mod button_input; /// Common run conditions pub mod common_conditions; pub mod gamepad; -mod input; pub mod keyboard; pub mod mouse; pub mod touch; pub mod touchpad; pub use axis::*; -pub use input::*; +pub use button_input::*; /// Most commonly used re-exported types. pub mod prelude { @@ -29,7 +29,7 @@ pub mod prelude { keyboard::{KeyCode, ScanCode}, mouse::MouseButton, touch::{TouchInput, Touches}, - Axis, Input, + Axis, ButtonInput, }; } @@ -68,14 +68,14 @@ impl Plugin for InputPlugin { app // keyboard .add_event::() - .init_resource::>() - .init_resource::>() + .init_resource::>() + .init_resource::>() .add_systems(PreUpdate, keyboard_input_system.in_set(InputSystem)) // mouse .add_event::() .add_event::() .add_event::() - .init_resource::>() + .init_resource::>() .add_systems(PreUpdate, mouse_button_input_system.in_set(InputSystem)) .add_event::() .add_event::() @@ -88,7 +88,7 @@ impl Plugin for InputPlugin { .add_event::() .init_resource::() .init_resource::() - .init_resource::>() + .init_resource::>() .init_resource::>() .init_resource::>() .add_systems( diff --git a/crates/bevy_input/src/mouse.rs b/crates/bevy_input/src/mouse.rs index c0a63c17ae..7c90ff1fcb 100644 --- a/crates/bevy_input/src/mouse.rs +++ b/crates/bevy_input/src/mouse.rs @@ -1,6 +1,6 @@ //! The mouse input functionality. -use crate::{ButtonState, Input}; +use crate::{ButtonInput, ButtonState}; use bevy_ecs::entity::Entity; use bevy_ecs::{ change_detection::DetectChangesMut, @@ -20,7 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// ## Usage /// /// The event is read inside of the [`mouse_button_input_system`] -/// to update the [`Input`](Input) resource. +/// to update the [`Input`](ButtonInput) resource. #[derive(Event, Debug, Clone, Copy, PartialEq, Eq, Reflect)] #[reflect(Debug, PartialEq)] #[cfg_attr( @@ -41,7 +41,7 @@ pub struct MouseButtonInput { /// /// ## Usage /// -/// It is used as the generic `T` value of an [`Input`] to create a `bevy` +/// It is used as the generic `T` value of an [`ButtonInput`] to create a `bevy` /// resource. /// /// ## Updating @@ -133,14 +133,14 @@ pub struct MouseWheel { pub window: Entity, } -/// Updates the [`Input`] resource with the latest [`MouseButtonInput`] events. +/// Updates the [`ButtonInput`] resource with the latest [`MouseButtonInput`] events. /// /// ## Differences /// -/// The main difference between the [`MouseButtonInput`] event and the [`Input`] resource is that -/// the latter has convenient functions like [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`]. +/// The main difference between the [`MouseButtonInput`] event and the [`ButtonInput`] resource is that +/// the latter has convenient functions like [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`]. pub fn mouse_button_input_system( - mut mouse_button_input: ResMut>, + mut mouse_button_input: ResMut>, mut mouse_button_input_events: EventReader, ) { mouse_button_input.bypass_change_detection().clear(); diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 7302fdfc3e..ea4a971cdc 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -7,7 +7,7 @@ use bevy_ecs::{ reflect::ReflectComponent, system::{Local, Query, Res}, }; -use bevy_input::{mouse::MouseButton, touch::Touches, Input}; +use bevy_input::{mouse::MouseButton, touch::Touches, ButtonInput}; use bevy_math::{Rect, Vec2}; use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; use bevy_render::{camera::NormalizedRenderTarget, prelude::Camera, view::ViewVisibility}; @@ -126,7 +126,7 @@ pub fn ui_focus_system( mut state: Local, camera: Query<(&Camera, Option<&UiCameraConfig>)>, windows: Query<&Window>, - mouse_button_input: Res>, + mouse_button_input: Res>, touches_input: Res, ui_scale: Res, ui_stack: Res, diff --git a/crates/bevy_window/src/system.rs b/crates/bevy_window/src/system.rs index b7dec35a10..96db42c96c 100644 --- a/crates/bevy_window/src/system.rs +++ b/crates/bevy_window/src/system.rs @@ -2,7 +2,7 @@ use crate::{PrimaryWindow, Window, WindowCloseRequested}; use bevy_app::AppExit; use bevy_ecs::prelude::*; -use bevy_input::{keyboard::KeyCode, Input}; +use bevy_input::{keyboard::KeyCode, ButtonInput}; /// Exit the application when there are no open windows. /// @@ -52,7 +52,7 @@ pub fn close_when_requested(mut commands: Commands, mut closed: EventReader, - input: Res>, + input: Res>, ) { for (window, focus) in focused_windows.iter() { if !focus.focused { diff --git a/examples/2d/2d_gizmos.rs b/examples/2d/2d_gizmos.rs index a5aadbb2ad..196e73f1f5 100644 --- a/examples/2d/2d_gizmos.rs +++ b/examples/2d/2d_gizmos.rs @@ -61,7 +61,11 @@ fn system(mut gizmos: Gizmos, time: Res