[egui] Derive Serialize/Deserialize for a bunch of things

This commit is contained in:
Emil Ernerfeldt 2021-01-02 20:32:05 +01:00
parent 83b75b117e
commit fffa5e7795
5 changed files with 11 additions and 2 deletions

View file

@ -23,7 +23,7 @@ ahash = { version = "0.6", features = ["std"], default-features = false }
atomic_refcell = { version = "0.1", optional = true } # Used instead of parking_lot when you are always using Egui in a single thread. About as fast as parking_lot. Panics on multi-threaded use of egui::Context.
parking_lot = { version = "0.11", optional = true } # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios
rusttype = "0.9"
serde = { version = "1", features = ["derive"], optional = true }
serde = { version = "1", features = ["derive", "rc"], optional = true }
[features]
default = ["atomic_refcell", "default_fonts"]

View file

@ -15,6 +15,8 @@ use crate::{
// ----------------------------------------------------------------------------
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
struct Options {
/// The default style for new `Ui`:s.
style: Arc<Style>,

View file

@ -45,7 +45,8 @@ impl TextStyle {
/// Which style of font: [`Monospace`][`FontFamily::Monospace`] or [`Proportional`][`FontFamily::Proportional`].
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
// #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum FontFamily {
/// A font where each character is the same width (`w` is the same width as `i`).
Monospace,
@ -80,12 +81,15 @@ fn rusttype_font_from_font_data(name: &str, data: &FontData) -> rusttype::Font<'
/// ctx.set_fonts(fonts);
/// ```
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct FontDefinitions {
/// List of font names and their definitions.
/// The definition must be the contents of either a `.ttf` or `.otf` font file.
///
/// Egui has built-in-default for these,
/// but you can override them if you like.
#[cfg_attr(feature = "serde", serde(skip))]
pub font_data: BTreeMap<String, FontData>,
/// Which fonts (names) to use for each [`FontFamily`].

View file

@ -446,6 +446,8 @@ use self::PathType::{Closed, Open};
/// Tessellation quality options
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct TessellationOptions {
/// Size of a pixel in points, e.g. 0.5
pub aa_size: f32,

View file

@ -10,6 +10,7 @@ use crate::{
/// Specifies the look and feel of a [`Ui`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct Style {
/// Default `TextStyle` for normal text (i.e. for `Label` and `TextEdit`).
pub body_text_style: TextStyle,