Skip to content

Support letter spacing in bevy_text#23380

Merged
alice-i-cecile merged 18 commits intobevyengine:mainfrom
gregcsokas:support-letter-spacing-in-bevy_text
Mar 18, 2026
Merged

Support letter spacing in bevy_text#23380
alice-i-cecile merged 18 commits intobevyengine:mainfrom
gregcsokas:support-letter-spacing-in-bevy_text

Conversation

@gregcsokas
Copy link
Copy Markdown
Contributor

@gregcsokas gregcsokas commented Mar 16, 2026

Objective

Solution

Connects Bevy's text pipeline to parley's built-in letter spacing support,
mirroring the approach used for LineHeight.
Rem and percentage-based sizing are not yet implemented.

Testing

  • Added a letter_spacing example that visually validates the feature.
  • Fixed AABB-related tests for text2d.
  • Reviewers can run: cargo run --example letter_spacing
  • Works like LineHeight, but currently only supports Px().
  • Note: letter spacing is currently a required field —
    open to making it optional if that's preferred.

Showcase

cargo run --example letter_spacing

Or here is a video about it:

Kooha-2026-03-16-10-14-23.webm

@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 ✨

@gregcsokas gregcsokas changed the title Support letter spacing in bevy text Support letter spacing in bevy_text Mar 16, 2026
@kfc35 kfc35 added C-Feature A new feature, making something new possible A-Text Rendering and layout for characters S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Mar 16, 2026
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 checked out the branch and it works as advertised — the example looks good too.

I don’t see any problems with the code.

Comment thread crates/bevy_text/src/text.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs
Comment thread examples/ui/text/letter_spacing.rs Outdated
Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
/// Default is 0
#[derive(Component, Debug, Clone, Copy, PartialEq, Reflect)]
#[reflect(Component, Debug, Clone, PartialEq)]
pub enum LetterSpacing {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Follow-up (or this PR if you want): support LetterSpacing::RelativeToFont, like in LineHeight.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Happy to add it! Though I'm not sure what the semantics should be — CSS only supports
absolute values for letter-spacing, unlike line-height which has a natural
relative meaning.

Based on MDN, letter-spacing supports the following values:

  • normal (default) — not applicable in a game engine context since there is no user-agent
  • <length> — absolute units like px, em, rem
  • <percentage> — relative to the font's space character width, which would require
    font-dependent calculations and is probably best left as a follow-up

So Em and Rem variants seem like a reasonable addition. Happy to implement those
if that's what you had in mind!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems reasonable to have a setting based on the font size, if you increase the font size you'd probably want the spacing to increase commensurately as well.

But I really think we should just merge this as is and add any responsive size support in a follow up. There are lots of changes we need to make and the anon tuples and queries could make the merge conflicts quite painful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh didn't see that you'd already added rem support, that's fine too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could also add vw and vh variants, they might be useful if someone wants to have a title with the letters spread out across the window. But leave it for a follow up, we should get this merged asap.

Comment thread crates/bevy_text/src/text.rs Outdated
Comment thread crates/bevy_text/src/pipeline.rs
Comment thread crates/bevy_text/src/text.rs Outdated
Comment thread crates/bevy_text/src/pipeline.rs
Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Very sensible: this is a nice feature and you've wired it into parley cleanly. There's a bit of cleanup to do, and I think you've forgotten to account for scale-factor here.

Ping me for re-review when that's fixed up :)

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, I don't see any problems apart from a few errors in the doc comments. The example is really nice.

Okay to just support pixel coords for the initial PR, we can add more options in a followup.

Comment thread crates/bevy_text/src/text.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
Comment thread examples/ui/text/letter_spacing.rs Outdated
@ickshonpe ickshonpe added the M-Release-Note Work that should be called out in the blog due to impact label Mar 17, 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.

@ickshonpe
Copy link
Copy Markdown
Contributor

ickshonpe commented Mar 17, 2026

Should have a release note as well. Maybe rename new_font_features.md to new new_text_features.md and add it somewhere there?

Comment thread release-content/release-notes/new_font_features.md Outdated
@ickshonpe ickshonpe 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 17, 2026
Comment thread release-content/release-notes/new_font_features.md Outdated
gregcsokas and others added 2 commits March 17, 2026 13:29
Comment thread crates/bevy_text/src/pipeline.rs Outdated
@gregcsokas
Copy link
Copy Markdown
Contributor Author

@alice-i-cecile ping :)

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 18, 2026
Merged via the queue into bevyengine:main with commit 71cfd3e Mar 18, 2026
42 checks passed
@arendjr
Copy link
Copy Markdown
Contributor

arendjr commented Mar 18, 2026

Thank you so much for implementing this!

@alice-i-cecile will this be available in the next Bevy minor, or will this be for 0.19?

@kfc35
Copy link
Copy Markdown
Contributor

kfc35 commented Mar 18, 2026

@arendjr This should be available in 0.19! I don’t think Bevy at this time adds new features like this to patch releases

github-merge-queue Bot pushed a commit that referenced this pull request Mar 18, 2026
@arendjr
Copy link
Copy Markdown
Contributor

arendjr commented Mar 19, 2026

Thank you!

splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
# Objective

- Implements the `LetterSpacing` feature from issue bevyengine#8781, the
`LineHeight` is already implemented.

## Solution

Connects Bevy's text pipeline to `parley`'s built-in letter spacing
support,
mirroring the approach used for `LineHeight`.
`Rem` and percentage-based sizing are not yet implemented.

## Testing

- Added a `letter_spacing` example that visually validates the feature.
- Fixed AABB-related tests for `text2d`.
- Reviewers can run: `cargo run --example letter_spacing`
- Works like `LineHeight`, but currently only supports `Px()`.
- Note: letter spacing is currently a required field —
  open to making it optional if that's preferred.

## Showcase

`cargo run --example letter_spacing`


Or here is a video about it:


[Kooha-2026-03-16-10-14-23.webm](https://github.com/user-attachments/assets/3d778bd0-c8bc-43d3-b61b-14ae23c3b906)

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
Co-authored-by: ickshonpe <david.curthoys@googlemail.com>
splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Text Rendering and layout for characters C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes 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.

5 participants