Skip to main content

fastpack_gui/
theme.rs

1use eframe::egui;
2
3const ACCENT: egui::Color32 = egui::Color32::from_rgb(62, 176, 154);
4
5pub fn apply(ctx: &egui::Context, dark_mode: bool) {
6    let mut style = (*ctx.style()).clone();
7    style.spacing.item_spacing = egui::vec2(6.0, 4.0);
8    style.spacing.button_padding = egui::vec2(6.0, 3.0);
9    style.spacing.window_margin = egui::Margin::same(6);
10    style.interaction.selectable_labels = false;
11    ctx.set_style(style);
12
13    ctx.set_visuals(if dark_mode {
14        custom_dark()
15    } else {
16        custom_light()
17    });
18}
19
20fn custom_dark() -> egui::Visuals {
21    let mut v = egui::Visuals::dark();
22
23    v.panel_fill = egui::Color32::from_rgb(30, 30, 30);
24    v.window_fill = egui::Color32::from_rgb(36, 36, 36);
25    v.faint_bg_color = egui::Color32::from_rgb(34, 34, 34);
26    v.extreme_bg_color = egui::Color32::from_rgb(22, 22, 22);
27
28    v.window_corner_radius = egui::CornerRadius::same(4);
29
30    v.selection.bg_fill = egui::Color32::from_rgba_unmultiplied(62, 176, 154, 100);
31    v.selection.stroke = egui::Stroke::new(1.0, ACCENT);
32    v.hyperlink_color = ACCENT;
33
34    let corner = egui::CornerRadius::same(3);
35    let separator = egui::Color32::from_rgb(55, 55, 55);
36
37    v.widgets.noninteractive.bg_fill = egui::Color32::from_rgb(38, 38, 38);
38    v.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0, separator);
39    v.widgets.noninteractive.fg_stroke =
40        egui::Stroke::new(1.0, egui::Color32::from_rgb(200, 200, 200));
41    v.widgets.noninteractive.corner_radius = corner;
42
43    v.widgets.inactive.bg_fill = egui::Color32::from_rgb(48, 48, 48);
44    v.widgets.inactive.bg_stroke = egui::Stroke::new(1.0, egui::Color32::from_rgb(65, 65, 65));
45    v.widgets.inactive.fg_stroke = egui::Stroke::new(1.0, egui::Color32::from_rgb(200, 200, 200));
46    v.widgets.inactive.corner_radius = corner;
47
48    v.widgets.hovered.bg_fill = egui::Color32::from_rgb(58, 58, 58);
49    v.widgets.hovered.bg_stroke = egui::Stroke::new(1.0, ACCENT);
50    v.widgets.hovered.corner_radius = corner;
51
52    v.widgets.active.bg_fill = egui::Color32::from_rgba_unmultiplied(62, 176, 154, 55);
53    v.widgets.active.bg_stroke = egui::Stroke::new(1.5, ACCENT);
54    v.widgets.active.corner_radius = corner;
55
56    v.widgets.open.bg_fill = egui::Color32::from_rgb(50, 50, 50);
57    v.widgets.open.bg_stroke = egui::Stroke::new(1.0, ACCENT);
58    v.widgets.open.corner_radius = corner;
59
60    v
61}
62
63fn custom_light() -> egui::Visuals {
64    let mut v = egui::Visuals::light();
65
66    v.panel_fill = egui::Color32::from_rgb(238, 238, 242);
67    v.window_fill = egui::Color32::from_rgb(246, 246, 250);
68    v.faint_bg_color = egui::Color32::from_rgb(228, 228, 233);
69    v.extreme_bg_color = egui::Color32::from_rgb(255, 255, 255);
70
71    v.window_corner_radius = egui::CornerRadius::same(4);
72
73    let accent = egui::Color32::from_rgb(0, 155, 135);
74    v.selection.bg_fill = egui::Color32::from_rgba_unmultiplied(62, 176, 154, 70);
75    v.selection.stroke = egui::Stroke::new(1.0, accent);
76    v.hyperlink_color = accent;
77
78    let corner = egui::CornerRadius::same(3);
79    let separator = egui::Color32::from_rgb(205, 205, 210);
80
81    v.widgets.noninteractive.bg_fill = egui::Color32::from_rgb(228, 228, 233);
82    v.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0, separator);
83    v.widgets.noninteractive.fg_stroke =
84        egui::Stroke::new(1.0, egui::Color32::from_rgb(55, 55, 62));
85    v.widgets.noninteractive.corner_radius = corner;
86
87    v.widgets.inactive.bg_fill = egui::Color32::from_rgb(218, 218, 224);
88    v.widgets.inactive.bg_stroke = egui::Stroke::new(1.0, egui::Color32::from_rgb(192, 192, 200));
89    v.widgets.inactive.fg_stroke = egui::Stroke::new(1.0, egui::Color32::from_rgb(45, 45, 52));
90    v.widgets.inactive.corner_radius = corner;
91
92    v.widgets.hovered.bg_fill = egui::Color32::from_rgb(206, 206, 214);
93    v.widgets.hovered.bg_stroke = egui::Stroke::new(1.0, accent);
94    v.widgets.hovered.fg_stroke = egui::Stroke::new(1.0, egui::Color32::from_rgb(30, 30, 36));
95    v.widgets.hovered.corner_radius = corner;
96
97    v.widgets.active.bg_fill = egui::Color32::from_rgba_unmultiplied(62, 176, 154, 45);
98    v.widgets.active.bg_stroke = egui::Stroke::new(1.5, accent);
99    v.widgets.active.fg_stroke = egui::Stroke::new(1.5, egui::Color32::from_rgb(20, 20, 26));
100    v.widgets.active.corner_radius = corner;
101
102    v.widgets.open.bg_fill = egui::Color32::from_rgb(212, 212, 220);
103    v.widgets.open.bg_stroke = egui::Stroke::new(1.0, accent);
104    v.widgets.open.corner_radius = corner;
105
106    v
107}