Improve event formatting

This commit is contained in:
Reinis Mazeiks committed 2022-06-28 23:46:24 +03:00
1 parent 6a6a028afc
commit c090741c60
3 files changed
+17 -4

No files matched your search

+3 -3
View File
@@ -36,7 +36,7 @@ fn app(cx: Scope) -> Element {
let first_index = events_lock.len().saturating_sub(MAX_EVENTS);
let events_rendered = events_lock[first_index..]
.iter()
.map(|event| cx.render(rsx!(div{"{event:?}"})));
.map(|event| cx.render(rsx!(div {"{event:?}"})));
let log_event = move |event: Event| {
events.write().push(event);
@@ -45,7 +45,6 @@ fn app(cx: Scope) -> Element {
cx.render(rsx! (
div {
style: "{container_style}",
"Hover over to display coordinates:",
div {
style: "{rect_style}",
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)),
onmousedown: move |event| log_event(Event::MouseDown(event.data)),
onmouseup: move |event| log_event(Event::MouseUp(event.data)),
// prevent selection
prevent_default: "mousedown",
}
div { events_rendered },
},
events_rendered,
))
}
+13 -1
View File
@@ -17,6 +17,7 @@ pub mod on {
use keyboard_types::{Code, Key, Location, Modifiers};
use std::collections::HashMap;
use std::convert::TryInto;
use std::fmt::{Debug, Formatter};
use std::str::FromStr;
use super::*;
@@ -568,7 +569,7 @@ pub mod on {
pub type MouseEvent = UiEvent<MouseData>;
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)]
#[derive(Clone)]
/// Data associated with a mouse event
///
/// 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>;
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)]
+1
View File
@@ -96,6 +96,7 @@ impl WheelDelta {
}
/// Coordinates of a point in the app's interface
#[derive(Debug)]
pub struct Coordinates {
screen: ScreenPoint,
client: ClientPoint,