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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
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,
}

/// Lets you change how tabs and the [`DockArea`](crate::DockArea) should look and feel.
/// [`Style`] is divided into several, more specialized structs that handle individual
/// elements of the UI.
///
/// Your [`Style`] can inherit all its properties from an [`egui::Style`] through the
/// [`Style::from_egui`] function.
///
/// Example:
///
/// ```rust
/// # use egui_dock::{DockArea, DockState, OverlayType, Style, TabAddAlign, TabViewer};
/// # use egui::{Ui, WidgetText};
/// # struct MyTabViewer;
/// # impl TabViewer for MyTabViewer {
/// #     type Tab = ();
/// #     fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { WidgetText::default() }
/// #     fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) {}
/// # }
/// # egui::__run_test_ctx(|ctx| {
/// # egui::CentralPanel::default().show(ctx, |ui| {
/// # let mut dock_state = DockState::new(vec![]);
/// // Inherit the look and feel from egui.
/// let mut style = Style::from_egui(ui.style());
///
/// // Modify a few fields.
/// style.overlay.overlay_type = OverlayType::HighlightedAreas;
/// style.buttons.add_tab_align = TabAddAlign::Left;
///
/// // Use the style with the `DockArea`.
/// DockArea::new(&mut dock_state)
///     .style(style)
///     .show_inside(ui, &mut MyTabViewer);
/// # });
/// # });
/// #
/// ```
#[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>,

    pub main_surface_border_stroke: Stroke,
    pub main_surface_border_rounding: Rounding,

    pub buttons: ButtonsStyle,
    pub separator: SeparatorStyle,
    pub tab_bar: TabBarStyle,
    pub tab: TabStyle,
    pub overlay: OverlayStyle,
}

/// 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,

    /// Whether tab titles expand to fill the width of their tab bars.
    pub fill_tab_bar: bool,
}

/// Specifies the look and feel of an individual tab.
#[derive(Clone, Debug)]
pub struct TabStyle {
    /// Style of the tab when it is active.
    pub active: TabInteractionStyle,

    /// Style of the tab when it is inactive.
    pub inactive: TabInteractionStyle,

    /// Style of the tab when it is focused.
    pub focused: TabInteractionStyle,

    /// Style of the tab when it is hovered.
    pub hovered: TabInteractionStyle,

    /// Style of the tab when it is inactive and has keyboard focus.
    pub inactive_with_kb_focus: TabInteractionStyle,

    /// Style of the tab when it is active and has keyboard focus.
    pub active_with_kb_focus: TabInteractionStyle,

    /// Style of the tab when it is focused and has keyboard focus.
    pub focused_with_kb_focus: TabInteractionStyle,

    /// Style for the tab body.
    pub tab_body: TabBodyStyle,

    /// 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,

    /// The minimum width of the tab.
    ///
    /// The tab title or [`TabBarStyle::fill_tab_bar`] may make the tab
    /// wider than this but never shorter.
    pub minimum_width: Option<f32>,
}

/// Specifies the look and feel of individual tabs while they are being interacted with.
#[derive(Clone, Debug)]
pub struct TabInteractionStyle {
    /// 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 the title text.
    pub text_color: Color32,
}

/// Specifies the look and feel of the tab body.
#[derive(Clone, Debug)]
pub struct TabBodyStyle {
    /// Inner margin of tab body. By `Default` it's `Margin::same(4.0)`.
    pub inner_margin: Margin,

    /// The stroke of the tabs border. By `Default` it's ['Stroke::default'].
    pub stroke: Stroke,

    /// 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,
}

/// Specifies the look and feel of the tab drop overlay.
#[derive(Clone, Debug)]
pub struct OverlayStyle {
    /// 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,

    /// Width of stroke when a selection uses an outline instead of filled rectangle.
    pub selection_stroke_width: f32,

    /// Units of padding between each button.
    pub button_spacing: f32,

    /// Max side length of a button on the overlay.
    pub max_button_size: f32,

    /// Style of the additional highlighting rectangle drawn on the surface which you're attempting to drop a tab in.
    ///
    /// By default this value shows no highlighting.
    pub hovered_leaf_highlight: LeafHighlighting,

    /// Opacity which surfaces will fade to in a range of `0.0..=1.0`.
    pub surface_fade_opacity: f32,

    /// The color of the overlay buttons.
    pub button_color: Color32,

