]> git.tdb.fi Git - libs/gltk.git/blob - source/toggle.h
Improve widget part caching
[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 "text.h"
6 #include "widget.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 /**
12 Allows toggling a value between two states.
13 */
14 class Toggle: public Widget
15 {
16 public:
17         class Loader: public DataFile::DerivedObjectLoader<Toggle, Widget::Loader>
18         {
19         public:
20                 Loader(Toggle &);
21         private:
22                 virtual void finish();
23                 void text(const std::string &);
24         };
25
26         sigc::signal<void, bool> signal_toggled;
27
28 private:
29         Text text;
30         bool pressed;
31         bool value;
32         bool exclusive;
33
34 public:
35         Toggle(const std::string & = std::string());
36
37         virtual const char *get_class() const { return "toggle"; }
38
39         virtual void autosize();
40
41         void set_text(const std::string &);
42         void set_exclusive(bool);
43         bool get_exclusive() const { return exclusive; }
44 private:
45         void exclude_siblings();
46 public:
47         void set_value(bool);
48         bool get_value() const { return value; }
49
50 private:
51         virtual void rebuild_special(const Part &);
52
53 public:
54         virtual void button_press(int, int, unsigned);
55         virtual void button_release(int, int, unsigned);
56 private:
57         virtual void on_style_change();
58 };
59
60 } // namespace GLtk
61 } // namespace Msp
62
63 #endif