]> git.tdb.fi Git - libs/gltk.git/blob - source/button.h
165ca4f8447d779a3b82ac05bd1180aa16512212
[libs/gltk.git] / source / button.h
1 #ifndef MSP_GLTK_BUTTON_H_
2 #define MSP_GLTK_BUTTON_H_
3
4 #include <sigc++/sigc++.h>
5 #include <msp/gl/texture2d.h>
6 #include "mspgltk_api.h"
7 #include "text.h"
8 #include "widget.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 /**
14 A clickable button widget.  Buttons can have a text label, which is displayed
15 in a spacial part "text".
16 */
17 class MSPGLTK_API Button: public Widget
18 {
19 public:
20         class MSPGLTK_API Loader: public DataFile::DerivedObjectLoader<Button, Widget::Loader>
21         {
22         public:
23                 Loader(Button &);
24         private:
25                 void text(const std::string &);
26         };
27
28         sigc::signal<void> signal_clicked;
29
30 private:
31         Text text;
32         const GL::Texture2D *icon = nullptr;
33         bool pressed = false;
34
35 public:
36         Button(const std::string & = std::string());
37
38         const char *get_class() const override { return "button"; }
39
40 private:
41         void autosize_special(const Part &, Geometry &) const override;
42
43 public:
44         void set_text(const std::string &);
45         void set_icon(const GL::Texture2D *);
46
47 private:
48         void rebuild_special(const Part &) override;
49
50 public:
51         void button_press(int, int, unsigned) override;
52         void button_release(int, int, unsigned) override;
53         void pointer_motion(int, int) override;
54         bool navigate(Navigation) override;
55 private:
56         void on_style_change() override;
57 };
58
59 } // namespace GLtk
60 } // namespace Msp
61
62 #endif