    /// The stroke of the button border.
    pub button_border_stroke: Stroke,

    /// The type of overlay used.
    pub overlay_type: OverlayType,

    /// The feel of the overlay, timings, detection, etc.
    pub feel: OverlayFeel,
}

/// Specifies the feel of the tab drop overlay, i.e anything non visual about the overlay.
#[derive(Clone, Debug)]
pub struct OverlayFeel {
    /// range is `0.0..=1.0`.
    pub window_drop_coverage: f32,

    /// range is `0.0..=1.0`.
    pub center_drop_coverage: f32,

    /// The amount of time windows should stay faded despite not needing to, prevents quick mouse movements from causing flashing.
    pub fade_hold_time: f32,

    /// Amount of time the overlay waits before dropping a preference it may have for a node.
    pub max_preference_time: f32,

    /// Units which the buttons interact area will be expanded by.
    pub interact_expansion: f32,
}

/// Specifies the type of overlay used.
#[derive(Clone, Debug, PartialEq)]
pub enum OverlayType {
    /// Shows highlighted areas predicting where a dropped tab would land were it to be dropped this frame.
    ///
    /// Always used when hovering over tabs and tab head.
    HighlightedAreas,

    /// Shows icons indicating the possible drop positions which the user may hover over to drop a tab at that given location.
    ///
    /// This is the default type of overlay for leaves.
    Widgets,
}

/// Highlighting on the currently hovered leaf.
#[derive(Clone, Debug)]
pub struct LeafHighlighting {
    /// Fill color.
    pub color: Color32,

    /// Rounding of the resulting rectangle.
    pub rounding: Rounding,

    /// Stroke.
    pub stroke: Stroke,

    /// Amount of egui units which each side should expand.
    pub expansion: f32,
}

impl Default for Style {
    fn default() -> Self {
        Self {
            dock_area_padding: None,
            main_surface_border_stroke: Stroke::new(f32::default(), Color32::BLACK),
            main_surface_border_rounding: Rounding::default(),
            buttons: ButtonsStyle::default(),
            separator: SeparatorStyle::default(),
            tab_bar: TabBarStyle::default(),
            tab: TabStyle::default(),
            overlay: OverlayStyle::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,
            fill_tab_bar: false,
        }
    }
}

impl Default for TabStyle {
    fn default() -> Self {
        Self {
            active: TabInteractionStyle::default(),
            inactive: TabInteractionStyle {
                text_color: Color32::DARK_GRAY,
                ..Default::default()
            },
            focused: TabInteractionStyle {
                text_color: Color32::BLACK,
                ..Default::default()
            },
            hovered: TabInteractionStyle {
                text_color: Color32::BLACK,
                ..Default::default()
            },
            active_with_kb_focus: TabInteractionStyle::default(),
            inactive_with_kb_focus: TabInteractionStyle {
                text_color: Color32::DARK_GRAY,
                ..Default::default()
            },
            focused_with_kb_focus: TabInteractionStyle {
                text_color: Color32::BLACK,
                ..Default::default()
            },
            tab_body: TabBodyStyle::default(),
            hline_below_active_tab_name: false,
            minimum_width: None,
        }
    }
}

impl Default for TabInteractionStyle {
    fn default() -> Self {
        Self {
            bg_fill: Color32::WHITE,
            outline_color: Color32::BLACK,
            rounding: Rounding::default(),
            text_color: Color32::DARK_GRAY,
        }
    }
}

impl Default for TabBodyStyle {
    fn default() -> Self {
        Self {
            inner_margin: Margin::same(4.0),
            stroke: Stroke::default(),
            rounding: Rounding::default(),
            bg_fill: Color32::WHITE,
        }
    }
}

impl Default for OverlayStyle {
    fn default() -> Self {
        Self {
            selection_color: Color32::from_rgb(0, 191, 255).linear_multiply(0.5),
            selection_stroke_width: 1.0,
            button_spacing: 10.0,
            max_button_size: 100.0,

            surface_fade_opacity: 0.1,

            hovered_leaf_highlight: Default::default(),
            button_color: Color32::from_gray(140),
            button_border_stroke: Stroke::new(1.0, Color32::from_gray(60)),
            overlay_type: OverlayType::Widgets,
            feel: Default::default(),
        }
    }
}

