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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
use egui::{ecolor::*, Margin, Rounding, Stroke};
/// Left or right alignment for tab add button.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[allow(missing_docs)]
pub enum TabAddAlign {
Left,
Right,
}
/// Specifies the look and feel of egui_dock.
#[derive(Clone, Debug)]
#[allow(missing_docs)]
pub struct Style {
/// Sets padding to indent from the edges of the window. By `Default` it's `None`.
pub dock_area_padding: Option<Margin>,
/// Sets selection color for the placing area of the tab where this tab targeted on it.
/// By `Default` it's `(0, 191, 255)` (light blue) with `0.5` capacity.
pub selection_color: Color32,
pub border: Stroke,
pub buttons: ButtonsStyle,
pub separator: SeparatorStyle,
pub tab_bar: TabBarStyle,
pub tabs: TabStyle,
}
/// Specifies the look and feel of buttons.
#[derive(Clone, Debug)]
pub struct ButtonsStyle {
/// Color of the close tab button.
pub close_tab_color: Color32,
/// Color of the active close tab button.
pub close_tab_active_color: Color32,
/// Color of the background close tab button.
pub close_tab_bg_fill: Color32,
/// Left or right aligning of the add tab button.
pub add_tab_align: TabAddAlign,
/// Color of the add tab button.
pub add_tab_color: Color32,
/// Color of the active add tab button.
pub add_tab_active_color: Color32,
/// Color of the add tab button's background.
pub add_tab_bg_fill: Color32,
/// Color of the add tab button's left border.
pub add_tab_border_color: Color32,
}
/// Specifies the look and feel of node separators.
#[derive(Clone, Debug)]
pub struct SeparatorStyle {
/// Width of the rectangle separator between nodes. By `Default` it's `1.0`.
pub width: f32,
/// Extra width added to the "logical thickness" of the rectangle so it's
/// easier to grab. By `Default` it's `4.0`.
pub extra_interact_width: f32,
/// Limit for the allowed area for the separator offset. By `Default` it's `175.0`.
/// `bigger value > less allowed offset` for the current window size.
pub extra: f32,
/// Idle color of the rectangle separator. By `Default` it's [`Color32::BLACK`].
pub color_idle: Color32,
/// Hovered color of the rectangle separator. By `Default` it's [`Color32::GRAY`].
pub color_hovered: Color32,
/// Dragged color of the rectangle separator. By `Default` it's [`Color32::WHITE`].
pub color_dragged: Color32,
}
/// Specifies the look and feel of tab bars.
#[derive(Clone, Debug)]
pub struct TabBarStyle {
/// Background color of tab bar. By `Default` it's [`Color32::WHITE`].
pub bg_fill: Color32,
/// Height of the tab bar. By `Default` it's `24.0`.
pub height: f32,
/// Show a scroll bar when tab bar overflows. By `Default` it's `true`.
pub show_scroll_bar_on_overflow: bool,
/// Tab rounding. By `Default` it's [`Rounding::default`]
pub rounding: Rounding,
/// Color of th line separating the tab name area from the tab content area.
/// By `Default` it's [`Color32::BLACK`].
pub hline_color: Color32,
}
/// Specifies the look and feel of individual tabs.
#[derive(Clone, Debug)]
pub struct TabStyle {
/// Inner margin of tab body. By `Default` it's `Margin::same(4.0)`
pub inner_margin: Margin,
/// Color of the outline around tabs. By `Default` it's [`Color32::BLACK`].
pub outline_color: Color32,
/// Tab rounding. By `Default` it's [`Rounding::default`]
pub rounding: Rounding,
/// Colour of the tab's background. By `Default` it's [`Color32::WHITE`]
pub bg_fill: Color32,
/// Color of tab title when an inactive tab is unfocused.
pub text_color_unfocused: Color32,
/// Color of tab title when an inactive tab is focused.
pub text_color_focused: Color32,
/// Color of tab title when an active tab is unfocused.
pub text_color_active_unfocused: Color32,
/// Color of tab title when an active tab is focused.
pub text_color_active_focused: Color32,
/// If `true`, show the hline below the active tabs name.
/// If `false`, show the active tab as merged with the tab ui area.
/// By `Default` it's `false`.
pub hline_below_active_tab_name: bool,
/// Whether tab titles expand to fill the width of their tab bars.
pub fill_tab_bar: bool,
}
impl Default for Style {
fn default() -> Self {
Self {
dock_area_padding: None,
border: Stroke::new(f32::default(), Color32::BLACK),
selection_color: Color32::from_rgb(0, 191, 255).linear_multiply(0.5),
buttons: ButtonsStyle::default(),
separator: SeparatorStyle::default(),
tab_bar: TabBarStyle::default(),
tabs: TabStyle::default(),
}
}
}
impl Default for ButtonsStyle {
fn default() -> Self {
Self {
close_tab_color: Color32::WHITE,
close_tab_active_color: Color32::WHITE,
close_tab_bg_fill: Color32::GRAY,
add_tab_align: TabAddAlign::Right,
add_tab_color: Color32::WHITE,
add_tab_active_color: Color32::WHITE,
add_tab_bg_fill: Color32::GRAY,
add_tab_border_color: Color32::BLACK,
}
}
}
impl Default for SeparatorStyle {
fn default() -> Self {
Self {
width: 1.0,
extra_interact_width: 2.0,
extra: 175.0,
color_idle: Color32::BLACK,
color_hovered: Color32::GRAY,
color_dragged: Color32::WHITE,
}
}
}
impl Default for TabBarStyle {
fn default() -> Self {
Self {
bg_fill: Color32::WHITE,
height: 24.0,
show_scroll_bar_on_overflow: true,
rounding: Rounding::default(),
hline_color: Color32::BLACK,
}
}
}
impl Default for TabStyle {
fn default() -> Self {
Self {
inner_margin: Margin::same(4.0),
bg_fill: Color32::WHITE,
fill_tab_bar: false,
hline_below_active_tab_name: false,
outline_color: Color32::BLACK,
rounding: Rounding::default(),
text_color_unfocused: Color32::DARK_GRAY,
text_color_focused: Color32::BLACK,
text_color_active_unfocused: Color32::DARK_GRAY,
text_color_active_focused: Color32::BLACK,
}
}
}
impl Style {
pub(crate) const TAB_ADD_BUTTON_SIZE: f32 = 24.0;
pub(crate) const TAB_ADD_PLUS_SIZE: f32 = 12.0;
pub(crate) const TAB_CLOSE_BUTTON_SIZE: f32 = 24.0;
pub(crate) const TAB_CLOSE_X_SIZE: f32 = 9.0;
}
impl Style {
/// Derives relevant fields from `egui::Style` and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`Style::border`]
/// - [`Style::selection_color`]
///
/// See also: [`ButtonsStyle::from_egui`], [`SeparatorStyle::from_egui`], [`TabBarStyle::from_egui`],
/// [`TabStyle::from_egui`]
pub fn from_egui(style: &egui::Style) -> Self {
Self {
border: Stroke {
color: style.visuals.widgets.active.bg_fill,
..Stroke::default()
},
selection_color: style.visuals.selection.bg_fill.linear_multiply(0.5),
buttons: ButtonsStyle::from_egui(style),
separator: SeparatorStyle::from_egui(style),
tab_bar: TabBarStyle::from_egui(style),
tabs: TabStyle::from_egui(style),
..Self::default()
}
}
}
impl ButtonsStyle {
/// Derives relevant fields from `egui::Style` and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`ButtonsStyle::close_tab_bg_fill`]
/// - [`ButtonsStyle::close_tab_color`]
/// - [`ButtonsStyle::close_tab_active_color`]
/// - [`ButtonsStyle::add_tab_bg_fill`]
/// - [`ButtonsStyle::add_tab_color`]
/// - [`ButtonsStyle::add_tab_active_color`]
pub fn from_egui(style: &egui::Style) -> Self {
Self {
close_tab_bg_fill: style.visuals.widgets.active.bg_fill,
close_tab_color: style.visuals.text_color(),
close_tab_active_color: style.visuals.strong_text_color(),
add_tab_bg_fill: style.visuals.widgets.active.bg_fill,
add_tab_color: style.visuals.text_color(),
add_tab_active_color: style.visuals.strong_text_color(),
add_tab_border_color: style.visuals.widgets.active.bg_fill,
..ButtonsStyle::default()
}
}
}
impl SeparatorStyle {
/// Derives relevant fields from `egui::Style` and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`SeparatorStyle::color_idle`]
/// - [`SeparatorStyle::color_hovered`]
/// - [`SeparatorStyle::color_dragged`]
pub fn from_egui(style: &egui::Style) -> Self {
Self {
// Same as egui panel resize colors:
color_idle: style.visuals.widgets.noninteractive.bg_stroke.color, // dim
color_hovered: style.visuals.widgets.hovered.fg_stroke.color, // bright
color_dragged: style.visuals.widgets.active.fg_stroke.color, // bright
..SeparatorStyle::default()
}
}
}
impl TabBarStyle {
/// Derives relevant fields from `egui::Style` and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`TabBarStyle::bg_fill`]
/// - [`TabBarStyle::hline_color`]
pub fn from_egui(style: &egui::Style) -> Self {
Self {
bg_fill: (Rgba::from(style.visuals.window_fill()) * Rgba::from_gray(0.7)).into(),
hline_color: style.visuals.widgets.active.bg_fill,
..TabBarStyle::default()
}
}
}
impl TabStyle {
/// Derives relevant fields from `egui::Style` and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`TabStyle::outline_color`]
/// - [`TabStyle::bg_fill`]
/// - [`TabStyle::text_color_unfocused`]
/// - [`TabStyle::text_color_focused`]
/// - [`TabStyle::text_color_active_unfocused`]
/// - [`TabStyle::text_color_active_focused`]
pub fn from_egui(style: &egui::Style) -> Self {
Self {
outline_color: style.visuals.widgets.active.bg_fill,
bg_fill: style.visuals.window_fill(),
text_color_unfocused: style.visuals.text_color(),
text_color_focused: style.visuals.strong_text_color(),
text_color_active_unfocused: style.visuals.text_color(),
text_color_active_focused: style.visuals.strong_text_color(),
..TabStyle::default()
}
}
}