]> git.tdb.fi Git - libs/gltk.git/blob - source/toggle.h
Cache widget parts in meshes
[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 Widget::Loader
18         {
19         public:
20                 Loader(Toggle &);
21                 Toggle &get_object() const;
22         private:
23                 virtual void finish();
24                 void text(const std::string &);
25         };
26
27         sigc::signal<void, bool> signal_toggled;
28
29 private:
30         Text text;
31         bool pressed;
32         bool value;
33         bool exclusive;
34
35 public:
36         Toggle(const std::string & = std::string());
37
38         virtual const char *get_class() const { return "toggle"; }
39
40         virtual void autosize();
41
42         void set_text(const std::string &);
43         void set_exclusive(bool);
44         bool get_exclusive() const { return exclusive; }
45 private:
46         void exclude_siblings();
47 public:
48         void set_value(bool);
49         bool get_value() const { return value; }
50
51 private:
52         virtual void rebuild_special(const Part &, CachedPart &);
53
54 public:
55         virtual void button_press(int, int, unsigned);
56         virtual void button_release(int, int, unsigned);
57 private:
58         virtual void on_style_change();
59 };
60
61 } // namespace GLtk
62 } // namespace Msp
63
64 #endif