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