summaryrefslogtreecommitdiff
path: root/LibGUI/GButton.h
blob: 1e6d6dd3ab0cd095bb41830c3a1b39839756db42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once

#include "GWidget.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(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;

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 const char* class_name() const override { return "GButton"; }

    String m_caption;
    RetainPtr<GraphicsBitmap> m_icon;
    bool m_being_pressed { false };
    bool m_tracking_cursor { false };
};