Skip to content

Commit

Permalink
Move ElementState to top-level of bevy_input. Resolves #687. (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
CleanCut authored Nov 3, 2020
1 parent d4dc115 commit 2f87ff6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
15 changes: 1 addition & 14 deletions crates/bevy_input/src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Input;
use crate::{ElementState, Input};
use bevy_app::prelude::*;
use bevy_ecs::{Local, Res, ResMut};

Expand All @@ -10,19 +10,6 @@ pub struct KeyboardInput {
pub state: ElementState,
}

/// The current "press" state of an element
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ElementState {
Pressed,
Released,
}

impl ElementState {
pub fn is_pressed(&self) -> bool {
matches!(self, ElementState::Pressed)
}
}

/// State used by the keyboard input system
#[derive(Default)]
pub struct KeyboardInputState {
Expand Down
13 changes: 13 additions & 0 deletions crates/bevy_input/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ impl Plugin for InputPlugin {
.add_system_to_stage(bevy_app::stage::EVENT, touch_screen_input_system.system());
}
}

/// The current "press" state of an element
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ElementState {
Pressed,
Released,
}

impl ElementState {
pub fn is_pressed(&self) -> bool {
matches!(self, ElementState::Pressed)
}
}
3 changes: 1 addition & 2 deletions crates/bevy_input/src/mouse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::keyboard::ElementState;
use crate::Input;
use crate::{ElementState, Input};
use bevy_app::prelude::{EventReader, Events};
use bevy_ecs::{Local, Res, ResMut};
use bevy_math::Vec2;
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_input/src/system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::keyboard::{ElementState, KeyCode, KeyboardInput};
use crate::{
keyboard::{KeyCode, KeyboardInput},
ElementState,
};
use bevy_app::{
prelude::{EventReader, Events},
AppExit,
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_winit/src/converters.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use bevy_input::{
keyboard::{ElementState, KeyCode, KeyboardInput},
keyboard::{KeyCode, KeyboardInput},
mouse::MouseButton,
touch::{TouchInput, TouchPhase},
ElementState,
};
use bevy_math::Vec2;

Expand Down

0 comments on commit 2f87ff6

Please sign in to comment.