From 51b3fb5532e6eb519213450a4cd502a3b05e23ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20C=C3=A9sar=20Neves=20Enumo?= Date: Sat, 14 Aug 2021 17:35:38 -0300 Subject: [PATCH] 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. --- Userland/Applications/Assistant/main.cpp | 19 ++++++++++++------- 1 file 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);