From 08edc872aabe7c8bb689c09d34a69114370e836d Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 14 Jun 2023 14:54:46 +0100 Subject: [PATCH] LibCore+Applications: Put timeout parameter first in `debounce()` This matches the parameter order for Core::Timer's factory methods, stops clang-format freaking out so much, and just seems nicer to me. :^) --- Userland/Applications/Assistant/main.cpp | 5 ++--- .../CharacterMap/CharacterSearchWidget.cpp | 2 +- Userland/Applications/PixelPaint/MainWidget.cpp | 10 ++++------ Userland/Applications/TextEditor/MainWidget.cpp | 5 ++--- Userland/Libraries/LibCore/Debounce.h | 2 +- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp index 483e45464c3..ecb372cce71 100644 --- a/Userland/Applications/Assistant/main.cpp +++ b/Userland/Applications/Assistant/main.cpp @@ -190,7 +190,7 @@ ErrorOr serenity_main(Main::Arguments arguments) } }; - text_box.on_change = Core::debounce([&]() { + text_box.on_change = Core::debounce(5, [&]() { { Threading::MutexLocker locker(app_state.lock); if (app_state.last_query == text_box.text()) @@ -200,8 +200,7 @@ ErrorOr serenity_main(Main::Arguments arguments) } db.search(text_box.text()); - }, - 5); + }); text_box.on_return_pressed = [&]() { if (!app_state.selected_index.has_value()) return; diff --git a/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp b/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp index 35803cf1d53..4d6e082a468 100644 --- a/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp @@ -62,7 +62,7 @@ CharacterSearchWidget::CharacterSearchWidget() m_search_input->on_up_pressed = [this] { m_results_table->move_cursor(GUI::AbstractView::CursorMovement::Up, GUI::AbstractView::SelectionUpdate::Set); }; m_search_input->on_down_pressed = [this] { m_results_table->move_cursor(GUI::AbstractView::CursorMovement::Down, GUI::AbstractView::SelectionUpdate::Set); }; - m_search_input->on_change = Core::debounce([this] { search(); }, 100); + m_search_input->on_change = Core::debounce(100, [this] { search(); }); m_results_table->horizontal_scrollbar().set_visible(false); m_results_table->set_column_headers_visible(false); diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 1de57f7c916..c4a3055cd62 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -1299,13 +1299,12 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr image) m_tab_widget->set_tab_title(image_editor, title); }; - image_editor.on_modified_change = Core::debounce([&](auto const modified) { + image_editor.on_modified_change = Core::debounce(100, [&](auto const modified) { m_tab_widget->set_tab_modified(image_editor, modified); update_window_modified(); m_histogram_widget->image_changed(); m_vectorscope_widget->image_changed(); - }, - 100); + }); image_editor.on_image_mouse_position_change = [&](auto const& mouse_position) { auto const& image_size = current_image_editor()->image().size(); @@ -1340,11 +1339,10 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr image) m_show_rulers_action->set_checked(show_rulers); }; - image_editor.on_scale_change = Core::debounce([this](float scale) { + image_editor.on_scale_change = Core::debounce(100, [this](float scale) { m_zoom_combobox->set_text(DeprecatedString::formatted("{}%", roundf(scale * 100))); current_image_editor()->update_tool_cursor(); - }, - 100); + }); image_editor.on_primary_color_change = [&](Color color) { m_palette_widget->set_primary_color(color); diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index 236773f2998..7e725578fc0 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -70,10 +70,9 @@ MainWidget::MainWidget() if (font_entry != "default") m_editor->set_font(Gfx::FontDatabase::the().get_by_name(font_entry)); - m_editor->on_change = Core::debounce([this] { + m_editor->on_change = Core::debounce(100, [this] { update_preview(); - }, - 100); + }); m_editor->on_modified_change = [this](bool modified) { window()->set_modified(modified); diff --git a/Userland/Libraries/LibCore/Debounce.h b/Userland/Libraries/LibCore/Debounce.h index e575a2a35af..d4a3fae8203 100644 --- a/Userland/Libraries/LibCore/Debounce.h +++ b/Userland/Libraries/LibCore/Debounce.h @@ -11,7 +11,7 @@ namespace Core { template -auto debounce(TFunction function, int timeout) +auto debounce(int timeout, TFunction function) { RefPtr timer; return [=](T... args) mutable {