-
-
Notifications
You must be signed in to change notification settings - Fork 4k
trigger Text
& Text2d
re-render when Children
is removed
#19666
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
base: main
Are you sure you want to change the base?
trigger Text
& Text2d
re-render when Children
is removed
#19666
Conversation
53732a5
to
2c91c80
Compare
Haha, I still want to come back to repair him today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As well the problems with using an observer, this won't work because the bug is recursive and it affects the Children
of TextSpan
entities too.
Maybe we should just give up on fine grained change detection for now, walk every TextSpan
entity building an ordered list of spans for each ComputedTextBlock
entity, and relayout if the list of spans or a TextSpan
's contents changes. I'm not sure.
/// Generic over the root text component and text span component. For example, | ||
/// [`Text2d`](crate::Text2d)/[`TextSpan`] for 2d or `Text`/[`TextSpan`] for UI. | ||
pub fn detect_text_needs_rerender_on_children_removed<Root: Component>( | ||
trigger: On<Remove, Children>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work I think, it's going to trigger and do a ComputedTextBlock
look up everytime any Children
component is despawned, not just those belonging to text entities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we explicitely observe entities that have Text
/Text2d
? I don't know if that dupplicates observer entities for every observed text root, I'm not sure it would be an issue either.
crates/bevy_text/src/text.rs
Outdated
/// [`Text2d`](crate::Text2d)/[`TextSpan`] for 2d or `Text`/[`TextSpan`] for UI. | ||
pub fn detect_text_needs_rerender_on_children_removed<Root: Component>( | ||
trigger: On<Remove, Children>, | ||
mut computed: Query<&mut ComputedTextBlock, With<Root>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same observer could update both root types. The discriminator also means that the observer is going to run twice every time any Children
component is removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll at least dedupplicate that first
I originally wished I could use a custom relation (e.g. |
I've come back to this, to try and handle any of |
2c91c80
to
86c0e30
Compare
86c0e30
to
4ee77c9
Compare
Objective
As of at least bevy 0.16.0, Removing
Children
from aText
Node would not be detected bybevy_text::text::detect_text_needs_rerender
, leading to rendering glitches (#19657). After pinning down the bug, the same happens withText2d
, assuming its docs are correct about its use ofTextSpan
(I didn't actually went down the rabbit hole a second time to make sure).Fixes #19657
Solution
On<Remove, Children>
, and query then setComputedTextBlock.needs_rerendering
if present.Testing