1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use egui::{FontDefinitions, Style};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
mod fonts;
mod style;
type ThemeValue = serde_json::Value;
#[derive(Serialize, Deserialize)]
pub struct EguiTheme {
pub(crate) egui_theme_version: String,
pub(crate) egui_version: String,
pub(crate) style: HashMap<String, ThemeValue>,
pub(crate) fonts: HashMap<String, ThemeValue>,
}
impl EguiTheme {
pub fn new(style: Style, font_definitions: FontDefinitions) -> Self {
let style = style::from_style(style);
let fonts = fonts::from_fonts(font_definitions);
Self {
egui_theme_version: crate::EGUI_THEME_VERSION.to_owned(),
egui_version: crate::EGUI_VERSION.to_owned(),
style,
fonts,
}
}
pub fn extract(self) -> (Style, FontDefinitions) {
let EguiTheme { style, fonts, .. } = self;
let style = style::to_style(style);
let fonts = fonts::to_fonts(fonts);
(style, fonts)
}
pub fn load_into_context(self, context: &mut egui::Context) {
let (style, fonts) = self.extract();
context.set_style(style);
context.set_fonts(fonts);
}
}