Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Dec 22, 2023

Conversation

emilk
Copy link
Owner

@emilk emilk commented Dec 22, 2023

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

@emilk emilk merged commit 0561fca into master Dec 22, 2023
35 checks passed
@emilk emilk deleted the emilk/fallback-color branch December 22, 2023 14:09
/// i.e. often taken to mean "no color".
pub const PLACEHOLDER: Color32 = Color32::from_rgba_premultiplied(64, 254, 0, 128);

#[deprecated = "Renmaed to PLACEHOLDER"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Misprint: Renamed. Strange, why wasn't catched by CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants