mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
fix text color override
This commit is contained in:
@@ -120,7 +120,10 @@ impl Style {
|
|||||||
},
|
},
|
||||||
stroke: visuals.fg_stroke,
|
stroke: visuals.fg_stroke,
|
||||||
text: TextVisuals {
|
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)),
|
font_id: font_id.unwrap_or(TextStyle::Body.resolve(self)),
|
||||||
strikethrough: Stroke::NONE,
|
strikethrough: Stroke::NONE,
|
||||||
underline: Stroke::NONE,
|
underline: Stroke::NONE,
|
||||||
@@ -131,12 +134,14 @@ impl Style {
|
|||||||
pub fn button_style(&self, state: WidgetState, selected: bool) -> ButtonStyle {
|
pub fn button_style(&self, state: WidgetState, selected: bool) -> ButtonStyle {
|
||||||
let mut visuals = *self.visuals.widgets.state(state);
|
let mut visuals = *self.visuals.widgets.state(state);
|
||||||
let mut ws = self.widget_style(state);
|
let mut ws = self.widget_style(state);
|
||||||
|
|
||||||
if selected {
|
if selected {
|
||||||
visuals.weak_bg_fill = self.visuals.selection.bg_fill;
|
visuals.weak_bg_fill = self.visuals.selection.bg_fill;
|
||||||
visuals.bg_fill = self.visuals.selection.bg_fill;
|
visuals.bg_fill = self.visuals.selection.bg_fill;
|
||||||
visuals.fg_stroke = self.visuals.selection.stroke;
|
visuals.fg_stroke = self.visuals.selection.stroke;
|
||||||
ws.text.color = self.visuals.selection.stroke.color;
|
ws.text.color = self.visuals.selection.stroke.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonStyle {
|
ButtonStyle {
|
||||||
frame: Frame {
|
frame: Frame {
|
||||||
fill: visuals.weak_bg_fill,
|
fill: visuals.weak_bg_fill,
|
||||||
@@ -189,7 +194,7 @@ impl Style {
|
|||||||
pub fn separator_style(&self, _state: WidgetState) -> SeparatorStyle {
|
pub fn separator_style(&self, _state: WidgetState) -> SeparatorStyle {
|
||||||
let visuals = self.visuals.noninteractive();
|
let visuals = self.visuals.noninteractive();
|
||||||
SeparatorStyle {
|
SeparatorStyle {
|
||||||
spacing: 0.0,
|
spacing: 6.0,
|
||||||
stroke: visuals.bg_stroke,
|
stroke: visuals.bg_stroke,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::{
|
|||||||
Image, IntoAtoms, NumExt as _, Response, RichText, Sense, Stroke, TextStyle, TextWrapMode, Ui,
|
Image, IntoAtoms, NumExt as _, Response, RichText, Sense, Stroke, TextStyle, TextWrapMode, Ui,
|
||||||
Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
|
Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
|
||||||
style_trait::{ButtonStyle, WidgetState},
|
style_trait::{ButtonStyle, WidgetState},
|
||||||
|
text_selection::visuals,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Clickable button with text.
|
/// Clickable button with text.
|
||||||
@@ -338,7 +339,9 @@ impl<'a> Button<'a> {
|
|||||||
}
|
}
|
||||||
WidgetText::RichText(mut text) => {
|
WidgetText::RichText(mut text) => {
|
||||||
let text_mut = Arc::make_mut(&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)
|
WidgetText::RichText(text)
|
||||||
}
|
}
|
||||||
w => w,
|
w => w,
|
||||||
@@ -356,10 +359,10 @@ impl<'a> Button<'a> {
|
|||||||
// Get AtomLayoutResponse, empty if not visible
|
// Get AtomLayoutResponse, empty if not visible
|
||||||
let response = if ui.is_rect_visible(prepared.response.rect) {
|
let response = if ui.is_rect_visible(prepared.response.rect) {
|
||||||
if image_tint_follows_text_color {
|
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)
|
prepared.paint(ui)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user