]> git.tdb.fi Git - libs/gltk.git/blob - source/list.h
Use a GL::Renderer to render widgets
[libs/gltk.git] / source / list.h
1 #ifndef MSP_GLTK_LIST_H_
2 #define MSP_GLTK_LIST_H_
3
4 #include <sigc++/signal.h>
5 #include "container.h"
6 #include "vslider.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 /**
12 Shows a list of items, allowing the user to select one.  A slider is included
13 to allow scrolling through a long list.
14 */
15 class List: virtual public Widget, private Container
16 {
17 public:
18         class Loader: public Widget::Loader
19         {
20         public:
21                 Loader(List &);
22         private:
23                 void item(const std::string &);
24         };
25
26         sigc::signal<void, unsigned, const std::string &> signal_item_selected;
27
28 private:
29         std::vector<std::string> items;
30         int sel_index;
31         unsigned first;
32         unsigned n_visible;
33         unsigned row_height;
34
35         const Part *items_part;
36
37         VSlider slider;
38
39 public:
40         List();
41
42         virtual const char *get_class() const { return "list"; }
43
44         virtual void autosize();
45         void autosize_rows(unsigned);
46         void autosize_all();
47
48         void append(const std::string &);
49         void insert(unsigned, const std::string &);
50         void remove(unsigned);
51         void clear();
52 private:
53         void items_changed();
54 public:
55         unsigned get_n_items() const { return items.size(); }
56
57         void set_selected_index(int);
58         const std::string &get_selected() const;
59         int get_selected_index() const { return sel_index; }
60
61 private:
62         virtual void rebuild_special(const Part &, CachedPart &);
63         virtual void render_special(const Part &, GL::Renderer &) const;
64
65 public:
66         virtual void button_press(int, int, unsigned);
67 private:
68         virtual void on_geometry_change();
69         virtual void on_style_change();
70
71         void reposition_slider();
72         void check_view_range();
73         void slider_value_changed(double);
74 };
75
76 } // namespace GLtk
77 } // namespace Msp
78
79 #endif