Fix `override_text_color` priority (#7439)
The override_text_color is now used when rendering text from a String or &str. This is consistent with the RichText variant and makes the option behave as advertised, taking precedence over WidgetVisuals and overriding the color for all text unless explicitly changed for a single widget (via RichText or LayoutJob). * Closes <https://github.com/emilk/egui/issues/7367> * [x] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
c2de29a8de
commit
1937cc4d61
|
|
@ -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()
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:60540cb1b5b71f100b2ea367a939cb9d93a91e56ff1f14ebfc988bbe79d69ac7
|
||||
size 19719
|
||||
Loading…
Reference in New Issue