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( ui.label(
RichText::new("‼ Debug build ‼") RichText::new("‼ Debug build ‼")
.small() .small()
.color(crate::Color32::RED), .color(ui.visuals().warn_fg_color),
) )
.on_hover_text("egui was compiled with debug assertions enabled."); .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 { 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 /// text with a background

View file

@ -446,6 +446,12 @@ pub struct Visuals {
/// Background color behind code-styled monospaced labels. /// Background color behind code-styled monospaced labels.
pub code_bg_color: Color32, 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_rounding: Rounding,
pub window_shadow: Shadow, pub window_shadow: Shadow,
@ -669,6 +675,8 @@ impl Visuals {
faint_bg_color: Color32::from_gray(35), faint_bg_color: Color32::from_gray(35),
extreme_bg_color: Color32::from_gray(10), // e.g. TextEdit background extreme_bg_color: Color32::from_gray(10), // e.g. TextEdit background
code_bg_color: Color32::from_gray(64), 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_rounding: Rounding::same(6.0),
window_shadow: Shadow::big_dark(), window_shadow: Shadow::big_dark(),
popup_shadow: Shadow::small_dark(), popup_shadow: Shadow::small_dark(),
@ -691,6 +699,8 @@ impl Visuals {
faint_bg_color: Color32::from_gray(242), faint_bg_color: Color32::from_gray(242),
extreme_bg_color: Color32::from_gray(255), // e.g. TextEdit background extreme_bg_color: Color32::from_gray(255), // e.g. TextEdit background
code_bg_color: Color32::from_gray(230), 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(), window_shadow: Shadow::big_light(),
popup_shadow: Shadow::small_light(), popup_shadow: Shadow::small_light(),
..Self::dark() ..Self::dark()
@ -1140,6 +1150,8 @@ impl Visuals {
faint_bg_color, faint_bg_color,
extreme_bg_color, extreme_bg_color,
code_bg_color, code_bg_color,
warn_fg_color,
error_fg_color,
window_rounding, window_rounding,
window_shadow, window_shadow,
popup_shadow, popup_shadow,
@ -1175,11 +1187,16 @@ impl Visuals {
ui.collapsing("Widgets", |ui| widgets.ui(ui)); ui.collapsing("Widgets", |ui| widgets.ui(ui));
ui.collapsing("Selection", |ui| selection.ui(ui)); ui.collapsing("Selection", |ui| selection.ui(ui));
ui_color( ui.horizontal(|ui| {
ui, ui_color(
&mut widgets.noninteractive.fg_stroke.color, ui,
"Text color", &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_color(ui, code_bg_color, RichText::new("Code background").code()).on_hover_ui(|ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0; ui.spacing_mut().item_spacing.x = 0.0;

View file

@ -95,7 +95,7 @@ impl eframe::App for HttpApp {
Err(error) => { Err(error) => {
// This should only happen if the fetch API isn't available or something similar. // This should only happen if the fetch API isn't available or something similar.
ui.colored_label( ui.colored_label(
egui::Color32::RED, ui.visuals().error_fg_color,
if error.is_empty() { "Error" } else { error }, if error.is_empty() { "Error" } else { error },
); );
} }

View file

@ -443,7 +443,7 @@ impl Tree {
fn children_ui(&mut self, ui: &mut Ui, depth: usize) -> Action { fn children_ui(&mut self, ui: &mut Ui, depth: usize) -> Action {
if depth > 0 if depth > 0
&& ui && ui
.button(RichText::new("delete").color(Color32::RED)) .button(RichText::new("delete").color(ui.visuals().warn_fg_color))
.clicked() .clicked()
{ {
return Action::Delete; return Action::Delete;

View file

@ -41,7 +41,7 @@ impl eframe::App for MyApp {
ui.spinner(); // still loading ui.spinner(); // still loading
} }
Some(Err(err)) => { 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)) => { Some(Ok(image)) => {
image.show_max_size(ui, ui.available_size()); image.show_max_size(ui, ui.available_size());