Skip to content

add coloring per text section in gizmos#23120

Merged
alice-i-cecile merged 4 commits intobevyengine:mainfrom
nuts-rice:main
Mar 1, 2026
Merged

add coloring per text section in gizmos#23120
alice-i-cecile merged 4 commits intobevyengine:mainfrom
nuts-rice:main

Conversation

@nuts-rice
Copy link
Copy Markdown
Contributor

@nuts-rice nuts-rice commented Feb 23, 2026

Objective

Solution

  • Add StrokeTextLayout::render_with_color_fn() to return polyline and color pairing
  • Add text_sections() to build concat string consisting of sections of character-coloring pair
  • Associated helper fn for yielding tuple of (char, Color)
  • replace text field in StrokeTextLayout with sections that is an iterable &'a [(&'a str, Color)]

Testing

  • Ran cargo test for gizmos
  • Prolly could use an example

Showcase

Example Usage:

gizmos.text_sections(iso, [
      ("Hello ", Color::WHITE),
      ("World!", Color::srgb(1., 0., 0.)),
  ], 25., Vec2::ZERO);

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Gizmos Visual editor and debug gizmos A-Text Rendering and layout for characters S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 23, 2026
@alice-i-cecile alice-i-cecile added this to the 0.19 milestone Feb 23, 2026
Copy link
Copy Markdown
Contributor

@ickshonpe ickshonpe left a comment

Choose a reason for hiding this comment

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

Yeah this is pretty good, the only problem is the extra allocations, which should be avoidable if StrokeTextLayout's text: &str field is replaced with a slice or iterator. Then make a function, something like:

fn colored_chars(s: &[(&str, Color)]) -> impl Iterator<Item = (char, Color)> {
    s.into_iter()
        .map(|(t, color)| t.chars().map(|c| (c, *color)))
        .flatten()
}

that maps the sections to an iterator that yields the individual chars and their colors for rendering.

Comment thread crates/bevy_gizmos/src/stroke_text.rs
Comment thread crates/bevy_gizmos/src/stroke_text.rs Outdated
Comment thread crates/bevy_gizmos/src/stroke_text.rs Outdated
@ickshonpe
Copy link
Copy Markdown
Contributor

Sorry was really tired last night and my review comments were kind of rambling, hopefully you get the idea though.

@nuts-rice
Copy link
Copy Markdown
Contributor Author

you're alright, gonna resolve them soon

@ickshonpe ickshonpe added the M-Release-Note Work that should be called out in the blog due to impact label Feb 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

Copy link
Copy Markdown
Contributor

@ickshonpe ickshonpe left a comment

Choose a reason for hiding this comment

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

Looks good now, everything seems to work:

success

Just needs the text_gizmos.md release note to be updated to include these changes, and I think the uncolored render function should be removed as not useful.

Comment thread crates/bevy_gizmos/src/stroke_text.rs Outdated
Comment thread crates/bevy_gizmos/src/stroke_text.rs Outdated
Comment thread release-content/release-notes/text_gizmos.md Outdated
Comment thread release-content/release-notes/text_gizmos.md Outdated
@nuts-rice nuts-rice force-pushed the main branch 2 times, most recently from ccf1541 to ed05f64 Compare February 24, 2026 23:47
@kfc35 kfc35 self-requested a review March 1, 2026 18:36
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

I didn’t spot any problems

You can update your PR description if you’d like to remove the mention of the specialized render_with_color_fn function which has since been removed

@kfc35 kfc35 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 1, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 1, 2026
Merged via the queue into bevyengine:main with commit 7769758 Mar 1, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Gizmos Visual editor and debug gizmos A-Text Rendering and layout for characters C-Feature A new feature, making something new possible M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bevy_gizmos: Multicolored text support.

4 participants