impl Default for OverlayFeel {
    fn default() -> Self {
        Self {
            max_preference_time: 0.3,
            window_drop_coverage: 0.5,
            center_drop_coverage: 0.25,
            fade_hold_time: 0.2,
            interact_expansion: 20.0,
        }
    }
}

impl Default for LeafHighlighting {
    fn default() -> Self {
        Self {
            color: Color32::TRANSPARENT,
            rounding: Rounding::same(0.0),
            stroke: Stroke::NONE,
            expansion: 0.0,
        }
    }
}

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::main_surface_border_stroke`]
    ///
    /// See also: [`ButtonsStyle::from_egui`], [`SeparatorStyle::from_egui`], [`TabBarStyle::from_egui`],
    /// [`TabStyle::from_egui`]
    pub fn from_egui(style: &egui::Style) -> Self {
        Self {
            main_surface_border_stroke: Stroke::NONE,
            main_surface_border_rounding: Rounding::ZERO,
            buttons: ButtonsStyle::from_egui(style),
            separator: SeparatorStyle::from_egui(style),
            tab_bar: TabBarStyle::from_egui(style),
            tab: TabStyle::from_egui(style),
            overlay: OverlayStyle::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.hovered.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.hovered.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.noninteractive.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::rounding`]
    /// - [`TabBarStyle::hline_color`]
    pub fn from_egui(style: &egui::Style) -> Self {
        Self {
            bg_fill: style.visuals.extreme_bg_color,
            rounding: Rounding {
                nw: style.visuals.widgets.inactive.rounding.nw + 2.0,
                ne: style.visuals.widgets.inactive.rounding.ne + 2.0,
                sw: 0.0,
                se: 0.0,
            },
            hline_color: style.visuals.widgets.noninteractive.bg_stroke.color,
            ..TabBarStyle::default()
        }
    }
}

impl TabStyle {
    /// Derives tab styles from `egui::Style`.
    ///
    /// See also: [`TabInteractionStyle::from_egui_active`], [`TabInteractionStyle::from_egui_inactive`],
    /// [`TabInteractionStyle::from_egui_focused`], [`TabInteractionStyle::from_egui_hovered`], [`TabBodyStyle::from_egui`],
    pub fn from_egui(style: &egui::Style) -> TabStyle {
        Self {
            active: TabInteractionStyle::from_egui_active(style),
            inactive: TabInteractionStyle::from_egui_inactive(style),
            focused: TabInteractionStyle::from_egui_focused(style),
            hovered: TabInteractionStyle::from_egui_hovered(style),
            active_with_kb_focus: TabInteractionStyle::from_egui_active_with_kb_focus(style),
            inactive_with_kb_focus: TabInteractionStyle::from_egui_inactive_with_kb_focus(style),
            focused_with_kb_focus: TabInteractionStyle::from_egui_focused_with_kb_focus(style),
            tab_body: TabBodyStyle::from_egui(style),
            ..Default::default()
        }
    }
}

impl TabInteractionStyle {
    /// Derives relevant fields from `egui::Style` for an active tab and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabInteractionStyle::outline_color`]
    /// - [`TabInteractionStyle::bg_fill`]
    /// - [`TabInteractionStyle::text_color`]
    /// - [`TabInteractionStyle::rounding`]
    pub fn from_egui_active(style: &egui::Style) -> Self {
        Self {
            outline_color: style.visuals.widgets.noninteractive.bg_stroke.color,
            bg_fill: style.visuals.window_fill(),
            text_color: style.visuals.text_color(),
            rounding: Rounding {
                sw: 0.0,
                se: 0.0,
                ..style.visuals.widgets.active.rounding
            },
        }
    }

    /// Derives relevant fields from `egui::Style` for an inactive tab and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabInteractionStyle::outline_color`]
    /// - [`TabInteractionStyle::bg_fill`]
    /// - [`TabInteractionStyle::text_color`]
    /// - [`TabInteractionStyle::rounding`]
    pub fn from_egui_inactive(style: &egui::Style) -> Self {
        Self {
            text_color: style.visuals.text_color(),
            bg_fill: egui::ecolor::tint_color_towards(
                style.visuals.window_fill,
                style.visuals.extreme_bg_color,
            ),
            outline_color: egui::ecolor::tint_color_towards(
                style.visuals.widgets.noninteractive.bg_stroke.color,
                style.visuals.extreme_bg_color,
            ),
            ..TabInteractionStyle::from_egui_active(style)
        }
    }

