mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:07:35 +00:00
LibGUI: Include keyboard modifier state with button on_click calls
This will allow you us to implement special behavior when Ctrl+clicking a button.
This commit is contained in:
parent
3a905aed06
commit
977863ea07
37 changed files with 76 additions and 76 deletions
|
@ -117,7 +117,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 = [] {
|
||||
quit_button.on_click = [](auto) {
|
||||
GUI::Application::the().quit(0);
|
||||
};
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ BookmarksBarWidget::BookmarksBarWidget(const String& bookmarks_file, bool enable
|
|||
m_additional->set_text(">");
|
||||
m_additional->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_additional->set_preferred_size(14, 20);
|
||||
m_additional->on_click = [&] {
|
||||
m_additional->on_click = [this](auto) {
|
||||
if (m_additional_menu) {
|
||||
m_additional_menu->popup(m_additional->relative_position().translated(relative_position().translated(m_additional->window()->position())));
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ void BookmarksBarWidget::did_update_model()
|
|||
button.set_preferred_size(font().width(title) + 32, 20);
|
||||
button.set_relative_rect(rect);
|
||||
|
||||
button.on_click = [title, url, this] {
|
||||
button.on_click = [title, url, this](auto) {
|
||||
if (on_bookmark_click)
|
||||
on_bookmark_click(title, url);
|
||||
};
|
||||
|
@ -166,7 +166,7 @@ void BookmarksBarWidget::update_content_size()
|
|||
m_additional_menu->add_action(GUI::Action::create(bookmark.text(),
|
||||
Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"),
|
||||
[&](auto&) {
|
||||
bookmark.on_click();
|
||||
bookmark.on_click(0);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
#include <LibCore/File.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/ProgressBar.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibProtocol/Client.h>
|
||||
|
@ -106,7 +106,7 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
m_cancel_button = button_container.add<GUI::Button>("Cancel");
|
||||
m_cancel_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_cancel_button->set_preferred_size(100, 22);
|
||||
m_cancel_button->on_click = [this] {
|
||||
m_cancel_button->on_click = [this](auto) {
|
||||
bool success = m_download->stop();
|
||||
ASSERT(success);
|
||||
window()->close();
|
||||
|
@ -116,7 +116,7 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
m_close_button->set_enabled(false);
|
||||
m_close_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_close_button->set_preferred_size(100, 22);
|
||||
m_close_button->on_click = [this] {
|
||||
m_close_button->on_click = [this](auto) {
|
||||
window()->close();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ Tab::Tab()
|
|||
m_bookmark_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_bookmark_button->set_preferred_size(22, 22);
|
||||
|
||||
m_bookmark_button->on_click = [this] {
|
||||
m_bookmark_button->on_click = [this](auto) {
|
||||
auto url = m_html_widget->main_frame().document()->url().to_string();
|
||||
if (BookmarksBarWidget::the().contains_bookmark(url)) {
|
||||
BookmarksBarWidget::the().remove_bookmark(url);
|
||||
|
|
|
@ -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] {
|
||||
m_clear_button->on_click = [this](auto) {
|
||||
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] {
|
||||
m_clear_error_button->on_click = [this](auto) {
|
||||
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] {
|
||||
m_backspace_button->on_click = [this](auto) {
|
||||
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] {
|
||||
m_decimal_point_button->on_click = [this](auto) {
|
||||
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] {
|
||||
m_equals_button->on_click = [this](auto) {
|
||||
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] {
|
||||
button.on_click = [this, operation](auto) {
|
||||
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] {
|
||||
button.on_click = [this, digit](auto) {
|
||||
m_keypad.type_digit(digit);
|
||||
update_display();
|
||||
};
|
||||
|
|
|
@ -107,7 +107,7 @@ AddEventDialog::AddEventDialog(RefPtr<Calendar> calendar, Core::DateTime date_ti
|
|||
auto& ok_button = button_container.add<GUI::Button>("OK");
|
||||
ok_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
ok_button.set_preferred_size(80, 20);
|
||||
ok_button.on_click = [this] {
|
||||
ok_button.on_click = [this](auto) {
|
||||
dbg() << "TODO: Add event icon on specific tile";
|
||||
done(Dialog::ExecOK);
|
||||
};
|
||||
|
|
|
@ -64,7 +64,7 @@ CalendarWidget::CalendarWidget()
|
|||
m_prev_month_button->set_font(Gfx::Font::default_bold_font());
|
||||
m_prev_month_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_prev_month_button->set_preferred_size(40, 40);
|
||||
m_prev_month_button->on_click = [this] {
|
||||
m_prev_month_button->on_click = [this](auto) {
|
||||
int m_target_month = m_calendar->selected_month() - 1;
|
||||
int m_target_year = m_calendar->selected_year();
|
||||
|
||||
|
@ -79,7 +79,7 @@ CalendarWidget::CalendarWidget()
|
|||
m_next_month_button->set_font(Gfx::Font::default_bold_font());
|
||||
m_next_month_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_next_month_button->set_preferred_size(40, 40);
|
||||
m_next_month_button->on_click = [this] {
|
||||
m_next_month_button->on_click = [this](auto) {
|
||||
int m_target_month = m_calendar->selected_month() + 1;
|
||||
int m_target_year = m_calendar->selected_year();
|
||||
|
||||
|
@ -100,7 +100,7 @@ CalendarWidget::CalendarWidget()
|
|||
m_add_event_button = top_right_container.add<GUI::Button>("Add Event");
|
||||
m_add_event_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_add_event_button->set_preferred_size(100, 25);
|
||||
m_add_event_button->on_click = [this] {
|
||||
m_add_event_button->on_click = [this](auto) {
|
||||
show_add_event_window();
|
||||
};
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ void DisplaySettingsWidget::create_frame()
|
|||
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button.set_preferred_size(22, 22);
|
||||
button.on_click = [this]() {
|
||||
button.on_click = [this](auto) {
|
||||
Optional<String> open_path = GUI::FilePicker::get_open_filepath("Select wallpaper from file system.");
|
||||
|
||||
if (!open_path.has_value())
|
||||
|
@ -240,7 +240,7 @@ void DisplaySettingsWidget::create_frame()
|
|||
ok_button.set_text("OK");
|
||||
ok_button.set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
ok_button.set_preferred_size(60, 22);
|
||||
ok_button.on_click = [this] {
|
||||
ok_button.on_click = [this](auto) {
|
||||
send_settings_to_window_server();
|
||||
GUI::Application::the().quit();
|
||||
};
|
||||
|
@ -249,7 +249,7 @@ void DisplaySettingsWidget::create_frame()
|
|||
cancel_button.set_text("Cancel");
|
||||
cancel_button.set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
cancel_button.set_preferred_size(60, 22);
|
||||
cancel_button.on_click = [] {
|
||||
cancel_button.on_click = [](auto) {
|
||||
GUI::Application::the().quit();
|
||||
};
|
||||
|
||||
|
@ -257,7 +257,7 @@ void DisplaySettingsWidget::create_frame()
|
|||
apply_button.set_text("Apply");
|
||||
apply_button.set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
apply_button.set_preferred_size(60, 22);
|
||||
apply_button.on_click = [this] {
|
||||
apply_button.on_click = [this](auto) {
|
||||
send_settings_to_window_server();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -149,16 +149,16 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
|
||||
button_widget.layout()->add_spacer();
|
||||
|
||||
make_button("OK", button_widget).on_click = [this] {
|
||||
make_button("OK", button_widget).on_click = [this](auto) {
|
||||
if (apply_changes())
|
||||
close();
|
||||
};
|
||||
make_button("Cancel", button_widget).on_click = [this] {
|
||||
make_button("Cancel", button_widget).on_click = [this](auto) {
|
||||
close();
|
||||
};
|
||||
|
||||
m_apply_button = make_button("Apply", button_widget);
|
||||
m_apply_button->on_click = [this] { apply_changes(); };
|
||||
m_apply_button->on_click = [this](auto) { apply_changes(); };
|
||||
m_apply_button->set_enabled(false);
|
||||
|
||||
update();
|
||||
|
|
|
@ -219,7 +219,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
|
|||
save_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
save_button.set_preferred_size(80, 0);
|
||||
save_button.set_text("Save");
|
||||
save_button.on_click = [this] {
|
||||
save_button.on_click = [this](auto) {
|
||||
auto ret_val = m_edited_font->write_to_file(m_path);
|
||||
if (!ret_val) {
|
||||
GUI::MessageBox::show("The font file could not be saved.", "Save failed", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
|
||||
|
@ -230,7 +230,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
|
|||
quit_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
quit_button.set_preferred_size(80, 0);
|
||||
quit_button.set_text("Quit");
|
||||
quit_button.on_click = [this] {
|
||||
quit_button.on_click = [](auto) {
|
||||
exit(0);
|
||||
};
|
||||
|
||||
|
|
|
@ -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] {
|
||||
m_open_button->on_click = [this](auto) {
|
||||
Optional<String> open_path = GUI::FilePicker::get_open_filepath();
|
||||
if (!open_path.has_value())
|
||||
return;
|
||||
|
|
|
@ -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] {
|
||||
m_play->on_click = [this](auto) {
|
||||
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 = [this] { m_manager.stop(); };
|
||||
m_stop->on_click = [this](auto) { m_manager.stop(); };
|
||||
|
||||
m_status = add<GUI::Label>();
|
||||
m_status->set_frame_shape(Gfx::FrameShape::Box);
|
||||
|
|
|
@ -248,7 +248,7 @@ int main(int argc, char** argv)
|
|||
if (first)
|
||||
menu_option.set_checked(true);
|
||||
|
||||
menu_option.on_click = [content = &content, &stack] {
|
||||
menu_option.on_click = [content = &content, &stack](auto) {
|
||||
stack.set_active_widget(content);
|
||||
content->invalidate_layout();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue