0.11 Migration: What to use instead of `CalculatedSize`
In bevy 0.10, CalculatedSized used to have a size field representing the node's "calculated" size, ie: size before layout constraints (is my understanding)
This section of the migration guide describe that "CalculatedSize has been renamed to ContentSize".
However, there is no mention of what to use instead of size! ContentSize has a measure_func field I've no idea how to get back the value that previously was there!
It seems ContentSize was changed in https://github.com/bevyengine/bevy/pull/7779, the migration guide mentions UiImageSize, but I also need to know the content size for text nodes.
Very good question, I am running into the same issue as well.
It is impossible to access equivalent data in 0.11 for text. You need to manually compute it. Here is how you would do it.
/// Due to a regression in bevy 0.11, it is now impossible to access
/// text pre-layouting
fn create_text_measure(
fonts: Res<Assets<Font>>,
texts: Query<&Text>,
ui_scale: Res<UiScale>,
windows: Query<&Window, With<PrimaryWindow>>,
) {
let window_factor = windows.get_single().map(|w| w.resolution.scale_factor());
let window_factor = window_factor.unwrap_or(1.);
for text in &texts {
let Ok(measure) = TextPipeline::default().create_text_measure(
&fonts,
&text.sections,
ui_scale.scale * window_factor,
text.alignment,
text.linebreak_behavior,
) else {
continue;
};
measure.compute_size(/* Vec2::INFINITY if unbound */)
}
}
You might be worried about the TextPipeline::default().create_text_measure but worry not! the TextPipeline state isn't used in any way in create_text_measure