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

Replace the local text queues in the text systems with flags stored in a component #8549

Merged
merged 22 commits into from
May 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a8a820c
Use a single query instead of a `ParamSet` for `measure_text_system`
ickshonpe May 5, 2023
dfca89c
Replaced the `ParamSet` parameter with a single query in `text_system`.
ickshonpe May 5, 2023
4e1ade4
cargo fmt --all
ickshonpe May 5, 2023
9a424c7
The change detection predicate was checking for `!queued_text.contain…
ickshonpe May 5, 2023
b0620d0
removed left over debug variable
ickshonpe May 5, 2023
686e109
Renamed the `Local` parameter `queued_text` to `text_queue` in `measu…
ickshonpe May 5, 2023
baece54
fixed imports
ickshonpe May 5, 2023
d69d8ca
Renamed `new_queue` to `new_text_queue`.
ickshonpe May 5, 2023
6e93578
changes:
ickshonpe May 5, 2023
85eb848
* Added check to filter unchanged Text in `measure_text_system`.
ickshonpe May 5, 2023
7309bac
Remove the text queue from `text_system` and use the `TextFlags` comp…
ickshonpe May 5, 2023
de73323
* cargo fmt --all,
ickshonpe May 5, 2023
90427f2
Don't recompute text that needs a remeasure.
ickshonpe May 5, 2023
aca22ab
cargo fmy
ickshonpe May 5, 2023
253ec5d
fixed text flags for full remeasure
ickshonpe May 5, 2023
05eaf9d
Moved duplicate code from `measure_text_system` and `text_system` int…
ickshonpe May 5, 2023
396a59c
formatting
ickshonpe May 5, 2023
b0aa6d9
Added `TextFlags` doc comments explaining it is for internal use.
ickshonpe May 5, 2023
dc3e846
cargo fmt
ickshonpe May 5, 2023
9c2f299
Fixes for `too_many_arguments` and `needless_borrow` lints.
ickshonpe May 5, 2023
a4a3f65
Renamed the `remeasure` field of `TextFlags` to `generate_measure_func`
ickshonpe May 7, 2023
caf6c79
Renamings for `TextFlags` fields:
ickshonpe May 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Renamings for TextFlags fields:
* `generate_measure_func` -> `needs_new_measure_func`
* `recompute` -> `needs_recompute`
  • Loading branch information
ickshonpe committed May 8, 2023
commit caf6c7901730d1f24b4d1612fc2a36a4d030fca8
24 changes: 12 additions & 12 deletions crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ fn scale_value(value: f32, factor: f64) -> f32 {
#[reflect(Component, Default)]
pub struct TextFlags {
/// If set a new measure function for the text node will be created
generate_measure_func: bool,
needs_new_measure_func: bool,
/// If set the text will be recomputed
recompute: bool,
needs_recompute: bool,
}

impl Default for TextFlags {
fn default() -> Self {
Self {
generate_measure_func: true,
recompute: true,
needs_new_measure_func: true,
needs_recompute: true,
}
}
}
Expand Down Expand Up @@ -98,12 +98,12 @@ fn create_text_measure(
content_size.set(TextMeasure { info: measure });

// Text measure func created succesfully, so set `TextFlags` to schedule a recompute
text_flags.generate_measure_func = false;
text_flags.recompute = true;
text_flags.needs_new_measure_func = false;
text_flags.needs_recompute = true;
}
Err(TextError::NoSuchFont) => {
// Try again next frame
text_flags.generate_measure_func = true;
text_flags.needs_new_measure_func = true;
}
Err(e @ TextError::FailedToAddGlyph(_)) => {
panic!("Fatal error when processing text: {e}.");
Expand Down Expand Up @@ -132,7 +132,7 @@ pub fn measure_text_system(
if *last_scale_factor == scale_factor {
// scale factor unchanged, only create new measure funcs for modified text
for (text, content_size, text_flags) in text_query.iter_mut() {
if text.is_changed() || text_flags.generate_measure_func {
if text.is_changed() || text_flags.needs_new_measure_func {
create_text_measure(
&fonts,
&mut text_pipeline,
Expand Down Expand Up @@ -177,7 +177,7 @@ fn queue_text(
mut text_layout_info: Mut<TextLayoutInfo>,
) {
// Skip the text node if it is waiting for a new measure func
if !text_flags.generate_measure_func {
if !text_flags.needs_new_measure_func {
let node_size = Vec2::new(
scale_value(node.size().x, scale_factor),
scale_value(node.size().y, scale_factor),
Expand All @@ -199,14 +199,14 @@ fn queue_text(
) {
Err(TextError::NoSuchFont) => {
// There was an error processing the text layout, try again next frame
text_flags.recompute = true;
text_flags.needs_recompute = true;
}
Err(e @ TextError::FailedToAddGlyph(_)) => {
panic!("Fatal error when processing text: {e}.");
}
Ok(info) => {
*text_layout_info = info;
text_flags.recompute = false;
text_flags.needs_recompute = false;
}
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn text_system(
if *last_scale_factor == scale_factor {
// Scale factor unchanged, only recompute text for modified text nodes
for (node, text, text_layout_info, text_flags) in text_query.iter_mut() {
if node.is_changed() || text_flags.recompute {
if node.is_changed() || text_flags.needs_recompute {
queue_text(
&fonts,
&mut text_pipeline,
Expand Down