2019-01-20 04:49:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/AKString.h>
|
|
|
|
#include <AK/Function.h>
|
2019-05-24 16:32:20 +02:00
|
|
|
#include <LibGUI/GAbstractButton.h>
|
2019-02-07 23:13:47 +01:00
|
|
|
#include <SharedGraphics/GraphicsBitmap.h>
|
2019-05-24 16:32:20 +02:00
|
|
|
#include <SharedGraphics/StylePainter.h>
|
2019-04-04 14:15:57 +02:00
|
|
|
#include <SharedGraphics/TextAlignment.h>
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-04-12 02:53:27 +02:00
|
|
|
class GAction;
|
|
|
|
|
2019-05-24 16:32:20 +02:00
|
|
|
class GButton : public GAbstractButton {
|
2019-01-20 04:49:48 +01:00
|
|
|
public:
|
2019-06-02 14:58:02 +02:00
|
|
|
GButton(const StringView& text, GWidget* parent);
|
2019-01-20 04:49:48 +01:00
|
|
|
explicit GButton(GWidget* parent);
|
|
|
|
virtual ~GButton() override;
|
|
|
|
|
2019-04-13 16:59:55 +02:00
|
|
|
void set_icon(RetainPtr<GraphicsBitmap>&&);
|
2019-02-07 23:13:47 +01:00
|
|
|
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
|
|
|
GraphicsBitmap* icon() { return m_icon.ptr(); }
|
|
|
|
|
2019-04-04 14:15:57 +02:00
|
|
|
void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; }
|
|
|
|
TextAlignment text_alignment() const { return m_text_alignment; }
|
|
|
|
|
2019-01-21 00:31:11 +01:00
|
|
|
Function<void(GButton&)> on_click;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-03-28 17:32:38 +01:00
|
|
|
void set_button_style(ButtonStyle style) { m_button_style = style; }
|
|
|
|
ButtonStyle button_style() const { return m_button_style; }
|
2019-02-20 09:22:38 +01:00
|
|
|
|
2019-05-24 16:32:20 +02:00
|
|
|
virtual void click() override;
|
2019-03-19 01:41:00 +01:00
|
|
|
|
2019-04-12 02:53:27 +02:00
|
|
|
void set_action(GAction&);
|
|
|
|
|
2019-03-16 12:57:04 +01:00
|
|
|
virtual const char* class_name() const override { return "GButton"; }
|
2019-05-15 02:39:58 +02:00
|
|
|
virtual bool accepts_focus() const override { return true; }
|
2019-06-21 10:09:57 +02:00
|
|
|
virtual bool supports_keyboard_activation() const;
|
2019-03-16 12:57:04 +01:00
|
|
|
|
2019-04-13 03:08:16 +02:00
|
|
|
protected:
|
2019-01-21 00:46:08 +01:00
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-04-13 03:08:16 +02:00
|
|
|
private:
|
2019-02-07 23:13:47 +01:00
|
|
|
RetainPtr<GraphicsBitmap> m_icon;
|
2019-03-28 17:32:38 +01:00
|
|
|
ButtonStyle m_button_style { ButtonStyle::Normal };
|
2019-04-04 14:15:57 +02:00
|
|
|
TextAlignment m_text_alignment { TextAlignment::Center };
|
2019-04-12 02:53:27 +02:00
|
|
|
WeakPtr<GAction> m_action;
|
2019-01-20 04:49:48 +01:00
|
|
|
};
|