1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 21:07:36 +00:00

LibGUI: Remove Button& parameter from Button::on_click hook

There was but a single user of this parameter and it's a bit tedious
to write it out every time, so let's get rid of it.
This commit is contained in:
Andreas Kling 2020-03-03 17:02:38 +01:00
parent b1d35248e4
commit a26b63a958
26 changed files with 60 additions and 55 deletions

View file

@ -118,7 +118,7 @@ int main(int argc, char** argv)
quit_button->set_text("Okay");
quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
quit_button->set_preferred_size(100, 20);
quit_button->on_click = [](GUI::Button&) {
quit_button->on_click = [] {
GUI::Application::the().quit(0);
};

View file

@ -85,7 +85,7 @@ CalculatorWidget::CalculatorWidget()
m_clear_button = add<GUI::Button>();
m_clear_button->set_foreground_color(Color::NamedColor::Red);
m_clear_button->set_text("C");
m_clear_button->on_click = [this](GUI::Button&) {
m_clear_button->on_click = [this] {
m_keypad.set_value(0.0);
m_calculator.clear_operation();
update_display();
@ -96,7 +96,7 @@ CalculatorWidget::CalculatorWidget()
m_clear_error_button = add<GUI::Button>();
m_clear_error_button->set_foreground_color(Color::NamedColor::Red);
m_clear_error_button->set_text("CE");
m_clear_error_button->on_click = [this](GUI::Button&) {
m_clear_error_button->on_click = [this] {
m_calculator.clear_error();
update_display();
};
@ -106,7 +106,7 @@ CalculatorWidget::CalculatorWidget()
m_backspace_button = add<GUI::Button>();
m_backspace_button->set_foreground_color(Color::NamedColor::Red);
m_backspace_button->set_text("Backspace");
m_backspace_button->on_click = [this](GUI::Button&) {
m_backspace_button->on_click = [this] {
m_keypad.type_backspace();
update_display();
};
@ -117,7 +117,7 @@ CalculatorWidget::CalculatorWidget()
m_decimal_point_button->move_to(133, 177);
m_decimal_point_button->set_foreground_color(Color::NamedColor::Blue);
m_decimal_point_button->set_text(".");
m_decimal_point_button->on_click = [this](GUI::Button&) {
m_decimal_point_button->on_click = [this] {
m_keypad.type_decimal_point();
update_display();
};
@ -175,7 +175,7 @@ CalculatorWidget::CalculatorWidget()
m_equals_button->move_to(211, 177);
m_equals_button->set_foreground_color(Color::NamedColor::Red);
m_equals_button->set_text("=");
m_equals_button->on_click = [this](GUI::Button&) {
m_equals_button->on_click = [this] {
double argument = m_keypad.value();
double res = m_calculator.finish_operation(argument);
m_keypad.set_value(res);
@ -191,7 +191,7 @@ CalculatorWidget::~CalculatorWidget()
void CalculatorWidget::add_button(GUI::Button& button, Calculator::Operation operation)
{
add_button(button);
button.on_click = [this, operation](GUI::Button&) {
button.on_click = [this, operation] {
double argument = m_keypad.value();
double res = m_calculator.begin_operation(operation, argument);
m_keypad.set_value(res);
@ -203,7 +203,7 @@ void CalculatorWidget::add_button(GUI::Button& button, int digit)
{
add_button(button);
button.set_text(String::number(digit));
button.on_click = [this, digit](GUI::Button&) {
button.on_click = [this, digit] {
m_keypad.type_digit(digit);
update_display();
};

View file

@ -193,7 +193,7 @@ void DisplayPropertiesWidget::create_frame()
apply_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
apply_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
apply_button->set_preferred_size(60, 22);
apply_button->on_click = [this, tab_widget](GUI::Button&) {
apply_button->on_click = [this, tab_widget] {
send_settings_to_window_server(tab_widget->active_tab_index());
};
@ -202,7 +202,7 @@ void DisplayPropertiesWidget::create_frame()
ok_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
ok_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
ok_button->set_preferred_size(60, 22);
ok_button->on_click = [this, tab_widget](GUI::Button&) {
ok_button->on_click = [this, tab_widget] {
send_settings_to_window_server(tab_widget->active_tab_index());
GUI::Application::the().quit();
};
@ -212,7 +212,7 @@ void DisplayPropertiesWidget::create_frame()
cancel_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
cancel_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
cancel_button->set_preferred_size(60, 22);
cancel_button->on_click = [](auto&) {
cancel_button->on_click = [] {
GUI::Application::the().quit();
};
}

View file

@ -139,11 +139,16 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
button_widget->layout()->add_spacer();
make_button("OK", button_widget)->on_click = [&](auto&) {if(apply_changes()) close(); };
make_button("Cancel", button_widget)->on_click = [&](auto&) { close(); };
make_button("OK", button_widget)->on_click = [this] {
if (apply_changes())
close();
};
make_button("Cancel", button_widget)->on_click = [this] {
close();
};
m_apply_button = make_button("Apply", button_widget);
m_apply_button->on_click = [&](auto&) { apply_changes(); };
m_apply_button->on_click = [this] { apply_changes(); };
m_apply_button->set_enabled(false);
update();

View file

@ -75,13 +75,13 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
};
m_ui->save_button->set_text("Save");
m_ui->save_button->on_click = [this](GUI::Button&) {
m_ui->save_button->on_click = [this] {
dbgprintf("write to file: '%s'\n", m_path.characters());
m_edited_font->write_to_file(m_path);
};
m_ui->quit_button->set_text("Quit");
m_ui->quit_button->on_click = [](auto&) {
m_ui->quit_button->on_click = [] {
exit(0);
};

View file

@ -107,7 +107,7 @@ SamplerWidget::SamplerWidget(AudioEngine& audio_engine)
m_open_button->set_preferred_size(24, 24);
m_open_button->set_focusable(false);
m_open_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"));
m_open_button->on_click = [this](const auto&) {
m_open_button->on_click = [this] {
Optional<String> open_path = GUI::FilePicker::get_open_filepath();
if (!open_path.has_value())
return;

View file

@ -81,14 +81,14 @@ SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<Audio::C
m_play = control_widget->add<GUI::Button>();
m_play->set_icon(*m_pause_icon);
m_play->set_enabled(false);
m_play->on_click = [this](GUI::Button& button) {
button.set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon);
m_play->on_click = [this] {
m_play->set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon);
};
m_stop = control_widget->add<GUI::Button>();
m_stop->set_enabled(false);
m_stop->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png"));
m_stop->on_click = [&](GUI::Button&) { m_manager.stop(); };
m_stop->on_click = [this] { m_manager.stop(); };
m_status = add<GUI::Label>();
m_status->set_frame_shape(Gfx::FrameShape::Box);

View file

@ -103,13 +103,13 @@ PowerDialog::PowerDialog()
button_box->layout()->set_spacing(8);
auto ok_button = button_box->add<GUI::Button>();
ok_button->on_click = [this](auto&) {
ok_button->on_click = [this] {
done(m_selected_option);
};
ok_button->set_text("OK");
auto cancel_button = button_box->add<GUI::Button>();
cancel_button->on_click = [this](auto&) {
cancel_button->on_click = [this] {
done(-1);
};
cancel_button->set_text("Cancel");

View file

@ -101,7 +101,7 @@ void TaskbarWindow::create_quick_launch_bar()
button->set_icon(Gfx::Bitmap::load_from_file(app_icon_path));
// FIXME: the tooltip ends up outside the screen rect.
button->set_tooltip(name);
button->on_click = [app_executable](auto&) {
button->on_click = [app_executable] {
pid_t pid = fork();
if (pid < 0) {
perror("fork");

View file

@ -50,7 +50,7 @@ Window& WindowList::ensure_window(const WindowIdentifier& identifier)
return *it->value;
auto window = make<Window>(identifier);
window->set_button(aid_create_button(identifier));
window->button()->on_click = [window = window.ptr(), identifier](auto&) {
window->button()->on_click = [window = window.ptr(), identifier] {
if (window->is_minimized() || !window->is_active()) {
GUI::WindowServerConnection::the().post_message(Messages::WindowServer::WM_SetActiveWindow(identifier.client_id(), identifier.window_id()));
} else {

View file

@ -37,8 +37,8 @@
#include <LibGUI/MessageBox.h>
#include <LibGUI/StackWidget.h>
#include <LibGUI/Window.h>
#include <LibGfx/Font.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font.h>
#include <stdio.h>
#include <unistd.h>
@ -249,7 +249,7 @@ int main(int argc, char** argv)
if (first)
menu_option->set_checked(true);
menu_option->on_click = [content = content.ptr(), &stack](auto&) {
menu_option->on_click = [content = content.ptr(), &stack] {
stack->set_active_widget(content);
content->invalidate_layout();
};