1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00
serenity/LibGUI/GButton.h
Andreas Kling 57ff293a51 LibGUI: Implement nested event loops to support dialog boxes.
This patch adds a simple GMessageBox that can run in a nested event loop.
Here's how you use it:

    GMessageBox box("Message text here", "Message window title");
    int result = box.exec();

The next step is to make the WindowServer respect the modality flag of
these windows and prevent interaction with other windows in the same
process until the modal window has been closed.
2019-03-19 00:01:02 +01:00

43 lines
1.3 KiB
C++

#pragma once
#include <LibGUI/GWidget.h>
#include <LibGUI/GStyle.h>
#include <AK/AKString.h>
#include <AK/Function.h>
#include <SharedGraphics/GraphicsBitmap.h>
class GButton : public GWidget {
public:
explicit GButton(GWidget* parent);
virtual ~GButton() override;
String caption() const { return m_caption; }
void set_caption(const String&);
void set_icon(RetainPtr<GraphicsBitmap>&& icon) { m_icon = move(icon); }
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
GraphicsBitmap* icon() { return m_icon.ptr(); }
Function<void(GButton&)> on_click;
void set_button_style(GButtonStyle style) { m_button_style = style; }
GButtonStyle button_style() const { return m_button_style; }
virtual const char* class_name() const override { return "GButton"; }
private:
virtual void paint_event(GPaintEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
virtual void mouseup_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void enter_event(GEvent&) override;
virtual void leave_event(GEvent&) override;
String m_caption;
RetainPtr<GraphicsBitmap> m_icon;
GButtonStyle m_button_style { GButtonStyle::Normal };
bool m_being_pressed { false };
bool m_tracking_cursor { false };
bool m_hovered { false };
};