Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/egui/src/widget_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,17 @@ impl WidgetText {
) -> Arc<Galley> {
match self {
Self::Text(text) => {
let color = style
.visuals
.override_text_color
.unwrap_or(crate::Color32::PLACEHOLDER);
let mut layout_job = LayoutJob::simple_format(
text,
TextFormat {
// We want the style overrides to take precedence over the fallback font
font_id: FontSelection::default()
.resolve_with_fallback(style, fallback_font),
color: crate::Color32::PLACEHOLDER,
color,
valign: default_valign,
..Default::default()
},
Expand Down
30 changes: 30 additions & 0 deletions crates/egui_kittest/tests/regression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,33 @@ pub fn slider_should_move_with_fixed_decimals() {
let actual_slider = harness.get_by_role(accesskit::Role::SpinButton);
assert_eq!(actual_slider.value(), Some("1.00".to_owned()));
}

#[test]
pub fn override_text_color_affects_interactive_widgets() {
use egui::{Color32, RichText};

let mut harness = Harness::new_ui(|ui| {
_ = ui.button("normal");
_ = ui.checkbox(&mut true, "normal");
_ = ui.radio(true, "normal");
ui.visuals_mut().widgets.inactive.fg_stroke.color = Color32::RED;
_ = ui.button("red");
_ = ui.checkbox(&mut true, "red");
_ = ui.radio(true, "red");
// override_text_color takes precedence over `WidgetVisuals`, as it docstring claims
ui.visuals_mut().override_text_color = Some(Color32::GREEN);
_ = ui.button("green");
_ = ui.checkbox(&mut true, "green");
_ = ui.radio(true, "green");
// Setting the color explicitly with `RichText` overrides style
_ = ui.button(RichText::new("blue").color(Color32::BLUE));
_ = ui.checkbox(&mut true, RichText::new("blue").color(Color32::BLUE));
_ = ui.radio(true, RichText::new("blue").color(Color32::BLUE));
});

#[cfg(all(feature = "wgpu", feature = "snapshot"))]
let mut results = SnapshotResults::new();

#[cfg(all(feature = "wgpu", feature = "snapshot"))]
results.add(harness.try_snapshot("override_text_color_interactive"));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - thank you! ❤️

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading