egui_stack 0.28.9

Docking system for egui, continuing egui_dock
Documentation
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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
use egui::{CornerRadius, Margin, Stroke, Vec2, ecolor::*};

/// Left or right alignment for tab add button.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum TabAddAlign {
    /// Right after the last tab, the default; at the end of the bar when the tabs fill it.
    Left,
    /// At the end of the tab bar, past its empty part (the former default).
    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_stack::{DockArea, DockState, OverlayType, Style, TabAddAlign, TabViewer};
/// # use egui::{Id, Ui, WidgetText};
/// # struct MyTabViewer;
/// # impl TabViewer for MyTabViewer {
/// #     type Tab = ();
/// #     fn id(&mut self, tab: &mut Self::Tab) -> Id { Id::new(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_ui(|ui| {
/// # #[allow(deprecated)]
/// # egui::CentralPanel::default().show(ui, |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::Right;
///
/// // Use the style with the `DockArea`.
/// DockArea::new(&mut dock_state)
///     .style(style)
///     .show_inside(ui, &mut MyTabViewer);
/// # });
/// # });
/// #
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
#[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: CornerRadius,

    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)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
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,

    /// Where the add tab button sits: right after the last tab ([`TabAddAlign::Left`], the
    /// default) or at the end of the tab bar ([`TabAddAlign::Right`]).
    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,

    /// Color of the close all tabs button.
    pub close_all_tabs_color: Color32,

    /// Color of the active close all tabs button.
    pub close_all_tabs_active_color: Color32,

    /// Color of the close all tabs button's background.
    pub close_all_tabs_bg_fill: Color32,

    /// Color of the close all tabs button's left border.
    pub close_all_tabs_border_color: Color32,

    /// Color of disabled close all tabs button.
    pub close_all_tabs_disabled_color: Color32,

    /// Color of the collapse tabs button.
    pub collapse_tabs_color: Color32,

    /// Color of the active collapse tabs button.
    pub collapse_tabs_active_color: Color32,

    /// Color of the collapse tabs button's background.
    pub collapse_tabs_bg_fill: Color32,

    /// Color of the collapse tabs button's left border.
    pub collapse_tabs_border_color: Color32,

    /// Color of the minimize window button.
    pub minimize_window_color: Color32,

    /// Color of the active minimize window button.
    pub minimize_window_active_color: Color32,

    /// Color of the minimize window button's background.
    pub minimize_window_bg_fill: Color32,

    /// Color of the minimize window button's left border.
    pub minimize_window_border_color: Color32,

    /// Color of the show tab bar triangle button.
    pub show_tab_bar_color: Color32,

    /// Color of the show tab bar triangle button when hovered.
    pub show_tab_bar_active_color: Color32,

    /// Size of the show tab bar triangle button.
    pub show_tab_bar_size: f32,

    /// How much the show tab bar button grows when hovered.
    pub show_tab_bar_hover_expand: f32,

    /// Color of the grip at the end of a tab bar, which moves the whole tab group
    /// ([`GroupHandles::GRIP`](crate::GroupHandles::GRIP)).
    pub group_grip_color: Color32,

    /// Color of the group grip when hovered, focused or dragged.
    pub group_grip_active_color: Color32,

    /// Color of the group grip's background when hovered, focused or dragged.
    pub group_grip_bg_fill: Color32,
}

