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

Support line-height / letter-spacing in bevy_text #8781

Open
mattzque opened this issue Jun 7, 2023 · 3 comments
Open

Support line-height / letter-spacing in bevy_text #8781

mattzque opened this issue Jun 7, 2023 · 3 comments
Labels
A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible

Comments

@mattzque
Copy link

mattzque commented Jun 7, 2023

What problem does this solve or what need does it fill?

There seems to be no way to adjust the line spacing and letter spacing / glyph spacing. To make text more readable I'd like to increase the line height to 1.5, which is typically used to make longer paragraphs more readable.

What solution would you like?

Something similar to line-height(mdn) and letter-spacing (mdn) in CSS would be great. Ideally it should take the font size into account instead of just an absolute (logical) pixel value, but any way to adjust it would already be great.
Letter spacing would most likely be more challenging than line height, since it might affect line breaking and should be calculated before the line breaking occurs, but since they seem related I thought I make an issue about both.

What alternative(s) have you considered?

I don't see any way to achieve this myself since TextSection already implements line breaking I think it should handle this.
But perhaps there is a way to do this already?

Additional context

I believe the glyph positioning is calculated here:
https://github.com/bevyengine/bevy/blob/main/crates/bevy_text/src/glyph_brush.rs#L34
using the glyph_brush crate:
https://github.com/alexheretic/glyph-brush/blob/main/layout/src/builtin.rs#L135
There is also a related issue I found:
alexheretic/glyph-brush#132

I'm not sure if this is something we can adjust in bevy, given the calculated glyph information provided by glyph-brush or if this has to be added upstream first.

@mattzque mattzque added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jun 7, 2023
@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Jun 8, 2023
@ickshonpe
Copy link
Contributor

It's not hard at all to implement a basic version that just adds absolute space between lines.

I'm not quite sure what to do about a version that takes font size into account because a TextBundle can have multiple fonts. Perhaps it should just use the size of the largest font in the TextBundle.

Character spacing shouldn't be difficult either but might be better left until after the switch to Cosmic Text.

@ickshonpe
Copy link
Contributor

Just looked and Cosmic Text has built-in support for line-height. So this is something that should be included in Bevy 0.12.

@arendjr
Copy link
Contributor

arendjr commented Aug 26, 2023

I just noticed #7616 mentions implementing support for line height, which would be great. Hopefully letter-spacing can follow soon after, since it's practically impossible to implement designs using custom letter-spacing now.

@viridia viridia added the A-Text Rendering and layout for characters label Apr 18, 2024
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 A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

5 participants