Add method to RichText making it easier to construct layout jobs #3319
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3318
This refactors the existing code that was used inside
RichText.into_text_job()
to generate aLayoutJob
to also expose a method that appends to aLayoutJob
passed in from the outside. This makes it possible to construct aLayoutJob
using onlyRichText
s, without having to manually touchTextFormat
.In my code I added an extension method to UI (which didn't seem fitting for core egui) that looks like this:
which can be used like so:
This, in my opinion, is a much more ergonomic API that was available previously. Compare the above code to the code inside the linked #3318.
Note that the color of text must be specified in the RichText since
WidgetText.into_text_job()
always setsWidgetTextJob::job_has_color
to true when converting from a LayoutJob, or the text will show up as green.I'm not sure if this change is appropriate for core
egui
, but since it helped me, I thought I'd share and see.