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

[bevy_text] Enable shifting text position within a Text component #14030

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zmbush
Copy link

@zmbush zmbush commented Jun 26, 2024

Objective

  • Make it possible to shift the position of text within Text to enable, for example, animations.

Solution

  • Add a Vec2 named offset to TextSection, which is added to the position of each glyph after the text layout.

Testing

  • Did some manual testing, I have been using this change in an in-development game for several weeks with good results.
  • Added usage of this feature to the ui/text example
text-animation-example.mp4

Changelog

Added

  • offset field to TextSection that will be added to the position of each glyph.

Migration Guide

  • TextSection now contains the field offset (defaults to Vec2(0.0, 0.0)), which may cause previously exhaustively specified TextSections to fail to compile.

Copy link
Contributor

Welcome, new contributor!

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

@zmbush zmbush force-pushed the bevy-text-offset branch 2 times, most recently from f36aa72 to 0c3b9b8 Compare June 26, 2024 05:12
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Text Rendering and layout for characters S-Blocked This cannot move forward until something else changes D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jun 26, 2024
@alice-i-cecile
Copy link
Member

Neat! I'm going to hold off on this until #10193 is merged: that should be mergeable soon and will interact with this.

@mockersf
Copy link
Member

how does different text sections interact when they have offsets? how does it interact with general layout?

@zmbush
Copy link
Author

zmbush commented Jun 26, 2024

how does different text sections interact when they have offsets? how does it interact with general layout?

The intention was that they would not interact at all, since the offsets would be added after typesetting inside of pipelime.rs. The idea was to enable text animations like the wavy text in Night in the Woods.

So you could use offsets to break the text outside of the text or UI layout

@alice-i-cecile alice-i-cecile added the X-Contentious There are nontrivial implications that should be thought through label Jun 26, 2024
@zmbush
Copy link
Author

zmbush commented Jul 3, 2024

I re-made this change on top of #10193. Looks like the implementation will be even simpler!

TotalKrill/bevy@cosmic-text...zmbush:text-offset-cosmic

I also added a usage example to the ui/text example

Recording.2024-07-03.164506.mp4

This makes it possible to shift text (such as for animations), while
still laying it out with `cosmic-text`.
@zmbush zmbush force-pushed the bevy-text-offset branch from 0c3b9b8 to b983261 Compare July 6, 2024 07:31
@zmbush
Copy link
Author

zmbush commented Jul 6, 2024

@alice-i-cecile I have rebased this on top of the committed cosmic-text PR.

Copy link
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.

This works fine and the implementation is simple enough but it's no good I think. Having an offset field per TextSection limits the sine wave example to one glpyh per TextSection. I would rather have the offsets stored per glyph if we go this way.

But ideally you don't want to retain the offsets at all. Better alternatives are to either write a custom extraction function that calculates each glyph's position from its index and the elapsed time. Or make a system like the text_wave_system in the example but rather than indirectly manipulating the positions using an offset field, just update the glyph positions stored in the TextLayoutInfo component directly.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Blocked This cannot move forward until something else changes labels Jul 9, 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 C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants