summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LibGUI/GButton.cpp14
-rw-r--r--LibGUI/GButton.h6
-rw-r--r--Userland/guitest2.cpp37
3 files changed, 45 insertions, 12 deletions
diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp
index bc5511019e..59729e2e0d 100644
--- a/LibGUI/GButton.cpp
+++ b/LibGUI/GButton.cpp
@@ -11,7 +11,7 @@ GButton::~GButton()
{
}
-void GButton::setCaption(String&& caption)
+void GButton::set_caption(String&& caption)
{
if (caption == m_caption)
return;
@@ -32,7 +32,7 @@ void GButton::paintEvent(GPaintEvent&)
painter.draw_line({ 0, 1 }, { 0, height() - 2 }, Color::Black);
painter.draw_line({ width() - 1, 1 }, { width() - 1, height() - 2 }, Color::Black);
- if (m_beingPressed) {
+ if (m_being_pressed) {
// Base
painter.fill_rect({ 1, 1, width() - 2, height() - 2 }, buttonColor);
@@ -58,7 +58,7 @@ void GButton::paintEvent(GPaintEvent&)
if (!caption().is_empty()) {
auto textRect = rect();
- if (m_beingPressed)
+ if (m_being_pressed)
textRect.move_by(1, 1);
painter.draw_text(textRect, caption(), Painter::TextAlignment::Center, Color::Black);
}
@@ -68,7 +68,7 @@ void GButton::mouseDownEvent(GMouseEvent& event)
{
dbgprintf("Button::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
- m_beingPressed = true;
+ m_being_pressed = true;
update();
GWidget::mouseDownEvent(event);
@@ -78,12 +78,12 @@ void GButton::mouseUpEvent(GMouseEvent& event)
{
dbgprintf("Button::mouseUpEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
- m_beingPressed = false;
+ m_being_pressed = false;
update();
GWidget::mouseUpEvent(event);
- if (onClick)
- onClick(*this);
+ if (on_click)
+ on_click(*this);
}
diff --git a/LibGUI/GButton.h b/LibGUI/GButton.h
index 7d3e234f9f..78c73c23de 100644
--- a/LibGUI/GButton.h
+++ b/LibGUI/GButton.h
@@ -10,9 +10,9 @@ public:
virtual ~GButton() override;
String caption() const { return m_caption; }
- void setCaption(String&&);
+ void set_caption(String&&);
- Function<void(GButton&)> onClick;
+ Function<void(GButton&)> on_click;
private:
virtual void paintEvent(GPaintEvent&) override;
@@ -22,6 +22,6 @@ private:
virtual const char* class_name() const override { return "GButton"; }
String m_caption;
- bool m_beingPressed { false };
+ bool m_being_pressed { false };
};
diff --git a/Userland/guitest2.cpp b/Userland/guitest2.cpp
index ecc9b09166..0244d20e86 100644
--- a/Userland/guitest2.cpp
+++ b/Userland/guitest2.cpp
@@ -11,15 +11,20 @@
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GLabel.h>
+#include <LibGUI/GButton.h>
#include <LibGUI/GEventLoop.h>
static GWindow* make_font_test_window();
+static GWindow* make_launcher_window();
int main(int argc, char** argv)
{
GEventLoop loop;
- auto* window = make_font_test_window();
- window->show();
+ auto* font_test_window = make_font_test_window();
+ font_test_window->show();
+
+ auto* launcher_window = make_launcher_window();
+ launcher_window->show();
return loop.exec();
}
@@ -51,3 +56,31 @@ GWindow* make_font_test_window()
return window;
}
+
+GWindow* make_launcher_window()
+{
+ auto* window = new GWindow;
+ window->set_title("Launcher");
+ window->set_rect({ 100, 400, 80, 200 });
+
+ auto* widget = new GWidget;
+ window->set_main_widget(widget);
+ widget->setWindowRelativeRect({ 0, 0, 80, 200 });
+
+ auto* label = new GLabel(widget);
+ label->setWindowRelativeRect({ 0, 0, 80, 20 });
+ label->setText("Apps");
+
+ auto* button = new GButton(widget);
+ button->setWindowRelativeRect({ 5, 20, 70, 20 });
+ button->set_caption("Terminal");
+
+ button->on_click = [] (GButton&) {
+ if (!fork()) {
+ execve("/bin/Terminal", nullptr, nullptr);
+ ASSERT_NOT_REACHED();
+ }
+ };
+
+ return window;
+}