Make it possible to read bevy-calculated ContentSize.#9112
Make it possible to read bevy-calculated ContentSize.#9112nicopap wants to merge 2 commits intobevyengine:mainfrom
ContentSize.#9112Conversation
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_funcinContentSizeby enum variants.ContentSize::measuremethod.setusage with directly setting the enumThe tradeoff is that users can't implement themselves
Measureanymore. Which might be a problem. An option is to provide a 4th variant with a trait object. It would make sense, sinceContentSizeends up turned into a trait object on use inui_layout_systemin any case.Migration Guide
ContentSize::setandMeasuredoesn't exist anymore. Instead, set its value directly.