1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

fix text color override

This commit is contained in:
adrien
2025-11-12 17:29:29 +01:00
parent 34bf318782
commit 2f917bcb9f
2 changed files with 13 additions and 5 deletions

View File

@@ -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,
}
}

View File

@@ -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 {