diff options
author | Carlos César Neves Enumo <paker_wreah@hotmail.com> | 2021-08-14 17:35:38 -0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-15 12:24:57 +0200 |
commit | 51b3fb5532e6eb519213450a4cd502a3b05e23ff (patch) | |
tree | 4a99598fd0a18f1e2ef47e1d8438f4326f9b8d45 | |
parent | e26cfd313e61ebd26d1e0c7e71820f6c266be973 (diff) | |
download | serenity-51b3fb5532e6eb519213450a4cd502a3b05e23ff.zip |
Assistant: Bundle UI updates to avoid flickering
While typing, we get the results from each provider asynchronously.
Previously, we were updating the UI for each result size,
which was causing a lot of flickering.
This fix creates a small timer to bundle the results
and reduce the number of UI updates per input.
-rw-r--r-- | Userland/Applications/Assistant/main.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp index 50dd99b196..da0d825b72 100644 --- a/Userland/Applications/Assistant/main.cpp +++ b/Userland/Applications/Assistant/main.cpp @@ -285,13 +285,7 @@ int main(int argc, char** argv) GUI::Application::the()->quit(); }; - db.on_new_results = [&](auto results) { - if (results.is_empty()) - app_state.selected_index = {}; - else - app_state.selected_index = 0; - app_state.results = results; - app_state.visible_result_count = min(results.size(), MAX_SEARCH_RESULTS); + auto update_ui_timer = Core::Timer::create_single_shot(10, [&] { results_container.remove_all_children(); for (size_t i = 0; i < app_state.visible_result_count; ++i) { @@ -310,6 +304,17 @@ int main(int argc, char** argv) auto window_height = app_state.visible_result_count * 40 + text_box.height() + 28; window->resize(GUI::Desktop::the().rect().width() / 3, window_height); + }); + + db.on_new_results = [&](auto results) { + if (results.is_empty()) + app_state.selected_index = {}; + else + app_state.selected_index = 0; + app_state.results = results; + app_state.visible_result_count = min(results.size(), MAX_SEARCH_RESULTS); + + update_ui_timer->restart(); }; window->set_frameless(true); |