/// Specifies the look and feel of node separators.
#[derive(Clone, Debug)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
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::TRANSPARENT`]: at
    /// rest the separator is the gap between the two nodes, and it shows on hover and drag.
    /// Set a colour to draw it at rest too.
    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)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
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,

    /// Inner margin of tab bar. By `Default` it's `Margin::ZERO`.
    pub inner_margin: Margin,

    /// Show a scroll bar when tab bar overflows. By `Default` it's `true`.
    pub show_scroll_bar_on_overflow: bool,

    /// Tab bar corner radius. By `Default` it's [`CornerRadius::default`].
    ///
    /// Only the top corners are used: the bar's bottom edge joins the tab body, so its bottom
    /// corners are painted square.
    pub corner_radius: CornerRadius,

    /// Color of the 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.
    /// By `Default` it's `false`.
    pub fill_tab_bar: bool,
}

/// Specifies the look and feel of an individual tab.
#[derive(Clone, Debug)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
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,

    /// Spacing between tabs.
    pub spacing: f32,

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

    /// The space, in points, left on each side of the tab's title.
    ///
    /// A tab is at least as wide as its title, plus twice this padding, plus its close button if
    /// it has one. Lower it, down to `0.0`, for narrower tabs; [`minimum_width`](Self::minimum_width)
    /// can then set the width. By `Default` it's `8.0`.
    pub padding: f32,
}

/// Specifies the look and feel of individual tabs while they are being interacted with.
#[derive(Clone, Debug)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
pub struct TabInteractionStyle {
    /// Color of the outline around tabs. By `Default` it's [`Color32::BLACK`].
    pub outline_color: Color32,

    /// Tab corner radius. By `Default` it's [`CornerRadius::default`].
    ///
    /// A tab in its tab bar joins the body below it, so its bottom corners are painted square;
    /// a dragged tab uses all four.
    pub corner_radius: CornerRadius,

    /// 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)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
pub struct TabBodyStyle {
    /// Inner margin of tab body. By `Default` it's `Margin::same(4.0)`.
    pub inner_margin: Margin,

    /// The stroke of the body's border. By `Default` it's [`Stroke::NONE`]: no border, the
    /// separators part the leaves. Set a stroke to border each body, or paint borders of your
    /// own with [`DockPainter::tab_body`](crate::DockPainter::tab_body).
    pub stroke: Stroke,

    /// Tab body corner radius. By `Default` it's [`CornerRadius::default`].
    ///
    /// Under a tab bar, the body's top corners join the bar and are painted square; only a body
    /// whose tab bar is hidden uses them.
    pub corner_radius: CornerRadius,

    /// Colour of the tab's background. By `Default` it's [`Color32::WHITE`].
    pub bg_fill: Color32,

    /// Optional height override for the draggable area when the tab bar is hidden.
    ///
    /// When `None` (default), the drag area height equals [`TabBodyStyle::inner_margin`]`.top`.
    /// When `Some(height)`, the drag area uses this height instead, overlapping the tab body
    /// content without shifting it down.
    /// Setting this to `Some(0.0)` disables dragging from the hidden tab bar entirely.
    pub hidden_tab_bar_drag_height: Option<f32>,
}

/// Specifies the look and feel of the tab drop overlay.
#[derive(Clone, Debug)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
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 light tint over the region a dragged tab would take, with [`OverlayType::Zones`].
    /// By `Default` it's `(0, 191, 255)` (light blue) at `0.15` opacity.
    pub zone_fill: Color32,

    /// The border around the region a dragged tab would take, with [`OverlayType::Zones`].
    /// By `Default` it's `2.0` wide, `(0, 191, 255)` (light blue).
    pub zone_stroke: Stroke,

    /// The rounding of the region a dragged tab would take, with [`OverlayType::Zones`].
    pub zone_corner_radius: CornerRadius,

    /// 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)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
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,

    /// With [`OverlayType::Zones`], how much of a leaf's width (left and right) or height (top
    /// and bottom) the band along each edge covers, in `0.0..=0.5`: over a band, a dropped tab
    /// splits the leaf on that side; over the rest, it joins the leaf's tabs. The height is the
    /// body's, below the tab bar, with [`zone_edges_below_tab_bar`](Self::zone_edges_below_tab_bar).
    /// See [`DropZone::in_leaf`](crate::DropZone::in_leaf).
    pub zone_edge_coverage: f32,

    /// With [`OverlayType::Zones`], whether the edge bands
    /// ([`zone_edge_coverage`](Self::zone_edge_coverage)) are laid on the leaf's body, below its
    /// tab bar and the [`zone_tab_bar_stack_band`](Self::zone_tab_bar_stack_band), or on the whole
    /// leaf, tab bar included. On the whole leaf, the top band of a compact leaf lies mostly under
    /// its tab bar, leaving a thin strip of it right below the bar.
    ///
    /// By `Default` it's `true`; `false`, with a `zone_tab_bar_stack_band` of `0.0`, gives the
    /// geometry of egui_stack 0.25.12 and before.
    pub zone_edges_below_tab_bar: bool,

    /// With [`OverlayType::Zones`], the height in points of a band right under a leaf's tab bar
    /// where a dropped tab joins the leaf's tabs, as over the tab bar itself, whatever the edge
    /// bands say: a tab aimed at the tab bar and released a little low does not split the leaf.
    ///
    /// By `Default` it's `8.0`, a third of a default tab bar's height.
    pub zone_tab_bar_stack_band: f32,

    /// How far, in points, the pointer must move from where it was pressed on a tab (or on the
    /// empty part of a tab bar) along `x` and along `y` before the tab (or the tab group) starts
    /// being dragged; further along either axis, it drags.
    ///
    /// egui takes a press for a click until the pointer moves further than its click distance
    /// ([`egui::InputOptions::max_click_dist`]), so a distance at or below it starts the drag as
    /// soon as the press is no longer a click. A larger distance leaves a range where the press
    /// neither clicks nor drags, which can guard against moving a tab by accident.
    ///
    /// By `Default` it's `6.0` along both axes, egui's default click distance.
    pub drag_activation_distance: Vec2,

    /// The breadth in points of a collapsed zone's restore band, shown while a tab is dragged
    /// ([`Fold::Collapse`](crate::layout::Fold::Collapse), [`DockSpace::bind`](crate::DockSpace::bind)):
    /// a tab released on it brings the zone back. Bands on the same boundary stack, each this
    /// wide.
    ///
    /// By `Default` it's `8.0`.
    pub restore_band: f32,
}

/// Specifies the type of overlay used.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[non_exhaustive]
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.
    Widgets,

    /// Highlights, on the leaf under the pointer, the region the tab would take: the half along
    /// an edge when the pointer is in that edge's band ([`OverlayFeel::zone_edge_coverage`]),
    /// which splits the leaf, or the whole leaf elsewhere, where the tab joins its tabs. The
    /// region gets a border ([`OverlayStyle::zone_stroke`]) and a light tint
    /// ([`OverlayStyle::zone_fill`]); there are no buttons. Over a tab bar, the tab goes where
    /// the pointer is in it.
    ///
    /// A tab allowed in windows ([`TabViewer::allowed_in_windows`](crate::TabViewer::allowed_in_windows))
    /// dropped outside the dock, where no leaf and no window of the dock is under the pointer,
    /// opens in a new window.
    ///
    /// This is the default.
    Zones,
}

/// Highlighting on the currently hovered leaf.
#[derive(Clone, Debug)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(default)
)]
pub struct LeafHighlighting {
    /// Fill color.
    pub color: Color32,

    /// Rounding of the resulting rectangle.
    pub corner_radius: CornerRadius,

    /// 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: CornerRadius::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::Left,
            add_tab_color: Color32::WHITE,
            add_tab_active_color: Color32::WHITE,
            add_tab_bg_fill: Color32::GRAY,
            add_tab_border_color: Color32::BLACK,

            close_all_tabs_color: Color32::WHITE,
            close_all_tabs_active_color: Color32::WHITE,
            close_all_tabs_bg_fill: Color32::GRAY,
            close_all_tabs_border_color: Color32::BLACK,
            close_all_tabs_disabled_color: Color32::LIGHT_GRAY,

            collapse_tabs_color: Color32::WHITE,
            collapse_tabs_active_color: Color32::WHITE,
            collapse_tabs_bg_fill: Color32::GRAY,
            collapse_tabs_border_color: Color32::BLACK,

            minimize_window_color: Color32::WHITE,
            minimize_window_active_color: Color32::WHITE,
            minimize_window_bg_fill: Color32::GRAY,
            minimize_window_border_color: Color32::BLACK,

            show_tab_bar_color: Color32::GRAY,
            show_tab_bar_active_color: Color32::WHITE,
            show_tab_bar_size: 10.0,
            show_tab_bar_hover_expand: 1.0,

            group_grip_color: Color32::GRAY,
            group_grip_active_color: Color32::WHITE,
            group_grip_bg_fill: Color32::GRAY,
        }
    }
}

impl Default for SeparatorStyle {
    fn default() -> Self {
        Self {
            width: 1.0,
            extra_interact_width: 2.0,
            extra: 175.0,
            color_idle: Color32::TRANSPARENT,
            color_hovered: Color32::GRAY,
            color_dragged: Color32::WHITE,
        }
    }
}

impl Default for TabBarStyle {
    fn default() -> Self {
        Self {
            bg_fill: Color32::WHITE,
            height: 24.0,
            inner_margin: Margin::ZERO,
            show_scroll_bar_on_overflow: true,
            corner_radius: CornerRadius::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()
            },
            spacing: 0.0,
            tab_body: TabBodyStyle::default(),
            hline_below_active_tab_name: false,
            minimum_width: None,
            padding: 8.0,
        }
    }
}

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

impl Default for TabBodyStyle {
    fn default() -> Self {
        Self {
            inner_margin: Margin::same(4),
            stroke: Stroke::NONE,
            corner_radius: CornerRadius::default(),
            bg_fill: Color32::WHITE,
            hidden_tab_bar_drag_height: None,
        }
    }
}

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_f32, Color32::from_gray(60)),
            zone_fill: Color32::from_rgb(0, 191, 255).gamma_multiply(0.15),
            zone_stroke: Stroke::new(2.0, Color32::from_rgb(0, 191, 255)),
            zone_corner_radius: CornerRadius::same(2),
            overlay_type: OverlayType::Zones,
            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,
            zone_edge_coverage: 0.3,
            zone_edges_below_tab_bar: true,
            zone_tab_bar_stack_band: 8.0,
            drag_activation_distance: Vec2::splat(6.0),
            restore_band: 8.0,
        }
    }
}

impl Default for LeafHighlighting {
    fn default() -> Self {
        Self {
            color: Color32::TRANSPARENT,
            corner_radius: CornerRadius::same(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;
    pub(crate) const TAB_CLOSE_ALL_BUTTON_SIZE: f32 = 24.0;
    pub(crate) const TAB_CLOSE_ALL_SIZE: f32 = 10.0;
    pub(crate) const TAB_COLLAPSE_BUTTON_SIZE: f32 = 24.0;
    pub(crate) const TAB_COLLAPSE_ARROW_SIZE: f32 = 10.0;
    pub(crate) const TAB_GROUP_GRIP_SIZE: f32 = 16.0;
    pub(crate) const TAB_EXPAND_BUTTON_SIZE: f32 = 24.0;
    pub(crate) const TAB_EXPAND_ARROW_SIZE: f32 = 10.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: CornerRadius::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`]
    /// - [`ButtonsStyle::add_tab_border_color`]
    /// - [`ButtonsStyle::close_all_tabs_bg_fill`]
    /// - [`ButtonsStyle::close_all_tabs_color`]
    /// - [`ButtonsStyle::close_all_tabs_active_color`]
    /// - [`ButtonsStyle::close_all_tabs_border_color`]
    /// - [`ButtonsStyle::collapse_tabs_bg_fill`]
    /// - [`ButtonsStyle::collapse_tabs_color`]
    /// - [`ButtonsStyle::collapse_tabs_active_color`]
    /// - [`ButtonsStyle::collapse_tabs_border_color`]
    /// - [`ButtonsStyle::group_grip_color`]
    /// - [`ButtonsStyle::group_grip_active_color`]
    /// - [`ButtonsStyle::group_grip_bg_fill`]
    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,
            close_all_tabs_bg_fill: style.visuals.widgets.hovered.bg_fill,
            close_all_tabs_color: style.visuals.text_color(),
            close_all_tabs_active_color: style.visuals.strong_text_color(),
            close_all_tabs_border_color: style.visuals.widgets.noninteractive.bg_fill,
            close_all_tabs_disabled_color: style.visuals.widgets.inactive.bg_fill,
            collapse_tabs_bg_fill: style.visuals.widgets.hovered.bg_fill,
            collapse_tabs_color: style.visuals.text_color(),
            collapse_tabs_active_color: style.visuals.strong_text_color(),
            collapse_tabs_border_color: style.visuals.widgets.noninteractive.bg_fill,
            minimize_window_bg_fill: style.visuals.widgets.hovered.bg_fill,
            minimize_window_color: style.visuals.text_color(),
            minimize_window_active_color: style.visuals.strong_text_color(),
            minimize_window_border_color: style.visuals.widgets.noninteractive.bg_fill,
            show_tab_bar_color: style.visuals.text_color(),
            show_tab_bar_active_color: style.visuals.strong_text_color(),
            group_grip_color: style.visuals.weak_text_color(),
            group_grip_active_color: style.visuals.strong_text_color(),
            group_grip_bg_fill: style.visuals.widgets.hovered.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_hovered`]
    /// - [`SeparatorStyle::color_dragged`]
    ///
    /// [`SeparatorStyle::color_idle`] stays transparent. For a line at rest as well, set it, for
    /// example to `style.visuals.widgets.noninteractive.bg_stroke.color`.
    pub fn from_egui(style: &egui::Style) -> Self {
        Self {
            // Same as egui panel resize colors:
            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: style.visuals.extreme_bg_color,
            corner_radius: CornerRadius {
                nw: style.visuals.widgets.inactive.corner_radius.nw + 2,
                ne: style.visuals.widgets.inactive.corner_radius.ne + 2,
                sw: 0,
                se: 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`]
    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(),
            corner_radius: CornerRadius {
                sw: 0,
                se: 0,
                ..style.visuals.widgets.active.corner_radius
            },
        }
    }

    /// 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`]
    pub fn from_egui_inactive(style: &egui::Style) -> Self {
        Self {
            text_color: style.visuals.text_color(),
            bg_fill: tint_color_towards(style.visuals.window_fill, style.visuals.extreme_bg_color),
            outline_color: 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`]
    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`]
    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`]
    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`]
    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`]
    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::corner_radius`]
    /// - [`TabBodyStyle::bg_fill`]
    ///
    /// [`TabBodyStyle::stroke`] stays [`Stroke::NONE`]. For a border around each body, set it,
    /// for example to `style.visuals.widgets.noninteractive.bg_stroke`.
    pub fn from_egui(style: &egui::Style) -> Self {
        Self {
            inner_margin: style.spacing.window_margin,
            stroke: Stroke::NONE,
            corner_radius: style.visuals.widgets.active.corner_radius,
            bg_fill: style.visuals.window_fill(),
            hidden_tab_bar_drag_height: None,
        }
    }
}

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`]
    /// - [`OverlayStyle::zone_fill`]
    /// - [`OverlayStyle::zone_stroke`]
    /// - [`OverlayStyle::zone_corner_radius`]
    pub fn from_egui(style: &egui::Style) -> Self {
        let selection = style.visuals.selection.bg_fill;
        Self {
            selection_color: selection.linear_multiply(0.5),
            zone_fill: selection.gamma_multiply(0.15),
            zone_stroke: Stroke::new(2.0, selection),
            zone_corner_radius: style.visuals.widgets.noninteractive.corner_radius,
            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()
        }
    }
}