Skip to content

Commit

Permalink
make text update lazier in tonemapping ex. try bevyengine#2
Browse files Browse the repository at this point in the history
  • Loading branch information
tigregalis committed May 8, 2023
1 parent bc44c0e commit b638d67
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions examples/3d/tonemapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,33 +471,32 @@ fn update_color_grading_settings(
}

fn update_ui(
mut text: Query<&mut Text, Without<SceneNumber>>,
mut text_query: Query<&mut Text, Without<SceneNumber>>,
settings: Query<(&Tonemapping, &ColorGrading)>,
current_scene: Res<CurrentScene>,
selected_parameter: Res<SelectedParameter>,
mut hide_ui: Local<bool>,
keys: Res<Input<KeyCode>>,
) {
let (method, color_grading) = settings.single();
let method = *method;

let mut text = text.single_mut();
let text = &mut text.sections[0].value;

if keys.just_pressed(KeyCode::H) {
*hide_ui = !*hide_ui;
}
text.clear();

let old_text = &text_query.single().sections[0].value;

if *hide_ui {
if !text_query.single().sections[0].value.is_empty() {
if !old_text.is_empty() {
// single_mut() always triggers change detection,
// so only access if text actually needs changing
text_query.single_mut().sections[0].value.clear();
}
return;
}

let mut text = String::with_capacity(text_query.single().sections[0].value.len());
let (method, color_grading) = settings.single();
let method = *method;

let mut text = String::with_capacity(old_text.len());

let scn = current_scene.0;
text.push_str("(H) Hide UI\n\n");
Expand Down Expand Up @@ -603,7 +602,7 @@ fn update_ui(
text.push_str("(Enter) Reset all to scene recommendation\n");
}

if text != text_query.single().sections[0].value {
if text != old_text.as_str() {
// single_mut() always triggers change detection,
// so only access if text actually changed
text_query.single_mut().sections[0].value = text;
Expand Down

0 comments on commit b638d67

Please sign in to comment.