]> git.tdb.fi Git - libs/gltk.git/blob - source/toggle.h
Use the override specifier when overriding a virtual function
[libs/gltk.git] / source / toggle.h
1 #ifndef MSP_GLTK_TOGGLE_H_
2 #define MSP_GLTK_TOGGLE_H_
3
4 #include <sigc++/signal.h>
5 #include "mspgltk_api.h"
6 #include "text.h"
7 #include "widget.h"
8
9 namespace Msp {
10 namespace GLtk {
11
12 /**
13 Allows toggling a value between two states.
14 */
15 class MSPGLTK_API Toggle: public Widget
16 {
17 public:
18         class MSPGLTK_API Loader: public DataFile::DerivedObjectLoader<Toggle, Widget::Loader>
19         {
20         public:
21                 Loader(Toggle &);
22         private:
23                 void finish() override;
24                 void text(const std::string &);
25         };
26
27         sigc::signal<void, bool> signal_toggled;
28
29 private:
30         Text text;
31         bool pressed = false;
32         bool value = false;
33         bool exclusive = false;
34
35 public:
36         Toggle(const std::string & = std::string());
37
38         const char *get_class() const override { return "toggle"; }
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_exclusive(bool);
46         bool get_exclusive() const { return exclusive; }
47 private:
48         void exclude_siblings();
49 public:
50         void set_value(bool);
51         bool get_value() const { return value; }
52
53 private:
54         void rebuild_special(const Part &) override;
55
56 public:
57         void button_press(int, int, unsigned) override;
58         void button_release(int, int, unsigned) override;
59         bool navigate(Navigation) override;
60 private:
61         void on_style_change() override;
62 };
63
64 } // namespace GLtk
65 } // namespace Msp
66
67 #endif