Improve event formatting
This commit is contained in:
1 parent
6a6a028afc
commit
c090741c60
3 files changed
+17
-4
No files matched your search
@@ -36,7 +36,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
let first_index = events_lock.len().saturating_sub(MAX_EVENTS);
|
let first_index = events_lock.len().saturating_sub(MAX_EVENTS);
|
||||||
let events_rendered = events_lock[first_index..]
|
let events_rendered = events_lock[first_index..]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|event| cx.render(rsx!(div{"{event:?}"})));
|
.map(|event| cx.render(rsx!(div {"{event:?}"})));
|
||||||
|
|
||||||
let log_event = move |event: Event| {
|
let log_event = move |event: Event| {
|
||||||
events.write().push(event);
|
events.write().push(event);
|
||||||
@@ -45,7 +45,6 @@ fn app(cx: Scope) -> Element {
|
|||||||
cx.render(rsx! (
|
cx.render(rsx! (
|
||||||
div {
|
div {
|
||||||
style: "{container_style}",
|
style: "{container_style}",
|
||||||
"Hover over to display coordinates:",
|
|
||||||
div {
|
div {
|
||||||
style: "{rect_style}",
|
style: "{rect_style}",
|
||||||
onmousemove: move |event| log_event(Event::MouseMove(event.data)),
|
onmousemove: move |event| log_event(Event::MouseMove(event.data)),
|
||||||
@@ -53,9 +52,10 @@ fn app(cx: Scope) -> Element {
|
|||||||
ondblclick: move |event| log_event(Event::MouseDoubleClick(event.data)),
|
ondblclick: move |event| log_event(Event::MouseDoubleClick(event.data)),
|
||||||
onmousedown: move |event| log_event(Event::MouseDown(event.data)),
|
onmousedown: move |event| log_event(Event::MouseDown(event.data)),
|
||||||
onmouseup: move |event| log_event(Event::MouseUp(event.data)),
|
onmouseup: move |event| log_event(Event::MouseUp(event.data)),
|
||||||
|
// prevent selection
|
||||||
prevent_default: "mousedown",
|
prevent_default: "mousedown",
|
||||||
}
|
}
|
||||||
|
div { events_rendered },
|
||||||
},
|
},
|
||||||
events_rendered,
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ pub mod on {
|
|||||||
use keyboard_types::{Code, Key, Location, Modifiers};
|
use keyboard_types::{Code, Key, Location, Modifiers};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -568,7 +569,7 @@ pub mod on {
|
|||||||
|
|
||||||
pub type MouseEvent = UiEvent<MouseData>;
|
pub type MouseEvent = UiEvent<MouseData>;
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
/// Data associated with a mouse event
|
/// Data associated with a mouse event
|
||||||
///
|
///
|
||||||
/// Do not use the deprecated fields; they may change or become private in the future.
|
/// Do not use the deprecated fields; they may change or become private in the future.
|
||||||
@@ -753,6 +754,17 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for MouseData {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("MouseData")
|
||||||
|
.field("coordinates", &self.coordinates())
|
||||||
|
.field("modifiers", &self.modifiers())
|
||||||
|
.field("held_buttons", &self.held_buttons())
|
||||||
|
.field("trigger_button", &self.trigger_button())
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type PointerEvent = UiEvent<PointerData>;
|
pub type PointerEvent = UiEvent<PointerData>;
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ impl WheelDelta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Coordinates of a point in the app's interface
|
/// Coordinates of a point in the app's interface
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Coordinates {
|
pub struct Coordinates {
|
||||||
screen: ScreenPoint,
|
screen: ScreenPoint,
|
||||||
client: ClientPoint,
|
client: ClientPoint,
|
||||||
|
|||||||
Reference in new issue
Block a user