Skip to content

Commit 17e90e3

Browse files
gweiserthacknus
authored andcommitted
Serde feature: Add serde derives to input related structs (emilk#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 <georg.weisert@freshx.de>
1 parent 68d0762 commit 17e90e3

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

crates/egui/src/input_state.rs

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const MAX_DOUBLE_CLICK_DELAY: f64 = 0.3; // TODO(emilk): move to settings
2222
/// You can check if `egui` is using the inputs using
2323
/// [`crate::Context::wants_pointer_input`] and [`crate::Context::wants_keyboard_input`].
2424
#[derive(Clone, Debug)]
25+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
2526
pub struct InputState {
2627
/// The raw input we got this frame from the backend.
2728
pub raw: RawInput,
@@ -546,6 +547,7 @@ impl InputState {
546547

547548
/// A pointer (mouse or touch) click.
548549
#[derive(Clone, Debug, PartialEq)]
550+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
549551
pub(crate) struct Click {
550552
pub pos: Pos2,
551553

@@ -567,6 +569,7 @@ impl Click {
567569
}
568570

569571
#[derive(Clone, Debug, PartialEq)]
572+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
570573
pub(crate) enum PointerEvent {
571574
Moved(Pos2),
572575
Pressed {
@@ -595,6 +598,7 @@ impl PointerEvent {
595598

596599
/// Mouse or touch state.
597600
#[derive(Clone, Debug)]
601+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
598602
pub struct PointerState {
599603
/// Latest known time
600604
time: f64,

crates/egui/src/input_state/touch_state.rs

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct MultiTouchInfo {
6464

6565
/// The current state (for a specific touch device) of touch events and gestures.
6666
#[derive(Clone)]
67+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
6768
pub(crate) struct TouchState {
6869
/// Technical identifier of the touch device. This is used to identify relevant touch events
6970
/// for this [`TouchState`] instance.
@@ -83,6 +84,7 @@ pub(crate) struct TouchState {
8384
}
8485

8586
#[derive(Clone, Debug)]
87+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8688
struct GestureState {
8789
start_time: f64,
8890
start_pointer_pos: Pos2,
@@ -93,6 +95,7 @@ struct GestureState {
9395

9496
/// Gesture data that can change over time
9597
#[derive(Clone, Copy, Debug)]
98+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
9699
struct DynGestureState {
97100
/// used for proportional zooming
98101
avg_distance: f32,
@@ -110,6 +113,7 @@ struct DynGestureState {
110113
/// Describes an individual touch (finger or digitizer) on the touch surface. Instances exist as
111114
/// long as the finger/pen touches the surface.
112115
#[derive(Clone, Copy, Debug)]
116+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
113117
struct ActiveTouch {
114118
/// Current position of this touch, in device coordinates (not necessarily screen position)
115119
pos: Pos2,
@@ -302,6 +306,7 @@ impl Debug for TouchState {
302306
}
303307

304308
#[derive(Clone, Debug)]
309+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
305310
enum PinchType {
306311
Horizontal,
307312
Vertical,

crates/emath/src/history.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::collections::VecDeque;
1616
/// or for smoothed velocity (e.g. mouse pointer speed).
1717
/// All times are in seconds.
1818
#[derive(Clone, Debug)]
19+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1920
pub struct History<T> {
2021
/// In elements, i.e. of `values.len()`.
2122
/// The length is initially zero, but once past `min_len` will not shrink below it.

0 commit comments

Comments
 (0)