diff --git a/Cargo.lock b/Cargo.lock index 826e5440e..7b5cf3b77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,7 +355,6 @@ dependencies = [ "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "rusttype 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -395,7 +394,6 @@ dependencies = [ "egui_glium 0.1.0", "glium 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -406,7 +404,6 @@ dependencies = [ "egui 0.1.0", "egui_wasm 0.1.0", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -990,6 +987,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "serde" version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "serde_derive" diff --git a/egui/Cargo.toml b/egui/Cargo.toml index 2f6d810d0..8b75c1da4 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -11,8 +11,10 @@ edition = "2018" ahash = "0.3" parking_lot = "0.10" rusttype = "0.9" -serde = "1" -serde_derive = "1" +serde = { version = "1", features = ["derive"], optional = true } + +[features] +with_serde = ["serde"] [dev-dependencies] criterion = { version = "0.3", default-features = false } diff --git a/egui/src/containers/area.rs b/egui/src/containers/area.rs index 2bf2b4d08..63b485a0a 100644 --- a/egui/src/containers/area.rs +++ b/egui/src/containers/area.rs @@ -6,7 +6,8 @@ use std::{fmt::Debug, hash::Hash, sync::Arc}; use crate::*; -#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct State { /// Last known pos pub pos: Pos2, @@ -20,7 +21,7 @@ pub(crate) struct State { /// You can throw a moveable Area. It's fun. /// TODO: separate out moveable to container? - #[serde(skip)] + #[cfg_attr(feature = "with_serde", serde(skip))] pub vel: Vec2, } diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index 71388cec5..e027cc8d9 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -5,12 +5,14 @@ use crate::{ *, }; -#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)] -#[serde(default)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] pub(crate) struct State { open: bool, - #[serde(skip)] // Times are relative, and we don't want to continue animations anyway + // Times are relative, and we don't want to continue animations anyway, hence `serde(skip)` + #[cfg_attr(feature = "with_serde", serde(skip))] toggle_time: f64, /// Height of the region when open. Used for animations @@ -33,9 +35,9 @@ impl State { .collapsing_headers .entry(id) .or_insert(State { - open: default_open, - ..Default::default() - }) + open: default_open, + ..Default::default() + }) .clone() } diff --git a/egui/src/containers/menu.rs b/egui/src/containers/menu.rs index 466ed4816..39ae4c4ed 100644 --- a/egui/src/containers/menu.rs +++ b/egui/src/containers/menu.rs @@ -2,11 +2,12 @@ use crate::{widgets::*, *}; use super::*; -#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct BarState { - #[serde(skip)] + #[cfg_attr(feature = "with_serde", serde(skip))] open_menu: Option, - #[serde(skip)] + #[cfg_attr(feature = "with_serde", serde(skip))] /// When did we open a menu? open_time: f64, } diff --git a/egui/src/containers/resize.rs b/egui/src/containers/resize.rs index 9ee6cd75d..5f0e1a4bb 100644 --- a/egui/src/containers/resize.rs +++ b/egui/src/containers/resize.rs @@ -2,7 +2,8 @@ use crate::*; -#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct State { pub(crate) size: Vec2, diff --git a/egui/src/containers/scroll_area.rs b/egui/src/containers/scroll_area.rs index 0d82f3708..20866c18c 100644 --- a/egui/src/containers/scroll_area.rs +++ b/egui/src/containers/scroll_area.rs @@ -1,7 +1,8 @@ use crate::*; -#[derive(Clone, Copy, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)] -#[serde(default)] +#[derive(Clone, Copy, Debug, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] pub(crate) struct State { /// Positive offset means scrolling down/right offset: Vec2, diff --git a/egui/src/examples/app.rs b/egui/src/examples/app.rs index 2a55ebebc..8b6b441d7 100644 --- a/egui/src/examples/app.rs +++ b/egui/src/examples/app.rs @@ -1,14 +1,13 @@ // #![allow(dead_code, unused_variables)] // should be commented out use std::sync::Arc; -use serde_derive::{Deserialize, Serialize}; - use crate::{color::*, containers::*, examples::FractalClock, widgets::*, *}; // ---------------------------------------------------------------------------- -#[derive(Default, Deserialize, Serialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] pub struct ExampleApp { previous_web_location_hash: String, @@ -87,7 +86,7 @@ impl ExampleApp { // ---------------------------------------------------------------------------- -#[derive(Deserialize, Serialize)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] struct OpenWindows { // examples: examples: bool, @@ -166,7 +165,7 @@ fn show_menu_bar(ui: &mut Ui, windows: &mut OpenWindows) { // ---------------------------------------------------------------------------- /// Showcase some ui code -#[derive(Deserialize, Serialize)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct ExampleWindow { num_columns: usize, @@ -285,8 +284,8 @@ impl ExampleWindow { // ---------------------------------------------------------------------------- -#[derive(Deserialize, Serialize)] -#[serde(default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] struct Widgets { checked: bool, count: usize, @@ -365,8 +364,8 @@ impl Widgets { // ---------------------------------------------------------------------------- -#[derive(Deserialize, Serialize)] -#[serde(default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] struct BoxPainting { size: Vec2, corner_radius: f32, @@ -415,8 +414,9 @@ impl BoxPainting { // ---------------------------------------------------------------------------- -#[derive(Default, Deserialize, Serialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] struct Painting { lines: Vec>, } @@ -474,8 +474,8 @@ impl Painting { use crate::layout::*; -#[derive(Deserialize, Serialize)] -#[serde(default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] struct LayoutExample { dir: Direction, align: Option, // None == jusitifed @@ -560,7 +560,8 @@ enum Action { Delete, } -#[derive(Clone, Default, Deserialize, Serialize)] +#[derive(Clone, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] struct Tree(Vec); impl Tree { diff --git a/egui/src/examples/fractal_clock.rs b/egui/src/examples/fractal_clock.rs index 6b5a5b52d..5df119567 100644 --- a/egui/src/examples/fractal_clock.rs +++ b/egui/src/examples/fractal_clock.rs @@ -1,11 +1,9 @@ use std::sync::Arc; -use serde_derive::{Deserialize, Serialize}; - use crate::{containers::*, widgets::*, *}; -#[derive(Deserialize, Serialize)] -#[serde(default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] pub struct FractalClock { paused: bool, time: f64, diff --git a/egui/src/id.rs b/egui/src/id.rs index 7f4c26a0e..93e1c4363 100644 --- a/egui/src/id.rs +++ b/egui/src/id.rs @@ -31,9 +31,8 @@ use std::hash::Hash; use crate::math::Pos2; -#[derive( - Clone, Copy, Debug, Hash, Eq, PartialEq, serde_derive::Deserialize, serde_derive::Serialize, -)] +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Id(u64); impl Id { diff --git a/egui/src/input.rs b/egui/src/input.rs index b5df6629b..1a3a28218 100644 --- a/egui/src/input.rs +++ b/egui/src/input.rs @@ -1,5 +1,3 @@ -use serde_derive::Deserialize; - use crate::{math::*, movement_tracker::MovementTracker}; /// If mouse moves more than this, it is no longer a click (but maybe a drag) @@ -9,8 +7,9 @@ const MAX_CLICK_DELAY: f64 = 0.3; /// What the integration gives to the gui. /// All coordinates in egui is in point/logical coordinates. -#[derive(Clone, Debug, Default, Deserialize)] -#[serde(default)] +#[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "with_serde", serde(default))] pub struct RawInput { /// Is the button currently down? pub mouse_down: bool, @@ -134,8 +133,9 @@ impl Default for MouseInput { } } -#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)] -#[serde(rename_all = "snake_case")] +#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum Event { Copy, Cut, @@ -147,8 +147,9 @@ pub enum Event { }, } -#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)] -#[serde(rename_all = "snake_case")] +#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum Key { Alt, Backspace, diff --git a/egui/src/layers.rs b/egui/src/layers.rs index 1324f1b7b..b3aa37c29 100644 --- a/egui/src/layers.rs +++ b/egui/src/layers.rs @@ -1,10 +1,10 @@ use ahash::AHashMap; -use serde_derive::{Deserialize, Serialize}; use crate::{math::Rect, paint::PaintCmd, Id}; /// Different layer categories -#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub enum Order { /// Painted behind all floating windows Background, @@ -18,7 +18,8 @@ pub enum Order { /// An ideintifer for a paint layer. /// Also acts as an identifier for `Area`:s. -#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Layer { pub order: Order, pub id: Id, diff --git a/egui/src/layout.rs b/egui/src/layout.rs index 76befccb3..1c7191914 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -1,11 +1,10 @@ -use serde_derive::{Deserialize, Serialize}; - use crate::{math::*, style::Style}; // ---------------------------------------------------------------------------- -#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] +#[derive(Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] + pub enum Direction { Horizontal, Vertical, @@ -17,8 +16,9 @@ impl Default for Direction { } } -#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] +#[derive(Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum Align { /// Left/Top Min, @@ -55,7 +55,8 @@ pub fn align_rect(rect: Rect, align: (Align, Align)) -> Rect { // ---------------------------------------------------------------------------- -#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Layout { /// Lay out things horizontally or vertically? dir: Direction, diff --git a/egui/src/math.rs b/egui/src/math.rs index f8f318c7d..8a6e744c3 100644 --- a/egui/src/math.rs +++ b/egui/src/math.rs @@ -1,8 +1,7 @@ use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, RangeInclusive, Sub, SubAssign}; -use serde_derive::{Deserialize, Serialize}; - -#[derive(Clone, Copy, Default, Deserialize, Serialize)] +#[derive(Clone, Copy, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Vec2 { pub x: f32, pub y: f32, @@ -212,7 +211,8 @@ impl std::fmt::Debug for Vec2 { // ---------------------------------------------------------------------------- /// Sometimes called a Point. I prefer the shorter Pos2 so it is equal length to Vec2 -#[derive(Clone, Copy, Default, Deserialize, Serialize)] +#[derive(Clone, Copy, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Pos2 { pub x: f32, pub y: f32, @@ -337,7 +337,8 @@ impl std::fmt::Debug for Pos2 { // ---------------------------------------------------------------------------- -#[derive(Clone, Copy, Default, Eq, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Copy, Default, Eq, PartialEq)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Rect { pub min: Pos2, pub max: Pos2, diff --git a/egui/src/memory.rs b/egui/src/memory.rs index bf1862883..df6470983 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -6,14 +6,15 @@ use crate::{ Id, Layer, Pos2, Rect, }; -#[derive(Clone, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)] -#[serde(default)] +#[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] pub struct Memory { - #[serde(skip)] + #[cfg_attr(feature = "with_serde", serde(skip))] pub(crate) interaction: Interaction, /// The widget with keyboard focus (i.e. a text input field). - #[serde(skip)] + #[cfg_attr(feature = "with_serde", serde(skip))] pub(crate) kb_focus_id: Option, // states of various types of widgets @@ -23,7 +24,7 @@ pub struct Memory { pub(crate) scroll_areas: HashMap, pub(crate) text_edit: HashMap, - #[serde(skip)] + #[cfg_attr(feature = "with_serde", serde(skip))] pub(crate) window_interaction: Option, pub(crate) areas: Areas, @@ -60,8 +61,9 @@ pub struct Interaction { pub drag_interest: bool, } -#[derive(Clone, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)] -#[serde(default)] +#[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(default))] pub struct Areas { areas: HashMap, /// Top is last diff --git a/egui/src/paint/color.rs b/egui/src/paint/color.rs index 5b97eef36..0661f00e4 100644 --- a/egui/src/paint/color.rs +++ b/egui/src/paint/color.rs @@ -1,8 +1,7 @@ -use serde_derive::{Deserialize, Serialize}; - /// 0-255 `sRGBA`. TODO: rename `sRGBA` for clarity. /// Uses premultiplied alpha. -#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Color { pub r: u8, pub g: u8, diff --git a/egui/src/paint/command.rs b/egui/src/paint/command.rs index 8dc3bfa43..9a5d5490a 100644 --- a/egui/src/paint/command.rs +++ b/egui/src/paint/command.rs @@ -3,8 +3,6 @@ use { crate::math::{Pos2, Rect}, }; -use serde_derive::{Deserialize, Serialize}; - // TODO: rename, e.g. `paint::Cmd`? #[derive(Clone, Debug)] pub enum PaintCmd { @@ -50,7 +48,8 @@ impl PaintCmd { } } -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct LineStyle { pub width: f32, pub color: Color, diff --git a/egui/src/paint/fonts.rs b/egui/src/paint/fonts.rs index f6e0e705d..7115045bc 100644 --- a/egui/src/paint/fonts.rs +++ b/egui/src/paint/fonts.rs @@ -4,7 +4,7 @@ use std::{ sync::Arc, }; -use {parking_lot::Mutex, serde_derive::Serialize}; +use parking_lot::Mutex; use super::{ font::Font, @@ -12,7 +12,8 @@ use super::{ }; /// TODO: rename -#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub enum TextStyle { Body, Button, @@ -20,7 +21,8 @@ pub enum TextStyle { Monospace, } -#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub enum FontFamily { Monospace, VariableWidth, diff --git a/egui/src/paint/mesher.rs b/egui/src/paint/mesher.rs index d49368cb6..dce13e2e7 100644 --- a/egui/src/paint/mesher.rs +++ b/egui/src/paint/mesher.rs @@ -12,7 +12,8 @@ use { const WHITE_UV: (u16, u16) = (1, 1); -#[derive(Clone, Copy, Debug, Default, serde_derive::Serialize)] +#[derive(Clone, Copy, Debug, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Vertex { /// Pixel coordinates pub pos: Pos2, @@ -22,7 +23,8 @@ pub struct Vertex { pub color: Color, } -#[derive(Clone, Debug, Default, serde_derive::Serialize)] +#[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Triangles { /// Draw as triangles (i.e. the length is a multiple of three) pub indices: Vec, diff --git a/egui/src/style.rs b/egui/src/style.rs index 42fae5df5..134ad0dc9 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -1,11 +1,10 @@ #![allow(clippy::if_same_then_else)] -use serde_derive::{Deserialize, Serialize}; - use crate::{color::*, math::*, paint::LineStyle, types::*}; // TODO: split into Spacing and Style? -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Style { /// Horizontal and vertical padding within a window frame. pub window_padding: Vec2, @@ -89,7 +88,8 @@ impl Default for Style { } } -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Interact { pub active: WidgetStyle, pub hovered: WidgetStyle, @@ -139,7 +139,8 @@ impl Interact { } } -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct WidgetStyle { /// Background color of widget pub bg_fill: Option, @@ -162,7 +163,8 @@ pub struct WidgetStyle { pub corner_radius: f32, } -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Window { pub corner_radius: f32, } @@ -175,7 +177,8 @@ impl Default for Window { } } -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct MenuBar { pub height: f32, } diff --git a/egui/src/types.rs b/egui/src/types.rs index 1cc971e4d..0acbb66b6 100644 --- a/egui/src/types.rs +++ b/egui/src/types.rs @@ -1,12 +1,11 @@ use std::sync::Arc; -use serde_derive::Serialize; - use crate::{math::Rect, Context, Ui}; // ---------------------------------------------------------------------------- -#[derive(Clone, Default, Serialize)] +#[derive(Clone, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Serialize))] pub struct Output { pub cursor_icon: CursorIcon, @@ -17,8 +16,9 @@ pub struct Output { pub copied_text: String, } -#[derive(Clone, Copy, Serialize)] -#[serde(rename_all = "snake_case")] +#[derive(Clone, Copy)] +#[cfg_attr(feature = "with_serde", derive(serde::Serialize))] +#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum CursorIcon { Default, /// Pointing hand, used for e.g. web links @@ -38,7 +38,8 @@ impl Default for CursorIcon { // ---------------------------------------------------------------------------- -#[derive(Clone, Copy, Debug, Serialize)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "with_serde", derive(serde::Serialize))] pub struct InteractInfo { /// The mouse is hovering above this thing pub hovered: bool, diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 7956ca0e8..d0228fa00 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -1,6 +1,7 @@ use crate::{paint::*, *}; -#[derive(Clone, Copy, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Clone, Copy, Debug, Default)] +#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct State { /// Charctaer based, NOT bytes. /// TODO: store as line + row diff --git a/egui_glium/Cargo.toml b/egui_glium/Cargo.toml index 059d77fa4..298e75e27 100644 --- a/egui_glium/Cargo.toml +++ b/egui_glium/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "egui_glium" version = "0.1.0" -authors = ["Emil Ernerfeldt "] +authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2018" [dependencies] -egui = { path = "../egui" } +egui = { path = "../egui", features = ["with_serde"] } chrono = { version = "0.4" } clipboard = "0.5" diff --git a/egui_wasm/Cargo.toml b/egui_wasm/Cargo.toml index c4c8ade1e..7910dcd20 100644 --- a/egui_wasm/Cargo.toml +++ b/egui_wasm/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "egui_wasm" version = "0.1.0" -authors = ["Emil Ernerfeldt "] +authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2018" diff --git a/example_glium/Cargo.toml b/example_glium/Cargo.toml index cd95146b3..5d89a2759 100644 --- a/example_glium/Cargo.toml +++ b/example_glium/Cargo.toml @@ -1,15 +1,14 @@ [package] name = "example_glium" version = "0.1.0" -authors = ["Emil Ernerfeldt "] +authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2018" [dependencies] -egui = { path = "../egui" } +egui = { path = "../egui", features = ["with_serde"] } egui_glium = { path = "../egui_glium" } -serde = "1" -serde_derive = "1" +serde = { version = "1", features = ["derive"] } serde_json = "1" glium = "0.24" diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index cb08fede5..02d80cf22 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -8,7 +8,7 @@ use { glium::glutin, }; -#[derive(Default, serde_derive::Deserialize, serde_derive::Serialize)] +#[derive(Default, serde::Deserialize, serde::Serialize)] struct Window { pos: Option, size: Option, diff --git a/example_wasm/Cargo.toml b/example_wasm/Cargo.toml index fba4b21bb..21899d9ed 100644 --- a/example_wasm/Cargo.toml +++ b/example_wasm/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "example_wasm" version = "0.1.0" -authors = ["Emil Ernerfeldt "] +authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2018" @@ -9,8 +9,7 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -serde = "1" -serde_derive = "1" +serde = { version = "1", features = ["derive"] } serde_json = "1" wasm-bindgen = "0.2" diff --git a/example_wasm/src/lib.rs b/example_wasm/src/lib.rs index ed171e76d..2ac86e187 100644 --- a/example_wasm/src/lib.rs +++ b/example_wasm/src/lib.rs @@ -13,14 +13,14 @@ use { use wasm_bindgen::prelude::*; -#[derive(Clone, Debug, Default, serde_derive::Deserialize)] +#[derive(Clone, Debug, Default, serde::Deserialize)] #[serde(default)] struct WebInput { egui: RawInput, web: Web, } -#[derive(Clone, Debug, Default, serde_derive::Deserialize)] +#[derive(Clone, Debug, Default, serde::Deserialize)] #[serde(default)] pub struct Web { pub location: String,