1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Add Visuals::error_fg_color and Visuals::warn_fg_color

This commit is contained in:
Emil Ernerfeldt
2022-07-29 15:32:32 +02:00
parent 8c09804abd
commit 2612dd1064
6 changed files with 28 additions and 10 deletions

View File

@@ -375,7 +375,7 @@ pub fn warn_if_debug_build(ui: &mut crate::Ui) {
ui.label(
RichText::new("‼ Debug build ‼")
.small()
.color(crate::Color32::RED),
.color(ui.visuals().warn_fg_color),
)
.on_hover_text("egui was compiled with debug assertions enabled.");
}

View File

@@ -219,7 +219,8 @@ impl Painter {
}
pub fn error(&self, pos: Pos2, text: impl std::fmt::Display) -> Rect {
self.debug_text(pos, Align2::LEFT_TOP, Color32::RED, format!("🔥 {}", text))
let color = self.ctx.style().visuals.error_fg_color;
self.debug_text(pos, Align2::LEFT_TOP, color, format!("🔥 {}", text))
}
/// text with a background

View File

@@ -446,6 +446,12 @@ pub struct Visuals {
/// Background color behind code-styled monospaced labels.
pub code_bg_color: Color32,
/// A good color for warning text (e.g. orange).
pub warn_fg_color: Color32,
/// A good color for error text (e.g. red).
pub error_fg_color: Color32,
pub window_rounding: Rounding,
pub window_shadow: Shadow,
@@ -669,6 +675,8 @@ impl Visuals {
faint_bg_color: Color32::from_gray(35),
extreme_bg_color: Color32::from_gray(10), // e.g. TextEdit background
code_bg_color: Color32::from_gray(64),
warn_fg_color: Color32::from_rgb(255, 143, 0), // orange
error_fg_color: Color32::from_rgb(255, 0, 0), // red
window_rounding: Rounding::same(6.0),
window_shadow: Shadow::big_dark(),
popup_shadow: Shadow::small_dark(),
@@ -691,6 +699,8 @@ impl Visuals {
faint_bg_color: Color32::from_gray(242),
extreme_bg_color: Color32::from_gray(255), // e.g. TextEdit background
code_bg_color: Color32::from_gray(230),
warn_fg_color: Color32::from_rgb(255, 0, 0), // red also, beecause orange doesn't look great because of https://github.com/emilk/egui/issues/1455
error_fg_color: Color32::from_rgb(255, 0, 0), // red
window_shadow: Shadow::big_light(),
popup_shadow: Shadow::small_light(),
..Self::dark()
@@ -1140,6 +1150,8 @@ impl Visuals {
faint_bg_color,
extreme_bg_color,
code_bg_color,
warn_fg_color,
error_fg_color,
window_rounding,
window_shadow,
popup_shadow,
@@ -1175,11 +1187,16 @@ impl Visuals {
ui.collapsing("Widgets", |ui| widgets.ui(ui));
ui.collapsing("Selection", |ui| selection.ui(ui));
ui_color(
ui,
&mut widgets.noninteractive.fg_stroke.color,
"Text color",
);
ui.horizontal(|ui| {
ui_color(
ui,
&mut widgets.noninteractive.fg_stroke.color,
"Text color",
);
ui_color(ui, warn_fg_color, RichText::new("Warnings"));
ui_color(ui, error_fg_color, RichText::new("Errors"));
});
ui_color(ui, code_bg_color, RichText::new("Code background").code()).on_hover_ui(|ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;