Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more click functionality #275

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/avsb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn current_count_render(
move |In(_entity): In<Entity>,
mut event: ResMut<KEvent>,
mut query: Query<&mut CurrentCountState>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
event.prevent_default();
event.stop_propagation();
if let Ok(mut current_count) = query.get_mut(state_entity) {
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn startup(
move |In(_entity): In<Entity>,
event: Res<KEvent>,
mut active_color: ResMut<ActiveColor>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
active_color.index = (active_color.index + 1) % COLORS.len();
}
},
Expand Down
4 changes: 2 additions & 2 deletions examples/conditional_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn my_widget_render(
mut query: Query<&mut MyWidgetState>| {
event.prevent_default();
event.stop_propagation();
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
if let Ok(mut state) = query.get_mut(state_entity) {
state.show_window = true;
}
Expand All @@ -79,7 +79,7 @@ fn my_widget_render(
move |In(_entity): In<Entity>,
mut event: ResMut<KEvent>,
mut query: Query<&mut MyWidgetState>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
event.prevent_default();
event.stop_propagation();
if let Ok(mut state) = query.get_mut(state_entity) {
Expand Down
2 changes: 1 addition & 1 deletion examples/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn update_theme_button(
query: Query<&ThemeButton>,
mut context_query: Query<&mut Theme>,
| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
if let Ok(button) = query.get(theme_button_entity) {
if let Ok(mut context_theme) = context_query.get_mut(theme_context_entity) {
*context_theme = button.theme.clone();
Expand Down
2 changes: 1 addition & 1 deletion examples/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn startup(

let handle_click_close = OnEvent::new(
move |In(_entity): In<Entity>, event: ResMut<KEvent>, mut exit: EventWriter<AppExit>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
exit.send(AppExit);
}
},
Expand Down
4 changes: 2 additions & 2 deletions examples/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn my_widget_render(
mut query: Query<&mut MyWidgetState>| {
event.prevent_default();
event.stop_propagation();
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
if let Ok(mut state) = query.get_mut(state_entity) {
state.show_modal = true;
}
Expand Down Expand Up @@ -107,7 +107,7 @@ fn my_widget_render(
move |In(_entity): In<Entity>,
mut event: ResMut<KEvent>,
mut query: Query<&mut MyWidgetState>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
event.prevent_default();
event.stop_propagation();
if let Ok(mut state) = query.get_mut(state_entity) {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn current_count_render(
move |In(_entity): In<Entity>,
mut event: ResMut<KEvent>,
mut query: Query<&mut CurrentCountState>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
event.prevent_default();
event.stop_propagation();
if let Ok(mut current_count) = query.get_mut(state_entity) {
Expand Down
2 changes: 1 addition & 1 deletion examples/tabs/tab_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn tab_button_render(
move |In(_entity): In<Entity>,
event: Res<KEvent>,
mut query: Query<&mut TabContext>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
if let Ok(mut tab_context) = query.get_mut(context_entity) {
tab_context.current_index = button_index;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/todo/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn render_todo_input(

let handle_click = OnEvent::new(
move |In(_entity): In<Entity>, event: Res<KEvent>, mut todo_list: ResMut<TodoList>| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
if !todo_list.new_item.is_empty() {
let value = todo_list.new_item.clone();
todo_list.items.push(value);
Expand Down
2 changes: 1 addition & 1 deletion examples/todo/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn render_todo_items(
move |In(_entity): In<Entity>,
event: Res<KEvent>,
mut todo_list: ResMut<TodoList>,| {
if let EventType::Click(..) = event.event_type {
if let EventType::LeftClick(..) = event.event_type {
todo_list.items.remove(index);
}
},
Expand Down
60 changes: 44 additions & 16 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::{Entity, Resource, World};
use bevy::{prelude::{Entity, Resource, World}, window::Cursor};

use crate::{
cursor::{CursorEvent, ScrollEvent},
Expand Down Expand Up @@ -38,7 +38,7 @@ impl Default for KEvent {
Self {
target: Entity::from_raw(0),
current_target: Entity::from_raw(0),
event_type: EventType::Click(CursorEvent::default()),
event_type: EventType::LeftClick(CursorEvent::default()),
should_propagate: true,
default_prevented: false,
on_change_systems: Vec::new(),
Expand Down Expand Up @@ -71,9 +71,13 @@ impl KEvent {
pub fn stop_propagation(&mut self) {
if matches!(
self.event_type,
EventType::Click(..)
EventType::LeftClick(..)
| EventType::RightClick(..)
| EventType::MiddleClick(..)
| EventType::MouseIn(..)
| EventType::MouseDown(..)
| EventType::MouseLeftDown(..)
| EventType::MouseRightDown(..)
| EventType::MouseMiddleDown(..)
| EventType::Scroll(..)
| EventType::Focus
| EventType::Hover(..)
Expand Down Expand Up @@ -110,18 +114,30 @@ impl KEvent {
/// with a custom wrapper.
#[derive(Debug, Clone, Copy)]
pub enum EventType {
/// An event that occurs when the user clicks a widget
Click(CursorEvent),
/// An event that occurs when the user left clicks a widget
LeftClick(CursorEvent),
/// An event that occurs when the user right clicks a widget
RightClick(CursorEvent),
/// An event that occurs when the user middle clicks a widget
MiddleClick(CursorEvent),
/// An event that occurs when the user hovers the cursor over a widget
Hover(CursorEvent),
/// An event that occurs when the user moves the cursor into a widget
MouseIn(CursorEvent),
/// An event that occurs when the user moves the cursor out of a widget
MouseOut(CursorEvent),
/// An event that occurs when the user presses down on the cursor over a widget
MouseDown(CursorEvent),
/// An event that occurs when the user releases the cursor over a widget
MouseUp(CursorEvent),
/// An event that occurs when the user presses left mouse button over a widget
MouseLeftDown(CursorEvent),
/// An event that occurs when the user releases left mouse button over a widget
MouseLeftUp(CursorEvent),
/// An event that occurs when the user presses right mouse button over a widget
MouseRightDown(CursorEvent),
/// An event that occurs when the user releases right mouse button over a widget
MouseRightUp(CursorEvent),
/// An event that occurs when the user releases middle mouse button over a widget
MouseMiddleDown(CursorEvent),
/// An event that occurs when the user releases middle mouse button over a widget
MouseMiddleUp(CursorEvent),
/// An event that occurs when the user scrolls over a widget
Scroll(ScrollEvent),
/// An event that occurs when a widget receives focus
Expand Down Expand Up @@ -172,9 +188,15 @@ impl EventType {
match self {
// Propagates
Self::Hover(..) => true,
Self::Click(..) => true,
Self::MouseDown(..) => true,
Self::MouseUp(..) => true,
Self::LeftClick(..) => true,
Self::RightClick(..) => true,
Self::MiddleClick(..) => true,
Self::MouseLeftDown(..) => true,
Self::MouseLeftUp(..) => true,
Self::MouseRightDown(..) => true,
Self::MouseRightUp(..) => true,
Self::MouseMiddleDown(..) => true,
Self::MouseMiddleUp(..) => true,
Self::Scroll(..) => true,
Self::CharInput { .. } => true,
Self::KeyUp(..) => true,
Expand All @@ -192,9 +214,15 @@ impl EventType {
match self {
// Mouse
Self::Hover(..) => EventCategory::Mouse,
Self::Click(..) => EventCategory::Mouse,
Self::MouseDown(..) => EventCategory::Mouse,
Self::MouseUp(..) => EventCategory::Mouse,
Self::LeftClick(..) => EventCategory::Mouse,
Self::RightClick(..) => EventCategory::Mouse,
Self::MiddleClick(..) => EventCategory::Mouse,
Self::MouseLeftDown(..) => EventCategory::Mouse,
Self::MouseLeftUp(..) => EventCategory::Mouse,
Self::MouseRightDown(..) => EventCategory::Mouse,
Self::MouseRightUp(..) => EventCategory::Mouse,
Self::MouseMiddleDown(..) => EventCategory::Mouse,
Self::MouseMiddleUp(..) => EventCategory::Mouse,
Self::MouseIn(..) => EventCategory::Mouse,
Self::MouseOut(..) => EventCategory::Mouse,
Self::Scroll(..) => EventCategory::Mouse,
Expand Down
Loading