diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 45b3f56d..f0a09725 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -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."); } diff --git a/egui/src/painter.rs b/egui/src/painter.rs index 89d29f80..af835be7 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -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 diff --git a/egui/src/style.rs b/egui/src/style.rs index 81e41132..37b20d6a 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -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; diff --git a/egui_demo_app/src/apps/http_app.rs b/egui_demo_app/src/apps/http_app.rs index cd551de5..df92e748 100644 --- a/egui_demo_app/src/apps/http_app.rs +++ b/egui_demo_app/src/apps/http_app.rs @@ -95,7 +95,7 @@ impl eframe::App for HttpApp { Err(error) => { // This should only happen if the fetch API isn't available or something similar. ui.colored_label( - egui::Color32::RED, + ui.visuals().error_fg_color, if error.is_empty() { "Error" } else { error }, ); } diff --git a/egui_demo_lib/src/demo/misc_demo_window.rs b/egui_demo_lib/src/demo/misc_demo_window.rs index 07ca8e14..85cdaff6 100644 --- a/egui_demo_lib/src/demo/misc_demo_window.rs +++ b/egui_demo_lib/src/demo/misc_demo_window.rs @@ -443,7 +443,7 @@ impl Tree { fn children_ui(&mut self, ui: &mut Ui, depth: usize) -> Action { if depth > 0 && ui - .button(RichText::new("delete").color(Color32::RED)) + .button(RichText::new("delete").color(ui.visuals().warn_fg_color)) .clicked() { return Action::Delete; diff --git a/examples/download_image/src/main.rs b/examples/download_image/src/main.rs index eb7d31cb..4922956c 100644 --- a/examples/download_image/src/main.rs +++ b/examples/download_image/src/main.rs @@ -41,7 +41,7 @@ impl eframe::App for MyApp { ui.spinner(); // still loading } Some(Err(err)) => { - ui.colored_label(egui::Color32::RED, err); // something went wrong + ui.colored_label(ui.visuals().error_fg_color, err); // something went wrong } Some(Ok(image)) => { image.show_max_size(ui, ui.available_size());