Skip to content

Commit

Permalink
Change all serde derives to cfg_attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
tosti007 committed Jul 24, 2023
1 parent 96e1749 commit 21ba51f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 33 deletions.
8 changes: 4 additions & 4 deletions examples/advanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() -> Result<(), eframe::Error> {
)
}

#[derive(serde::Deserialize, serde::Serialize)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Pane {
nr: usize,
}
Expand Down Expand Up @@ -156,14 +156,14 @@ impl egui_tiles::Behavior<Pane> for TreeBehavior {
}
}

#[derive(serde::Deserialize, serde::Serialize)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
struct MyApp {
tree: egui_tiles::Tree<Pane>,

#[serde(skip)]
#[cfg_attr(feature = "serde", serde(skip))]
behavior: TreeBehavior,

#[serde(skip)]
#[cfg_attr(feature = "serde", serde(skip))]
last_tree_debug: String,
}

Expand Down
22 changes: 6 additions & 16 deletions src/container/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,8 @@ use crate::{
};

/// How to lay out the children of a grid.
#[derive(
Clone,
Copy,
Debug,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
serde::Serialize,
serde::Deserialize,
)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum GridLayout {
/// Place children in a grid, with a dynamic number of columns and rows.
/// Resizing the window may change the number of columns and rows.
Expand All @@ -32,7 +21,8 @@ pub enum GridLayout {
}

/// A grid of tiles.
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Grid {
/// The order of the children, row-major.
///
Expand All @@ -50,11 +40,11 @@ pub struct Grid {
pub row_shares: Vec<f32>,

/// ui point x ranges for each column, recomputed during layout
#[serde(skip)]
#[cfg_attr(feature = "serde", serde(skip))]
col_ranges: Vec<Rangef>,

/// ui point y ranges for each row, recomputed during layout
#[serde(skip)]
#[cfg_attr(feature = "serde", serde(skip))]
row_ranges: Vec<Rangef>,
}

Expand Down
11 changes: 6 additions & 5 deletions src/container/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::{
/// Used for [`Linear`] containers (horizontal and vertical).
///
/// Also contains the shares for currently invisible tiles.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Shares {
/// How large of a share each child has.
///
Expand Down Expand Up @@ -78,17 +79,17 @@ impl std::ops::IndexMut<TileId> for Shares {
// ----------------------------------------------------------------------------

/// The direction of a [`Linear`] container. Either horizontal or vertical.
#[derive(
Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize,
)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum LinearDir {
#[default]
Horizontal,
Vertical,
}

/// Horizontal or vertical container.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Linear {
pub children: Vec<TileId>,
pub dir: LinearDir,
Expand Down
6 changes: 4 additions & 2 deletions src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub use tabs::Tabs;
/// The layout type of a [`Container`].
///
/// This is used to describe a [`Container`], and to change it to a different layout type.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum ContainerKind {
/// Each child in an individual tab.
#[default]
Expand All @@ -40,7 +41,8 @@ impl ContainerKind {
// ----------------------------------------------------------------------------

/// A container of several [`super::Tile`]s.
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum Container {
Tabs(Tabs),
Linear(Linear),
Expand Down
3 changes: 2 additions & 1 deletion src/container/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::{
};

/// A container with tabs. Only one tab is open (active) at a time.
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Tabs {
/// The tabs, in order.
pub children: Vec<TileId>,
Expand Down
6 changes: 4 additions & 2 deletions src/tile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{Container, ContainerKind};

/// An identifier for a [`Tile`] in the tree, be it a [`Container`] or a pane.
#[derive(Clone, Copy, Hash, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct TileId(u64);

impl TileId {
Expand All @@ -24,7 +25,8 @@ impl std::fmt::Debug for TileId {
// ----------------------------------------------------------------------------

/// A tile in the tree. Either a pane (leaf) or a [`Container`] of more tiles.
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum Tile<Pane> {
/// A leaf. This is where the user puts their UI, using the [`crate::Behavior`] trait.
Pane(Pane),
Expand Down
5 changes: 3 additions & 2 deletions src/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use super::{
///
/// let tree = Tree::new(root, tiles);
/// ```
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Tiles<Pane> {
next_tile_id: u64,

Expand All @@ -28,7 +29,7 @@ pub struct Tiles<Pane> {
invisible: ahash::HashSet<TileId>,

/// Filled in by the layout step at the start of each frame.
#[serde(default, skip)]
#[cfg_attr(feature = "serde", serde(default, skip))]
pub(super) rects: ahash::HashMap<TileId, Rect>,
}

Expand Down
3 changes: 2 additions & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use super::{
///
/// let tree = Tree::new(root, tiles);
/// ```
#[derive(Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Tree<Pane> {
/// None = empty tree
pub root: Option<TileId>,
Expand Down

0 comments on commit 21ba51f

Please sign in to comment.