mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:27:46 +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
|
@ -85,7 +85,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
|
|||
auto& ok_button = button_container.add<Button>("OK");
|
||||
ok_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
ok_button.set_preferred_size(80, 20);
|
||||
ok_button.on_click = [this] {
|
||||
ok_button.on_click = [this](auto) {
|
||||
done(Dialog::ExecOK);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ void AbstractButton::mouseup_event(MouseEvent& event)
|
|||
m_being_pressed = false;
|
||||
update();
|
||||
if (was_being_pressed && !was_auto_repeating)
|
||||
click();
|
||||
click(event.modifiers());
|
||||
}
|
||||
Widget::mouseup_event(event);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ void AbstractButton::leave_event(Core::Event&)
|
|||
void AbstractButton::keydown_event(KeyEvent& event)
|
||||
{
|
||||
if (event.key() == KeyCode::Key_Return) {
|
||||
click();
|
||||
click(event.modifiers());
|
||||
event.accept();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
bool is_hovered() const { return m_hovered; }
|
||||
bool is_being_pressed() const { return m_being_pressed; }
|
||||
|
||||
virtual void click() = 0;
|
||||
virtual void click(unsigned modifiers = 0) = 0;
|
||||
virtual bool accepts_focus() const override { return true; }
|
||||
virtual bool is_uncheckable() const { return true; }
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ void Button::paint_event(PaintEvent& event)
|
|||
paint_text(painter, text_rect, font, text_alignment());
|
||||
}
|
||||
|
||||
void Button::click()
|
||||
void Button::click(unsigned modifiers)
|
||||
{
|
||||
if (!is_enabled())
|
||||
return;
|
||||
|
@ -96,7 +96,7 @@ void Button::click()
|
|||
set_checked(!is_checked());
|
||||
}
|
||||
if (on_click)
|
||||
on_click();
|
||||
on_click(modifiers);
|
||||
if (m_action)
|
||||
m_action->activate(this);
|
||||
}
|
||||
|
|
|
@ -47,12 +47,12 @@ public:
|
|||
void set_text_alignment(Gfx::TextAlignment text_alignment) { m_text_alignment = text_alignment; }
|
||||
Gfx::TextAlignment text_alignment() const { return m_text_alignment; }
|
||||
|
||||
Function<void()> on_click;
|
||||
Function<void(unsigned modifiers)> on_click;
|
||||
|
||||
void set_button_style(Gfx::ButtonStyle style) { m_button_style = style; }
|
||||
Gfx::ButtonStyle button_style() const { return m_button_style; }
|
||||
|
||||
virtual void click() override;
|
||||
virtual void click(unsigned modifiers = 0) override;
|
||||
|
||||
void set_action(Action&);
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ void CheckBox::paint_event(PaintEvent& event)
|
|||
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
|
||||
}
|
||||
|
||||
void CheckBox::click()
|
||||
void CheckBox::click(unsigned)
|
||||
{
|
||||
if (!is_enabled())
|
||||
return;
|
||||
|
|
|
@ -35,7 +35,7 @@ class CheckBox : public AbstractButton {
|
|||
public:
|
||||
virtual ~CheckBox() override;
|
||||
|
||||
virtual void click() override;
|
||||
virtual void click(unsigned modifiers = 0) override;
|
||||
|
||||
private:
|
||||
explicit CheckBox(const StringView& = {});
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
Function<void(const Color)> on_click;
|
||||
|
||||
protected:
|
||||
virtual void click() override;
|
||||
virtual void click(unsigned modifiers = 0) override;
|
||||
virtual void doubleclick_event(GUI::MouseEvent&) override;
|
||||
virtual void paint_event(PaintEvent&) override;
|
||||
|
||||
|
@ -136,7 +136,7 @@ void ColorPicker::build_ui()
|
|||
ok_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
ok_button.set_preferred_size(80, 0);
|
||||
ok_button.set_text("OK");
|
||||
ok_button.on_click = [this] {
|
||||
ok_button.on_click = [this](auto) {
|
||||
done(ExecOK);
|
||||
};
|
||||
|
||||
|
@ -144,7 +144,7 @@ void ColorPicker::build_ui()
|
|||
cancel_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
cancel_button.set_preferred_size(80, 0);
|
||||
cancel_button.set_text("Cancel");
|
||||
cancel_button.on_click = [this] {
|
||||
cancel_button.on_click = [this](auto) {
|
||||
done(ExecCancel);
|
||||
};
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ void ColorButton::paint_event(PaintEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void ColorButton::click()
|
||||
void ColorButton::click(unsigned)
|
||||
{
|
||||
if (on_click)
|
||||
on_click(m_color);
|
||||
|
|
|
@ -68,7 +68,7 @@ ComboBox::ComboBox()
|
|||
m_open_button = add<Button>();
|
||||
m_open_button->set_focusable(false);
|
||||
m_open_button->set_text("\xc3\xb7");
|
||||
m_open_button->on_click = [this] {
|
||||
m_open_button->on_click = [this](auto) {
|
||||
if (m_list_window->is_visible())
|
||||
close();
|
||||
else
|
||||
|
|
|
@ -216,7 +216,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
|
|||
cancel_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
cancel_button.set_preferred_size(80, 0);
|
||||
cancel_button.set_text("Cancel");
|
||||
cancel_button.on_click = [this] {
|
||||
cancel_button.on_click = [this](auto) {
|
||||
done(ExecCancel);
|
||||
};
|
||||
|
||||
|
@ -224,7 +224,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
|
|||
ok_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
ok_button.set_preferred_size(80, 0);
|
||||
ok_button.set_text(ok_button_name(m_mode));
|
||||
ok_button.on_click = [this] {
|
||||
ok_button.on_click = [this](auto) {
|
||||
on_file_return();
|
||||
};
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ void InputBox::build()
|
|||
m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_ok_button->set_preferred_size(0, 20);
|
||||
m_ok_button->set_text("OK");
|
||||
m_ok_button->on_click = [this] {
|
||||
m_ok_button->on_click = [this](auto) {
|
||||
dbgprintf("GUI::InputBox: OK button clicked\n");
|
||||
m_text_value = m_text_editor->text();
|
||||
done(ExecOK);
|
||||
|
@ -93,7 +93,7 @@ void InputBox::build()
|
|||
m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_cancel_button->set_preferred_size(0, 20);
|
||||
m_cancel_button->set_text("Cancel");
|
||||
m_cancel_button->on_click = [this] {
|
||||
m_cancel_button->on_click = [this](auto) {
|
||||
dbgprintf("GUI::InputBox: Cancel button clicked\n");
|
||||
done(ExecCancel);
|
||||
};
|
||||
|
|
|
@ -134,7 +134,7 @@ void MessageBox::build()
|
|||
button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
button.set_preferred_size(96, 0);
|
||||
button.set_text(label);
|
||||
button.on_click = [this, label, result] {
|
||||
button.on_click = [this, label, result](auto) {
|
||||
done(result);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -78,7 +78,7 @@ void RadioButton::for_each_in_group(Callback callback)
|
|||
});
|
||||
}
|
||||
|
||||
void RadioButton::click()
|
||||
void RadioButton::click(unsigned)
|
||||
{
|
||||
if (!is_enabled())
|
||||
return;
|
||||
|
|
|
@ -35,7 +35,7 @@ class RadioButton : public AbstractButton {
|
|||
public:
|
||||
virtual ~RadioButton() override;
|
||||
|
||||
virtual void click() override;
|
||||
virtual void click(unsigned modifiers = 0) override;
|
||||
|
||||
protected:
|
||||
explicit RadioButton(const StringView& text = {});
|
||||
|
|
|
@ -45,12 +45,12 @@ SpinBox::SpinBox()
|
|||
m_increment_button = add<Button>();
|
||||
m_increment_button->set_focusable(false);
|
||||
m_increment_button->set_text("\xc3\xb6");
|
||||
m_increment_button->on_click = [this] { set_value(m_value + 1); };
|
||||
m_increment_button->on_click = [this](auto) { set_value(m_value + 1); };
|
||||
m_increment_button->set_auto_repeat_interval(150);
|
||||
m_decrement_button = add<Button>();
|
||||
m_decrement_button->set_focusable(false);
|
||||
m_decrement_button->set_text("\xc3\xb7");
|
||||
m_decrement_button->on_click = [this] { set_value(m_value - 1); };
|
||||
m_decrement_button->on_click = [this](auto) { set_value(m_value - 1); };
|
||||
m_decrement_button->set_auto_repeat_interval(150);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue