diff --git a/crates/bevy_input/src/keyboard.rs b/crates/bevy_input/src/keyboard.rs index 3a652330fc6cae..e829b90e478dcc 100644 --- a/crates/bevy_input/src/keyboard.rs +++ b/crates/bevy_input/src/keyboard.rs @@ -1,4 +1,4 @@ -use crate::{ElementState, Input}; +use crate::{ButtonState, Input}; use bevy_ecs::event::EventReader; use bevy_ecs::system::ResMut; @@ -7,7 +7,7 @@ use bevy_ecs::system::ResMut; pub struct KeyboardInput { pub scan_code: u32, pub key_code: Option, - pub state: ElementState, + pub state: ButtonState, } /// Updates the `Input` resource with the latest `KeyboardInput` events @@ -24,8 +24,8 @@ pub fn keyboard_input_system( } = event { match state { - ElementState::Pressed => keyboard_input.press(*key_code), - ElementState::Released => keyboard_input.release(*key_code), + ButtonState::Pressed => keyboard_input.press(*key_code), + ButtonState::Released => keyboard_input.release(*key_code), } } } diff --git a/crates/bevy_input/src/lib.rs b/crates/bevy_input/src/lib.rs index af4d1dd461429a..142f1883550cc8 100644 --- a/crates/bevy_input/src/lib.rs +++ b/crates/bevy_input/src/lib.rs @@ -90,13 +90,13 @@ impl Plugin for InputPlugin { /// The current "press" state of an element #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] -pub enum ElementState { +pub enum ButtonState { Pressed, Released, } -impl ElementState { +impl ButtonState { pub fn is_pressed(&self) -> bool { - matches!(self, ElementState::Pressed) + matches!(self, ButtonState::Pressed) } } diff --git a/crates/bevy_input/src/mouse.rs b/crates/bevy_input/src/mouse.rs index 10e32932faeeca..68f1540bb27fb8 100644 --- a/crates/bevy_input/src/mouse.rs +++ b/crates/bevy_input/src/mouse.rs @@ -1,4 +1,4 @@ -use crate::{ElementState, Input}; +use crate::{ButtonState, Input}; use bevy_ecs::{event::EventReader, system::ResMut}; use bevy_math::Vec2; @@ -6,7 +6,7 @@ use bevy_math::Vec2; #[derive(Debug, Clone)] pub struct MouseButtonInput { pub button: MouseButton, - pub state: ElementState, + pub state: ButtonState, } /// A button on a mouse device @@ -49,8 +49,8 @@ pub fn mouse_button_input_system( mouse_button_input.clear(); for event in mouse_button_input_events.iter() { match event.state { - ElementState::Pressed => mouse_button_input.press(event.button), - ElementState::Released => mouse_button_input.release(event.button), + ButtonState::Pressed => mouse_button_input.press(event.button), + ButtonState::Released => mouse_button_input.release(event.button), } } } diff --git a/crates/bevy_input/src/system.rs b/crates/bevy_input/src/system.rs index 753115bdebcdbf..d21fd70ee390f7 100644 --- a/crates/bevy_input/src/system.rs +++ b/crates/bevy_input/src/system.rs @@ -1,4 +1,4 @@ -use crate::{ElementState, KeyCode, KeyboardInput}; +use crate::{ButtonState, KeyCode, KeyboardInput}; use bevy_app::AppExit; use bevy_ecs::prelude::{EventReader, EventWriter}; @@ -14,7 +14,7 @@ pub fn exit_on_esc_system( ) { for event in keyboard_input_events.iter() { if let Some(key_code) = event.key_code { - if event.state == ElementState::Pressed && key_code == KeyCode::Escape { + if event.state == ButtonState::Pressed && key_code == KeyCode::Escape { app_exit_events.send_default(); } } diff --git a/crates/bevy_winit/src/converters.rs b/crates/bevy_winit/src/converters.rs index e1e7451d07dd95..3c131ad470c9f0 100644 --- a/crates/bevy_winit/src/converters.rs +++ b/crates/bevy_winit/src/converters.rs @@ -2,7 +2,7 @@ use bevy_input::{ keyboard::{KeyCode, KeyboardInput}, mouse::MouseButton, touch::{ForceTouch, TouchInput, TouchPhase}, - ElementState, + ButtonState, }; use bevy_math::Vec2; use bevy_window::CursorIcon; @@ -15,10 +15,10 @@ pub fn convert_keyboard_input(keyboard_input: &winit::event::KeyboardInput) -> K } } -pub fn convert_element_state(element_state: winit::event::ElementState) -> ElementState { +pub fn convert_element_state(element_state: winit::event::ElementState) -> ButtonState { match element_state { - winit::event::ElementState::Pressed => ElementState::Pressed, - winit::event::ElementState::Released => ElementState::Released, + winit::event::ElementState::Pressed => ButtonState::Pressed, + winit::event::ElementState::Released => ButtonState::Released, } }