-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Make it possible to read bevy-calculated ContentSize
.
#9112
base: main
Are you sure you want to change the base?
Conversation
Objective ------ - `bevy_text/src/pipeline.rs` had some crufty code. Solution ------ Remove the cruft. - `&mut self` argument was unused by `TextPipeline::create_text_measure`, so we replace it with a constructor `TextMeasureInfo::from_text`. - We also pass a `&Text` to `from_text` since there is no reason to split the struct before passing it as argument. - from_text also checks beforehand that every Font exist in the Assets<Font>. This allows rust to skip the drop code on the Vecs we create in the method, since there is no early exit. - We also remove the scaled_fonts field on `TextMeasureInfo`. This avoids an additional allocation. We can re-use the font on `fonts` instead in `compute_size`. Building a `ScaledFont` seems fairly cheap, when looking at the ab_glyph internals. - We also implement ToSectionText on TextMeasureSection, this let us skip creating a whole new Vec each time we call compute_size. - This let us remove compute_size_from_section_text, since its only purpose was to not have to allocate the Vec we just made redundant. - Make some immutabe `Vec<T>` into `Box<[T]>` and `String` into `Box<str>` The `ResMut<TextPipeline>` argument to `measure_text_system` doesn't exist anymore. If you were calling this system manually, you should remove the argument.
My thoughts:
|
So I also needed to expose a way to manipulate ContentSize in cuicui_layout. My solution involves using a SystemParam trait. I've used this style of API several times now (also in ui-navigation) but it's not established in bevy itself. It's very onerous right now, it's probably possible to simplify it, but I spent a considerable amount of time trying to satisfy the rust type system already. |
Just been thinking about this again after working on #9341. Maybe there are advantages to |
Objective
Make it possible to read bevy-calculated
ContentSize
.It can be useful to access the pre-layout content size. For example when integrating a different layout engine into bevy. It was previously possible, but #7779 made it impossible, it now requires ad-hoc redundant evaluation.
Although, maybe it's useful for other things as well? See bevyengine/bevy-website#701
Solution
measure_func
inContentSize
by enum variants.ContentSize::measure
method.set
usage with directly setting the enumThe tradeoff is that users can't implement themselves
Measure
anymore. Which might be a problem. An option is to provide a 4th variant with a trait object. It would make sense, sinceContentSize
ends up turned into a trait object on use inui_layout_system
in any case.Migration Guide
ContentSize::set
andMeasure
doesn't exist anymore. Instead, set its value directly.