    /// Derives relevant fields from `egui::Style` for a focused tab and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabInteractionStyle::outline_color`]
    /// - [`TabInteractionStyle::bg_fill`]
    /// - [`TabInteractionStyle::text_color`]
    /// - [`TabInteractionStyle::rounding`]
    pub fn from_egui_focused(style: &egui::Style) -> Self {
        Self {
            text_color: style.visuals.strong_text_color(),
            ..TabInteractionStyle::from_egui_active(style)
        }
    }

    /// Derives relevant fields from `egui::Style` for a hovered tab and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabInteractionStyle::outline_color`]
    /// - [`TabInteractionStyle::bg_fill`]
    /// - [`TabInteractionStyle::text_color`]
    /// - [`TabInteractionStyle::rounding`]
    pub fn from_egui_hovered(style: &egui::Style) -> Self {
        Self {
            text_color: style.visuals.strong_text_color(),
            outline_color: style.visuals.widgets.hovered.bg_stroke.color,
            ..TabInteractionStyle::from_egui_inactive(style)
        }
    }

    /// Derives relevant fields from `egui::Style` for an active tab with keyboard focus and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabInteractionStyle::outline_color`]
    /// - [`TabInteractionStyle::bg_fill`]
    /// - [`TabInteractionStyle::text_color`]
    /// - [`TabInteractionStyle::rounding`]
    pub fn from_egui_active_with_kb_focus(style: &egui::Style) -> Self {
        Self {
            text_color: style.visuals.strong_text_color(),
            outline_color: style.visuals.widgets.hovered.bg_stroke.color,
            ..TabInteractionStyle::from_egui_active(style)
        }
    }

    /// Derives relevant fields from `egui::Style` for an inactive tab with keyboard focus and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabInteractionStyle::outline_color`]
    /// - [`TabInteractionStyle::bg_fill`]
    /// - [`TabInteractionStyle::text_color`]
    /// - [`TabInteractionStyle::rounding`]
    pub fn from_egui_inactive_with_kb_focus(style: &egui::Style) -> Self {
        Self {
            text_color: style.visuals.strong_text_color(),
            outline_color: style.visuals.widgets.hovered.bg_stroke.color,
            ..TabInteractionStyle::from_egui_inactive(style)
        }
    }

    /// Derives relevant fields from `egui::Style` for a focused tab with keyboard focus and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabInteractionStyle::outline_color`]
    /// - [`TabInteractionStyle::bg_fill`]
    /// - [`TabInteractionStyle::text_color`]
    /// - [`TabInteractionStyle::rounding`]
    pub fn from_egui_focused_with_kb_focus(style: &egui::Style) -> Self {
        Self {
            text_color: style.visuals.strong_text_color(),
            outline_color: style.visuals.widgets.hovered.bg_stroke.color,
            ..TabInteractionStyle::from_egui_focused(style)
        }
    }
}

impl TabBodyStyle {
    /// Derives relevant fields from `egui::Style` and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`TabBodyStyle::inner_margin`]
    /// - [`TabBodyStyle::stroke]
    /// - [`TabBodyStyle::rounding`]
    /// - [`TabBodyStyle::bg_fill`]
    pub fn from_egui(style: &egui::Style) -> Self {
        Self {
            inner_margin: style.spacing.window_margin,
            stroke: style.visuals.widgets.noninteractive.bg_stroke,
            rounding: style.visuals.widgets.active.rounding,
            bg_fill: style.visuals.window_fill(),
        }
    }
}

impl OverlayStyle {
    /// Derives relevant fields from `egui::Style` and sets the remaining fields to their default values.
    ///
    /// Fields overwritten by [`egui::Style`] are:
    /// - [`OverlayStyle::selection_color`]
    /// - [`OverlayStyle::button_spacing]
    /// - [`OverlayStyle::button_color`]
    /// - [`OverlayStyle::button_border_stroke`]
    pub fn from_egui(style: &egui::Style) -> Self {
        Self {
            selection_color: style.visuals.selection.bg_fill.linear_multiply(0.5),
            button_spacing: style.spacing.icon_spacing,
            button_color: style.visuals.widgets.noninteractive.fg_stroke.color,
            button_border_stroke: style.visuals.widgets.noninteractive.bg_stroke,
            ..Default::default()
        }
    }
}