From e8af6f38fcebcc889963e86c4a3ccebe97db1908 Mon Sep 17 00:00:00 2001 From: Georg Weisert Date: Mon, 26 Feb 2024 13:33:43 +0100 Subject: [PATCH] Serde feature: Add serde derives to input related structs (#4100) We plan to store input data for creating automated tests, hence the need for more serde derives on input related structs. --------- Co-authored-by: Georg Weisert --- crates/egui/src/input_state.rs | 4 ++++ crates/egui/src/input_state/touch_state.rs | 5 +++++ crates/emath/src/history.rs | 1 + 3 files changed, 10 insertions(+) diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index 5446a799f70..1b1417d14f8 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -22,6 +22,7 @@ const MAX_DOUBLE_CLICK_DELAY: f64 = 0.3; // TODO(emilk): move to settings /// You can check if `egui` is using the inputs using /// [`crate::Context::wants_pointer_input`] and [`crate::Context::wants_keyboard_input`]. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct InputState { /// The raw input we got this frame from the backend. pub raw: RawInput, @@ -546,6 +547,7 @@ impl InputState { /// A pointer (mouse or touch) click. #[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct Click { pub pos: Pos2, @@ -567,6 +569,7 @@ impl Click { } #[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) enum PointerEvent { Moved(Pos2), Pressed { @@ -595,6 +598,7 @@ impl PointerEvent { /// Mouse or touch state. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct PointerState { /// Latest known time time: f64, diff --git a/crates/egui/src/input_state/touch_state.rs b/crates/egui/src/input_state/touch_state.rs index a948ab16fba..2ee7a91de75 100644 --- a/crates/egui/src/input_state/touch_state.rs +++ b/crates/egui/src/input_state/touch_state.rs @@ -64,6 +64,7 @@ pub struct MultiTouchInfo { /// The current state (for a specific touch device) of touch events and gestures. #[derive(Clone)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct TouchState { /// Technical identifier of the touch device. This is used to identify relevant touch events /// for this [`TouchState`] instance. @@ -83,6 +84,7 @@ pub(crate) struct TouchState { } #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] struct GestureState { start_time: f64, start_pointer_pos: Pos2, @@ -93,6 +95,7 @@ struct GestureState { /// Gesture data that can change over time #[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] struct DynGestureState { /// used for proportional zooming avg_distance: f32, @@ -110,6 +113,7 @@ struct DynGestureState { /// Describes an individual touch (finger or digitizer) on the touch surface. Instances exist as /// long as the finger/pen touches the surface. #[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] struct ActiveTouch { /// Current position of this touch, in device coordinates (not necessarily screen position) pos: Pos2, @@ -302,6 +306,7 @@ impl Debug for TouchState { } #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] enum PinchType { Horizontal, Vertical, diff --git a/crates/emath/src/history.rs b/crates/emath/src/history.rs index bacd9625fb8..d85a27a398a 100644 --- a/crates/emath/src/history.rs +++ b/crates/emath/src/history.rs @@ -16,6 +16,7 @@ use std::collections::VecDeque; /// or for smoothed velocity (e.g. mouse pointer speed). /// All times are in seconds. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct History { /// In elements, i.e. of `values.len()`. /// The length is initially zero, but once past `min_len` will not shrink below it.