1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 21:00:03 -04:00

Replace a special Color32::PLACEHOLDER with widget fallback color (#3727)

This introduces a special `Color32::PLACEHOLDER` which, during text
painting, will be replaced with `TextShape::fallback_color`.

The fallback color is mandatory to set in all text painting. Usually
this comes from the current visual style.

This lets users color only parts of a `WidgetText` (using e.g. a
`LayoutJob` or a `Galley`), where the uncolored parts (using
`Color32::PLACEHOLDER`) will be replaced by a default widget color (e.g.
blue for a hyperlink).

For instance, you can color the `⚠️`-emoji red in a piece of text red
and leave the rest of the text uncolored. The color of the rest of the
text will then depend on wether or not you put that text in a label, a
button, or a hyperlink.

Overall this simplifies a lot of complexity in the code but comes with a
few breaking changes:

* `TextShape::new`, `Shape::galley`, and `Painter::galley` now take a
fallback color by argument
* `Shape::galley_with_color` has been deprecated (use `Shape::galley`
instead)
* `Painter::galley_with_color` has been deprecated (use
`Painter::galley` instead)
* `WidgetTextGalley` is gone (use `Arc<Galley>` instead)
* `WidgetTextJob` is gone (use `LayoutJob` instead)
* `RichText::into_text_job` has been replaced with
`RichText::into_layout_job`
* `WidgetText::into_text_job` has been replaced with
`WidgetText::into_layout_job`
This commit is contained in:
Emil Ernerfeldt
2023-12-22 15:09:10 +01:00
committed by GitHub
parent e36b981118
commit 0561fcaba9
23 changed files with 270 additions and 309 deletions

View File

@@ -732,11 +732,7 @@ impl PlotItem for Text {
.anchor
.anchor_rect(Rect::from_min_size(pos, galley.size()));
let mut text_shape = epaint::TextShape::new(rect.min, galley.galley);
if !galley.galley_has_color {
text_shape.override_text_color = Some(color);
}
shapes.push(text_shape.into());
shapes.push(epaint::TextShape::new(rect.min, galley, color).into());
if self.highlight {
shapes.push(Shape::rect_stroke(