Skip to content

Commit 6974abb

Browse files
committed
Tweak light mode
1 parent 7c6da40 commit 6974abb

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

egui/src/grid.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,7 @@ impl GridLayout {
198198
let rect = rect.expand2(0.5 * self.spacing.y * Vec2::Y);
199199
let rect = rect.expand2(2.0 * Vec2::X); // HACK: just looks better with some spacing on the sides
200200

201-
let color = if self.style.visuals.dark_mode {
202-
Rgba::from_white_alpha(0.0065)
203-
} else {
204-
Rgba::from_black_alpha(0.075)
205-
};
206-
painter.rect_filled(rect, 2.0, color);
201+
painter.rect_filled(rect, 2.0, self.style.visuals.faint_bg_color);
207202
}
208203
}
209204
}

egui/src/style.rs

+39-15
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,18 @@ pub struct Visuals {
196196

197197
pub selection: Selection,
198198

199+
/// The color used for `Hyperlink`,
200+
pub hyperlink_color: Color32,
201+
202+
/// Something just barely different from the background color.
203+
/// Used for [`Grid::striped`].
204+
pub faint_bg_color: Color32,
205+
199206
/// Very dark or light color (for corresponding theme).
200207
/// Used as the background of text edits, scroll bars and others things
201208
/// that needs to look different from other interactive stuff.
202209
pub extreme_bg_color: Color32,
203210

204-
/// The color used for `Hyperlink`,
205-
pub hyperlink_color: Color32,
206-
207211
/// Background color behind code-styled monospaced labels.
208212
pub code_bg_color: Color32,
209213

@@ -392,8 +396,9 @@ impl Visuals {
392396
override_text_color: None,
393397
widgets: Widgets::default(),
394398
selection: Selection::default(),
395-
extreme_bg_color: Color32::from_gray(10),
396399
hyperlink_color: Color32::from_rgb(90, 170, 255),
400+
faint_bg_color: Color32::from_gray(24),
401+
extreme_bg_color: Color32::from_gray(10),
397402
code_bg_color: Color32::from_gray(64),
398403
window_corner_radius: 6.0,
399404
window_shadow: Shadow::big_dark(),
@@ -412,8 +417,9 @@ impl Visuals {
412417
dark_mode: false,
413418
widgets: Widgets::light(),
414419
selection: Selection::light(),
415-
extreme_bg_color: Color32::from_gray(235), // TODO: rename
416-
hyperlink_color: Color32::from_rgb(0, 133, 218),
420+
hyperlink_color: Color32::from_rgb(0, 155, 255),
421+
faint_bg_color: Color32::from_gray(240),
422+
extreme_bg_color: Color32::from_gray(250),
417423
code_bg_color: Color32::from_gray(200),
418424
window_shadow: Shadow::big_light(),
419425
..Self::dark()
@@ -506,7 +512,7 @@ impl Widgets {
506512
expansion: 0.0,
507513
},
508514
hovered: WidgetVisuals {
509-
bg_fill: Color32::from_gray(190),
515+
bg_fill: Color32::from_gray(210),
510516
bg_stroke: Stroke::new(1.0, Color32::from_gray(105)), // e.g. hover over window edge or button
511517
fg_stroke: Stroke::new(1.5, Color32::BLACK),
512518
corner_radius: 3.0,
@@ -740,7 +746,7 @@ impl Widgets {
740746
open.ui(ui)
741747
});
742748

743-
ui.vertical_centered(|ui| reset_button(ui, self));
749+
// ui.vertical_centered(|ui| reset_button(ui, self));
744750
}
745751
}
746752

@@ -812,8 +818,9 @@ impl Visuals {
812818
override_text_color: _,
813819
widgets,
814820
selection,
815-
extreme_bg_color,
816821
hyperlink_color,
822+
faint_bg_color,
823+
extreme_bg_color,
817824
code_bg_color,
818825
window_corner_radius,
819826
window_shadow,
@@ -825,6 +832,16 @@ impl Visuals {
825832
collapsing_header_frame,
826833
} = self;
827834

835+
ui.collapsing("Background Colors", |ui| {
836+
ui_color(ui, &mut widgets.inactive.bg_fill, "Buttons");
837+
ui_color(ui, &mut widgets.noninteractive.bg_fill, "Windows");
838+
ui_color(ui, faint_bg_color, "Faint accent").on_hover_text(
839+
"Used for faint accentuation of interactive things, like striped grids.",
840+
);
841+
ui_color(ui, extreme_bg_color, "Extreme")
842+
.on_hover_text("Background of plots and paintings");
843+
});
844+
828845
ui.collapsing("Window", |ui| {
829846
// Common shortcuts
830847
ui_color(ui, &mut widgets.noninteractive.bg_fill, "Fill");
@@ -841,13 +858,19 @@ impl Visuals {
841858
&mut widgets.noninteractive.fg_stroke.color,
842859
"Text color",
843860
);
861+
ui_color(ui, code_bg_color, Label::new("Code background").code()).on_hover_ui(|ui| {
862+
ui.horizontal(|ui| {
863+
ui.spacing_mut().item_spacing.x = 0.0;
864+
ui.label("For monospaced inlined text ");
865+
ui.code("like this");
866+
ui.label(".");
867+
});
868+
});
844869

845-
ui_color(ui, extreme_bg_color, "extreme_bg_color");
846870
ui_color(ui, hyperlink_color, "hyperlink_color");
847-
ui_color(ui, code_bg_color, "code_bg_color");
848871
ui.add(Slider::new(resize_corner_size, 0.0..=20.0).text("resize_corner_size"));
849-
ui.add(Slider::new(text_cursor_width, 0.0..=2.0).text("text_cursor_width"));
850-
ui.checkbox(text_cursor_preview, "text_cursor_preview");
872+
ui.add(Slider::new(text_cursor_width, 0.0..=4.0).text("text_cursor_width"));
873+
ui.checkbox(text_cursor_preview, "Preview text cursor on hover");
851874
ui.add(Slider::new(clip_rect_margin, 0.0..=20.0).text("clip_rect_margin"));
852875

853876
ui.checkbox(button_frame, "Button has a frame");
@@ -905,9 +928,10 @@ fn slider_vec2<'a>(
905928
}
906929
}
907930

908-
fn ui_color(ui: &mut Ui, srgba: &mut Color32, text: &str) {
931+
fn ui_color(ui: &mut Ui, srgba: &mut Color32, text: impl Into<Label>) -> Response {
909932
ui.horizontal(|ui| {
910933
ui.color_edit_button_srgba(srgba);
911934
ui.label(text);
912-
});
935+
})
936+
.response
913937
}

0 commit comments

Comments
 (0)