Skip to content

Commit

Permalink
Serde feature: Add serde derives to input related structs (#4100)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
gweisert and gweisert authored Feb 26, 2024
1 parent 5cf99c6 commit e8af6f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,

Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions crates/egui/src/input_state/touch_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -302,6 +306,7 @@ impl Debug for TouchState {
}

#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
enum PinchType {
Horizontal,
Vertical,
Expand Down
1 change: 1 addition & 0 deletions crates/emath/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
/// In elements, i.e. of `values.len()`.
/// The length is initially zero, but once past `min_len` will not shrink below it.
Expand Down

0 comments on commit e8af6f3

Please sign in to comment.