[egui] make serde an optional dependency
This commit is contained in:
parent
fd5ab736bb
commit
b80baf4039
28 changed files with 126 additions and 109 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -355,7 +355,6 @@ dependencies = [
|
||||||
"parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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 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]]
|
[[package]]
|
||||||
|
@ -395,7 +394,6 @@ dependencies = [
|
||||||
"egui_glium 0.1.0",
|
"egui_glium 0.1.0",
|
||||||
"glium 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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 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)",
|
"serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -406,7 +404,6 @@ dependencies = [
|
||||||
"egui 0.1.0",
|
"egui 0.1.0",
|
||||||
"egui_wasm 0.1.0",
|
"egui_wasm 0.1.0",
|
||||||
"serde 1.0.110 (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)",
|
"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)",
|
"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"
|
name = "serde"
|
||||||
version = "1.0.110"
|
version = "1.0.110"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
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]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
|
|
|
@ -11,8 +11,10 @@ edition = "2018"
|
||||||
ahash = "0.3"
|
ahash = "0.3"
|
||||||
parking_lot = "0.10"
|
parking_lot = "0.10"
|
||||||
rusttype = "0.9"
|
rusttype = "0.9"
|
||||||
serde = "1"
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
serde_derive = "1"
|
|
||||||
|
[features]
|
||||||
|
with_serde = ["serde"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "0.3", default-features = false }
|
criterion = { version = "0.3", default-features = false }
|
||||||
|
|
|
@ -6,7 +6,8 @@ use std::{fmt::Debug, hash::Hash, sync::Arc};
|
||||||
|
|
||||||
use crate::*;
|
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) struct State {
|
||||||
/// Last known pos
|
/// Last known pos
|
||||||
pub pos: Pos2,
|
pub pos: Pos2,
|
||||||
|
@ -20,7 +21,7 @@ pub(crate) struct State {
|
||||||
|
|
||||||
/// You can throw a moveable Area. It's fun.
|
/// You can throw a moveable Area. It's fun.
|
||||||
/// TODO: separate out moveable to container?
|
/// TODO: separate out moveable to container?
|
||||||
#[serde(skip)]
|
#[cfg_attr(feature = "with_serde", serde(skip))]
|
||||||
pub vel: Vec2,
|
pub vel: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,14 @@ use crate::{
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
open: bool,
|
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,
|
toggle_time: f64,
|
||||||
|
|
||||||
/// Height of the region when open. Used for animations
|
/// Height of the region when open. Used for animations
|
||||||
|
@ -33,9 +35,9 @@ impl State {
|
||||||
.collapsing_headers
|
.collapsing_headers
|
||||||
.entry(id)
|
.entry(id)
|
||||||
.or_insert(State {
|
.or_insert(State {
|
||||||
open: default_open,
|
open: default_open,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@ use crate::{widgets::*, *};
|
||||||
|
|
||||||
use super::*;
|
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 {
|
pub struct BarState {
|
||||||
#[serde(skip)]
|
#[cfg_attr(feature = "with_serde", serde(skip))]
|
||||||
open_menu: Option<Id>,
|
open_menu: Option<Id>,
|
||||||
#[serde(skip)]
|
#[cfg_attr(feature = "with_serde", serde(skip))]
|
||||||
/// When did we open a menu?
|
/// When did we open a menu?
|
||||||
open_time: f64,
|
open_time: f64,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
use crate::*;
|
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) struct State {
|
||||||
pub(crate) size: Vec2,
|
pub(crate) size: Vec2,
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
/// Positive offset means scrolling down/right
|
/// Positive offset means scrolling down/right
|
||||||
offset: Vec2,
|
offset: Vec2,
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// #![allow(dead_code, unused_variables)] // should be commented out
|
// #![allow(dead_code, unused_variables)] // should be commented out
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{color::*, containers::*, examples::FractalClock, widgets::*, *};
|
use crate::{color::*, containers::*, examples::FractalClock, widgets::*, *};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default)]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
pub struct ExampleApp {
|
pub struct ExampleApp {
|
||||||
previous_web_location_hash: String,
|
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 {
|
struct OpenWindows {
|
||||||
// examples:
|
// examples:
|
||||||
examples: bool,
|
examples: bool,
|
||||||
|
@ -166,7 +165,7 @@ fn show_menu_bar(ui: &mut Ui, windows: &mut OpenWindows) {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Showcase some ui code
|
/// Showcase some ui code
|
||||||
#[derive(Deserialize, Serialize)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub struct ExampleWindow {
|
pub struct ExampleWindow {
|
||||||
num_columns: usize,
|
num_columns: usize,
|
||||||
|
|
||||||
|
@ -285,8 +284,8 @@ impl ExampleWindow {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
struct Widgets {
|
struct Widgets {
|
||||||
checked: bool,
|
checked: bool,
|
||||||
count: usize,
|
count: usize,
|
||||||
|
@ -365,8 +364,8 @@ impl Widgets {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
struct BoxPainting {
|
struct BoxPainting {
|
||||||
size: Vec2,
|
size: Vec2,
|
||||||
corner_radius: f32,
|
corner_radius: f32,
|
||||||
|
@ -415,8 +414,9 @@ impl BoxPainting {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default)]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
struct Painting {
|
struct Painting {
|
||||||
lines: Vec<Vec<Vec2>>,
|
lines: Vec<Vec<Vec2>>,
|
||||||
}
|
}
|
||||||
|
@ -474,8 +474,8 @@ impl Painting {
|
||||||
|
|
||||||
use crate::layout::*;
|
use crate::layout::*;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
struct LayoutExample {
|
struct LayoutExample {
|
||||||
dir: Direction,
|
dir: Direction,
|
||||||
align: Option<Align>, // None == jusitifed
|
align: Option<Align>, // None == jusitifed
|
||||||
|
@ -560,7 +560,8 @@ enum Action {
|
||||||
Delete,
|
Delete,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
#[derive(Clone, Default)]
|
||||||
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
struct Tree(Vec<Tree>);
|
struct Tree(Vec<Tree>);
|
||||||
|
|
||||||
impl Tree {
|
impl Tree {
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{containers::*, widgets::*, *};
|
use crate::{containers::*, widgets::*, *};
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
pub struct FractalClock {
|
pub struct FractalClock {
|
||||||
paused: bool,
|
paused: bool,
|
||||||
time: f64,
|
time: f64,
|
||||||
|
|
|
@ -31,9 +31,8 @@ use std::hash::Hash;
|
||||||
|
|
||||||
use crate::math::Pos2;
|
use crate::math::Pos2;
|
||||||
|
|
||||||
#[derive(
|
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
|
||||||
Clone, Copy, Debug, Hash, Eq, PartialEq, serde_derive::Deserialize, serde_derive::Serialize,
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
)]
|
|
||||||
pub struct Id(u64);
|
pub struct Id(u64);
|
||||||
|
|
||||||
impl Id {
|
impl Id {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use serde_derive::Deserialize;
|
|
||||||
|
|
||||||
use crate::{math::*, movement_tracker::MovementTracker};
|
use crate::{math::*, movement_tracker::MovementTracker};
|
||||||
|
|
||||||
/// If mouse moves more than this, it is no longer a click (but maybe a drag)
|
/// 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.
|
/// What the integration gives to the gui.
|
||||||
/// All coordinates in egui is in point/logical coordinates.
|
/// All coordinates in egui is in point/logical coordinates.
|
||||||
#[derive(Clone, Debug, Default, Deserialize)]
|
#[derive(Clone, Debug, Default)]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
pub struct RawInput {
|
pub struct RawInput {
|
||||||
/// Is the button currently down?
|
/// Is the button currently down?
|
||||||
pub mouse_down: bool,
|
pub mouse_down: bool,
|
||||||
|
@ -134,8 +133,9 @@ impl Default for MouseInput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)]
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Copy,
|
Copy,
|
||||||
Cut,
|
Cut,
|
||||||
|
@ -147,8 +147,9 @@ pub enum Event {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)]
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))]
|
||||||
pub enum Key {
|
pub enum Key {
|
||||||
Alt,
|
Alt,
|
||||||
Backspace,
|
Backspace,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use ahash::AHashMap;
|
use ahash::AHashMap;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{math::Rect, paint::PaintCmd, Id};
|
use crate::{math::Rect, paint::PaintCmd, Id};
|
||||||
|
|
||||||
/// Different layer categories
|
/// 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 {
|
pub enum Order {
|
||||||
/// Painted behind all floating windows
|
/// Painted behind all floating windows
|
||||||
Background,
|
Background,
|
||||||
|
@ -18,7 +18,8 @@ pub enum Order {
|
||||||
|
|
||||||
/// An ideintifer for a paint layer.
|
/// An ideintifer for a paint layer.
|
||||||
/// Also acts as an identifier for `Area`:s.
|
/// 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 struct Layer {
|
||||||
pub order: Order,
|
pub order: Order,
|
||||||
pub id: Id,
|
pub id: Id,
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{math::*, style::Style};
|
use crate::{math::*, style::Style};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
Horizontal,
|
Horizontal,
|
||||||
Vertical,
|
Vertical,
|
||||||
|
@ -17,8 +16,9 @@ impl Default for Direction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))]
|
||||||
pub enum Align {
|
pub enum Align {
|
||||||
/// Left/Top
|
/// Left/Top
|
||||||
Min,
|
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 {
|
pub struct Layout {
|
||||||
/// Lay out things horizontally or vertically?
|
/// Lay out things horizontally or vertically?
|
||||||
dir: Direction,
|
dir: Direction,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, RangeInclusive, Sub, SubAssign};
|
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, RangeInclusive, Sub, SubAssign};
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
#[derive(Clone, Copy, Default)]
|
||||||
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[derive(Clone, Copy, Default, Deserialize, Serialize)]
|
|
||||||
pub struct Vec2 {
|
pub struct Vec2 {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
pub y: 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
|
/// 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 struct Pos2 {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
pub y: 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 struct Rect {
|
||||||
pub min: Pos2,
|
pub min: Pos2,
|
||||||
pub max: Pos2,
|
pub max: Pos2,
|
||||||
|
|
|
@ -6,14 +6,15 @@ use crate::{
|
||||||
Id, Layer, Pos2, Rect,
|
Id, Layer, Pos2, Rect,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
#[derive(Clone, Debug, Default)]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
pub struct Memory {
|
pub struct Memory {
|
||||||
#[serde(skip)]
|
#[cfg_attr(feature = "with_serde", serde(skip))]
|
||||||
pub(crate) interaction: Interaction,
|
pub(crate) interaction: Interaction,
|
||||||
|
|
||||||
/// The widget with keyboard focus (i.e. a text input field).
|
/// 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<Id>,
|
pub(crate) kb_focus_id: Option<Id>,
|
||||||
|
|
||||||
// states of various types of widgets
|
// states of various types of widgets
|
||||||
|
@ -23,7 +24,7 @@ pub struct Memory {
|
||||||
pub(crate) scroll_areas: HashMap<Id, scroll_area::State>,
|
pub(crate) scroll_areas: HashMap<Id, scroll_area::State>,
|
||||||
pub(crate) text_edit: HashMap<Id, text_edit::State>,
|
pub(crate) text_edit: HashMap<Id, text_edit::State>,
|
||||||
|
|
||||||
#[serde(skip)]
|
#[cfg_attr(feature = "with_serde", serde(skip))]
|
||||||
pub(crate) window_interaction: Option<window::WindowInteraction>,
|
pub(crate) window_interaction: Option<window::WindowInteraction>,
|
||||||
|
|
||||||
pub(crate) areas: Areas,
|
pub(crate) areas: Areas,
|
||||||
|
@ -60,8 +61,9 @@ pub struct Interaction {
|
||||||
pub drag_interest: bool,
|
pub drag_interest: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
#[derive(Clone, Debug, Default)]
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(default))]
|
||||||
pub struct Areas {
|
pub struct Areas {
|
||||||
areas: HashMap<Id, area::State>,
|
areas: HashMap<Id, area::State>,
|
||||||
/// Top is last
|
/// Top is last
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
/// 0-255 `sRGBA`. TODO: rename `sRGBA` for clarity.
|
/// 0-255 `sRGBA`. TODO: rename `sRGBA` for clarity.
|
||||||
/// Uses premultiplied alpha.
|
/// 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 struct Color {
|
||||||
pub r: u8,
|
pub r: u8,
|
||||||
pub g: u8,
|
pub g: u8,
|
||||||
|
|
|
@ -3,8 +3,6 @@ use {
|
||||||
crate::math::{Pos2, Rect},
|
crate::math::{Pos2, Rect},
|
||||||
};
|
};
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
// TODO: rename, e.g. `paint::Cmd`?
|
// TODO: rename, e.g. `paint::Cmd`?
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum PaintCmd {
|
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 struct LineStyle {
|
||||||
pub width: f32,
|
pub width: f32,
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use {parking_lot::Mutex, serde_derive::Serialize};
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
font::Font,
|
font::Font,
|
||||||
|
@ -12,7 +12,8 @@ use super::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// TODO: rename
|
/// 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 {
|
pub enum TextStyle {
|
||||||
Body,
|
Body,
|
||||||
Button,
|
Button,
|
||||||
|
@ -20,7 +21,8 @@ pub enum TextStyle {
|
||||||
Monospace,
|
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 {
|
pub enum FontFamily {
|
||||||
Monospace,
|
Monospace,
|
||||||
VariableWidth,
|
VariableWidth,
|
||||||
|
|
|
@ -12,7 +12,8 @@ use {
|
||||||
|
|
||||||
const WHITE_UV: (u16, u16) = (1, 1);
|
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 {
|
pub struct Vertex {
|
||||||
/// Pixel coordinates
|
/// Pixel coordinates
|
||||||
pub pos: Pos2,
|
pub pos: Pos2,
|
||||||
|
@ -22,7 +23,8 @@ pub struct Vertex {
|
||||||
pub color: Color,
|
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 {
|
pub struct Triangles {
|
||||||
/// Draw as triangles (i.e. the length is a multiple of three)
|
/// Draw as triangles (i.e. the length is a multiple of three)
|
||||||
pub indices: Vec<u32>,
|
pub indices: Vec<u32>,
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#![allow(clippy::if_same_then_else)]
|
#![allow(clippy::if_same_then_else)]
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{color::*, math::*, paint::LineStyle, types::*};
|
use crate::{color::*, math::*, paint::LineStyle, types::*};
|
||||||
|
|
||||||
// TODO: split into Spacing and Style?
|
// 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 {
|
pub struct Style {
|
||||||
/// Horizontal and vertical padding within a window frame.
|
/// Horizontal and vertical padding within a window frame.
|
||||||
pub window_padding: Vec2,
|
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 struct Interact {
|
||||||
pub active: WidgetStyle,
|
pub active: WidgetStyle,
|
||||||
pub hovered: 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 {
|
pub struct WidgetStyle {
|
||||||
/// Background color of widget
|
/// Background color of widget
|
||||||
pub bg_fill: Option<Color>,
|
pub bg_fill: Option<Color>,
|
||||||
|
@ -162,7 +163,8 @@ pub struct WidgetStyle {
|
||||||
pub corner_radius: f32,
|
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 struct Window {
|
||||||
pub corner_radius: f32,
|
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 struct MenuBar {
|
||||||
pub height: f32,
|
pub height: f32,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use serde_derive::Serialize;
|
|
||||||
|
|
||||||
use crate::{math::Rect, Context, Ui};
|
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 struct Output {
|
||||||
pub cursor_icon: CursorIcon,
|
pub cursor_icon: CursorIcon,
|
||||||
|
|
||||||
|
@ -17,8 +16,9 @@ pub struct Output {
|
||||||
pub copied_text: String,
|
pub copied_text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Serialize)]
|
#[derive(Clone, Copy)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[cfg_attr(feature = "with_serde", derive(serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))]
|
||||||
pub enum CursorIcon {
|
pub enum CursorIcon {
|
||||||
Default,
|
Default,
|
||||||
/// Pointing hand, used for e.g. web links
|
/// 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 {
|
pub struct InteractInfo {
|
||||||
/// The mouse is hovering above this thing
|
/// The mouse is hovering above this thing
|
||||||
pub hovered: bool,
|
pub hovered: bool,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{paint::*, *};
|
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 {
|
pub(crate) struct State {
|
||||||
/// Charctaer based, NOT bytes.
|
/// Charctaer based, NOT bytes.
|
||||||
/// TODO: store as line + row
|
/// TODO: store as line + row
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui_glium"
|
name = "egui_glium"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { path = "../egui" }
|
egui = { path = "../egui", features = ["with_serde"] }
|
||||||
|
|
||||||
chrono = { version = "0.4" }
|
chrono = { version = "0.4" }
|
||||||
clipboard = "0.5"
|
clipboard = "0.5"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "egui_wasm"
|
name = "egui_wasm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
[package]
|
[package]
|
||||||
name = "example_glium"
|
name = "example_glium"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { path = "../egui" }
|
egui = { path = "../egui", features = ["with_serde"] }
|
||||||
egui_glium = { path = "../egui_glium" }
|
egui_glium = { path = "../egui_glium" }
|
||||||
serde = "1"
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_derive = "1"
|
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
||||||
glium = "0.24"
|
glium = "0.24"
|
||||||
|
|
|
@ -8,7 +8,7 @@ use {
|
||||||
glium::glutin,
|
glium::glutin,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
#[derive(Default, serde::Deserialize, serde::Serialize)]
|
||||||
struct Window {
|
struct Window {
|
||||||
pos: Option<Pos2>,
|
pos: Option<Pos2>,
|
||||||
size: Option<Vec2>,
|
size: Option<Vec2>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "example_wasm"
|
name = "example_wasm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"]
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ edition = "2018"
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1"
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_derive = "1"
|
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "0.2"
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ use {
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde_derive::Deserialize)]
|
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
struct WebInput {
|
struct WebInput {
|
||||||
egui: RawInput,
|
egui: RawInput,
|
||||||
web: Web,
|
web: Web,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde_derive::Deserialize)]
|
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Web {
|
pub struct Web {
|
||||||
pub location: String,
|
pub location: String,
|
||||||
|
|
Loading…
Reference in a new issue