]> git.tdb.fi Git - libs/gltk.git/blob - source/toggle.h
Style and comment updates
[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
23         private:
24                 void finish() override;
25
26                 void text(const std::string &);
27         };
28
29         sigc::signal<void, bool> signal_toggled;
30
31 private:
32         Text text;
33         bool pressed = false;
34         bool value = false;
35         bool exclusive = false;
36
37 public:
38         Toggle(const std::string & = std::string());
39
40         const char *get_class() const override { return "toggle"; }
41
42 private:
43         void autosize_special(const Part &, Geometry &) const override;
44
45 public:
46         void set_text(const std::string &);
47         void set_exclusive(bool);
48         bool get_exclusive() const { return exclusive; }
49 private:
50         void exclude_siblings();
51 public:
52         void set_value(bool);
53         bool get_value() const { return value; }
54
55 private:
56         void rebuild_special(const Part &) override;
57
58 public:
59         void button_press(int, int, unsigned) override;
60         void button_release(int, int, unsigned) override;
61         bool navigate(Navigation) override;
62 private:
63         void on_style_change() override;
64 };
65
66 } // namespace GLtk
67 } // namespace Msp
68
69 #endif