From 2f917bcb9fb199cd5d4c519bc7d53c7cc2bc5b37 Mon Sep 17 00:00:00 2001 From: adrien <221212@umons.ac.be> Date: Wed, 12 Nov 2025 17:29:29 +0100 Subject: [PATCH] fix text color override --- crates/egui/src/style_trait.rs | 9 +++++++-- crates/egui/src/widgets/button.rs | 9 ++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/egui/src/style_trait.rs b/crates/egui/src/style_trait.rs index 66efc1def..424eea460 100644 --- a/crates/egui/src/style_trait.rs +++ b/crates/egui/src/style_trait.rs @@ -120,7 +120,10 @@ impl Style { }, stroke: visuals.fg_stroke, text: TextVisuals { - color: visuals.text_color(), + color: self + .visuals + .override_text_color + .unwrap_or(visuals.text_color()), font_id: font_id.unwrap_or(TextStyle::Body.resolve(self)), strikethrough: Stroke::NONE, underline: Stroke::NONE, @@ -131,12 +134,14 @@ impl Style { pub fn button_style(&self, state: WidgetState, selected: bool) -> ButtonStyle { let mut visuals = *self.visuals.widgets.state(state); let mut ws = self.widget_style(state); + if selected { visuals.weak_bg_fill = self.visuals.selection.bg_fill; visuals.bg_fill = self.visuals.selection.bg_fill; visuals.fg_stroke = self.visuals.selection.stroke; ws.text.color = self.visuals.selection.stroke.color; } + ButtonStyle { frame: Frame { fill: visuals.weak_bg_fill, @@ -189,7 +194,7 @@ impl Style { pub fn separator_style(&self, _state: WidgetState) -> SeparatorStyle { let visuals = self.visuals.noninteractive(); SeparatorStyle { - spacing: 0.0, + spacing: 6.0, stroke: visuals.bg_stroke, } } diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index cccef733c..8fc3e1a79 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -7,6 +7,7 @@ use crate::{ Image, IntoAtoms, NumExt as _, Response, RichText, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType, style_trait::{ButtonStyle, WidgetState}, + text_selection::visuals, }; /// Clickable button with text. @@ -338,7 +339,9 @@ impl<'a> Button<'a> { } WidgetText::RichText(mut text) => { let text_mut = Arc::make_mut(&mut text); - *text_mut = mem::take(text_mut).font(text_style.font_id.clone()); + *text_mut = mem::take(text_mut) + .font(text_style.font_id.clone()) + .color(text_style.color); WidgetText::RichText(text) } w => w, @@ -356,10 +359,10 @@ impl<'a> Button<'a> { // Get AtomLayoutResponse, empty if not visible let response = if ui.is_rect_visible(prepared.response.rect) { if image_tint_follows_text_color { - prepared.map_images(|image| image.tint(text_style.color)); + prepared.map_images(|image| image.tint(ui.visuals().text_color())); } - prepared.fallback_text_color = text_style.color; + prepared.fallback_text_color = ui.visuals().text_color(); prepared.paint(ui) } else {