diff --git a/examples/demo.rs b/examples/demo.rs index 254dbe7..894feec 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -59,7 +59,7 @@ fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseState>) -> El rsx! { for (entity, name) in entities { Button { - onclick: move |event: Event<()>| { + onclick: move |event: Event| if *event.data == PointerButton::Primary { if Some(entity) == ***selected_entity { selected_entity.set(None); } else { @@ -79,7 +79,7 @@ fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseState>) -> El } } Button { - onclick: move |event: Event<()>| { + onclick: move |event: Event| if *event.data == PointerButton::Primary { spawn_entity(); event.stop_propagation(); }, @@ -148,8 +148,8 @@ fn Button<'a>(cx: Scope<'a, ButtonProps<'a>>) -> Element<'a> { render! { node { onclick: move |event| cx.props.onclick.call(event), - onclick_down: |_| clicked.set(true), - onclick_up: |_| clicked.set(false), + onclick_down: |event| if *event.data == PointerButton::Primary { clicked.set(true) }, + onclick_up: |event| if *event.data == PointerButton::Primary { clicked.set(false) }, onmouse_enter: |_| hovered.set(true), onmouse_exit: |_| { hovered.set(false); clicked.set(false) }, padding: "8", @@ -161,7 +161,7 @@ fn Button<'a>(cx: Scope<'a, ButtonProps<'a>>) -> Element<'a> { #[derive(Props)] struct ButtonProps<'a> { - onclick: EventHandler<'a, Event<()>>, + onclick: EventHandler<'a, Event>, base_color: Option<&'a str>, click_color: Option<&'a str>, hover_color: Option<&'a str>, diff --git a/src/events.rs b/src/events.rs index c05148c..1c83915 100644 --- a/src/events.rs +++ b/src/events.rs @@ -17,16 +17,22 @@ use std::{any::Any, mem, rc::Rc}; // TODO: Other events pub mod events { + use bevy_mod_picking::pointer::PointerButton; + super::impl_event! [ (); - onclick - onclick_down - onclick_up onmouse_over onmouse_out onmouse_enter onmouse_exit ]; + + super::impl_event! [ + PointerButton; + onclick + onclick_down + onclick_up + ]; } #[derive(Resource, Default)] @@ -53,13 +59,13 @@ impl EventReaders { ) -> Vec<(Entity, &'static str, Rc, bool)> { let mut events: Vec<(Entity, &'static str, Rc, bool)> = Vec::new(); for event in self.click.read(click) { - events.push((event.target, "click", Rc::new(()), true)); + events.push((event.target, "click", Rc::new(event.button), true)); } for event in self.click_down.read(click_down) { - events.push((event.target, "click_down", Rc::new(()), true)); + events.push((event.target, "click_down", Rc::new(event.button), true)); } for event in self.click_up.read(click_up) { - events.push((event.target, "click_up", Rc::new(()), true)); + events.push((event.target, "click_up", Rc::new(event.button), true)); } for event in self.mouse_over.read(mouse_over) { events.push((event.target, "mouse_over", Rc::new(()), false)); diff --git a/src/lib.rs b/src/lib.rs index 28a764e..2a4780a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,6 +30,7 @@ pub mod prelude { pub use super::ecs_hooks::*; pub use super::elements::*; pub use super::{DioxusUiBundle, DioxusUiPlugin, DioxusUiRoot}; + pub use bevy_mod_picking::pointer::PointerButton; pub use dioxus; pub use dioxus::prelude::*; }