summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Widgets/Button.cpp3
-rw-r--r--Widgets/Button.h2
-rw-r--r--Widgets/Widget.h1
-rw-r--r--Widgets/test.cpp4
4 files changed, 10 insertions, 0 deletions
diff --git a/Widgets/Button.cpp b/Widgets/Button.cpp
index 9313ed143b..10ec97aa50 100644
--- a/Widgets/Button.cpp
+++ b/Widgets/Button.cpp
@@ -87,5 +87,8 @@ void Button::mouseUpEvent(MouseEvent& event)
update();
Widget::mouseUpEvent(event);
+
+ if (onClick)
+ onClick(*this);
}
diff --git a/Widgets/Button.h b/Widgets/Button.h
index 98c63596eb..09ad9e0458 100644
--- a/Widgets/Button.h
+++ b/Widgets/Button.h
@@ -11,6 +11,8 @@ public:
String caption() const { return m_caption; }
void setCaption(String&&);
+ std::function<void(Button&)> onClick;
+
private:
virtual void paintEvent(PaintEvent&) override;
virtual void mouseDownEvent(MouseEvent&) override;
diff --git a/Widgets/Widget.h b/Widgets/Widget.h
index d592e91375..e025dc3aed 100644
--- a/Widgets/Widget.h
+++ b/Widgets/Widget.h
@@ -5,6 +5,7 @@
#include "Rect.h"
#include "Color.h"
#include <AK/String.h>
+#include <functional>
class Window;
diff --git a/Widgets/test.cpp b/Widgets/test.cpp
index dab26bb5da..5e8f403779 100644
--- a/Widgets/test.cpp
+++ b/Widgets/test.cpp
@@ -63,6 +63,10 @@ int main(int argc, char** argv)
b->setWindowRelativeRect({ 0, 20, 100, 20 });
b->setCaption("Button");
+ b->onClick = [] (Button& button) {
+ printf("Button %p clicked!\n", &button);
+ };
+
auto* c = new CheckBox(widgetTestWindowWidget);
c->setWindowRelativeRect({ 0, 40, 100, 20 });
c->setCaption("CheckBox");