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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use Scalar;
use color::{Color, BLACK, WHITE};
use position::{Align, Direction, Padding, Position, Relative};
use fnv;
use std;
use std::any::Any;
use text;
use widget;
pub type StyleMap = fnv::FnvHashMap<std::any::TypeId, WidgetDefault>;
pub struct Theme {
pub name: String,
pub padding: Padding,
pub x_position: Position,
pub y_position: Position,
pub background_color: Color,
pub shape_color: Color,
pub border_color: Color,
pub border_width: Scalar,
pub label_color: Color,
pub font_id: Option<text::font::Id>,
pub font_size_large: u32,
pub font_size_medium: u32,
pub font_size_small: u32,
pub widget_styling: StyleMap,
pub mouse_drag_threshold: Scalar,
pub double_click_threshold: std::time::Duration,
}
pub struct WidgetDefault {
pub style: Box<Any + Send>,
pub common: widget::CommonStyle,
}
#[derive(Copy, Clone, Debug)]
pub struct UniqueDefault<'a, T: 'a> {
pub style: &'a T,
pub common: &'a widget::CommonStyle,
}
impl WidgetDefault {
pub fn new(style: Box<Any + Send>) -> WidgetDefault {
WidgetDefault {
style: style,
common: widget::CommonStyle::default(),
}
}
}
impl Theme {
pub fn default() -> Theme {
Theme {
name: "Demo Theme".to_string(),
padding: Padding::none(),
x_position: Position::Relative(Relative::Align(Align::Start), None),
y_position: Position::Relative(Relative::Direction(Direction::Backwards, 20.0), None),
background_color: BLACK,
shape_color: WHITE,
border_color: BLACK,
border_width: 1.0,
label_color: BLACK,
font_id: None,
font_size_large: 26,
font_size_medium: 18,
font_size_small: 12,
widget_styling: fnv::FnvHashMap::default(),
mouse_drag_threshold: 0.0,
double_click_threshold: std::time::Duration::from_millis(500),
}
}
pub fn widget_style<T>(&self) -> Option<UniqueDefault<T>>
where T: widget::Style,
{
let style_id = std::any::TypeId::of::<T>();
self.widget_styling.get(&style_id).and_then(|boxed_default| {
boxed_default.style.downcast_ref().map(|style| {
let common = &boxed_default.common;
UniqueDefault {
style: style,
common: common,
}
})
})
}
}