From: Mikko Rasa Date: Wed, 26 Jun 2013 11:24:08 +0000 (+0300) Subject: Add a persistent view size attribute to List X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=commitdiff_plain;h=c8291177b545ec81930603a5915234a60296db51 Add a persistent view size attribute to List --- diff --git a/source/dropdown.cpp b/source/dropdown.cpp index ddf5c92..ce0ba71 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -28,6 +28,7 @@ void Dropdown::init() dropped = false; add(list); + list.set_view_all(); list.signal_item_selected.connect(sigc::mem_fun(this, &Dropdown::list_item_selected)); list.signal_autosize_changed.connect(sigc::mem_fun(this, &Dropdown::list_autosize_changed)); } @@ -38,7 +39,7 @@ void Dropdown::autosize() return; Widget::autosize(); - list.autosize_all(); + list.autosize(); geom.w = max(geom.w, list.get_geometry().w); if(const Part *text_part = style->get_part("text")) @@ -123,7 +124,7 @@ void Dropdown::list_autosize_changed() void Dropdown::resize_list() { - list.autosize_all(); + list.autosize(); Geometry lgeom = list.get_geometry(); lgeom.x = 0; lgeom.y = -lgeom.h; diff --git a/source/list.cpp b/source/list.cpp index 710d1fc..c74af90 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -31,6 +31,7 @@ void List::init() sel_index = -1; first = 0; max_scroll = 0; + view_size = 5; observer = new DataObserver(*this); @@ -47,11 +48,6 @@ List::~List() } void List::autosize() -{ - autosize_rows(5); -} - -void List::autosize_rows(unsigned n) { if(!style) return; @@ -69,12 +65,12 @@ void List::autosize_rows(unsigned n) items[i]->autosize(); const Geometry &igeom = items[i]->get_geometry(); max_w = max(max_w, igeom.w); - if(isize()); -} - void List::set_data(ListData &d) { delete observer; @@ -114,6 +105,17 @@ List::Item *List::create_item(unsigned index) return new BasicItem(data->get_string(index)); } +void List::set_view_size(unsigned s) +{ + view_size = s; + signal_autosize_changed.emit(); +} + +void List::set_view_all() +{ + set_view_size(0); +} + void List::set_selected_index(int i) { if(i>static_cast(data->size())) diff --git a/source/list.h b/source/list.h index 561e388..dd44f3b 100644 --- a/source/list.h +++ b/source/list.h @@ -76,6 +76,7 @@ private: int sel_index; unsigned first; unsigned max_scroll; + unsigned view_size; VSlider slider; std::vector items; @@ -91,8 +92,6 @@ public: virtual const char *get_class() const { return "list"; } virtual void autosize(); - void autosize_rows(unsigned); - void autosize_all(); void set_data(ListData &); ListData &get_data() { return *data; } @@ -101,7 +100,10 @@ private: void items_changed(); protected: virtual Item *create_item(unsigned); + public: + void set_view_size(unsigned); + void set_view_all(); void set_selected_index(int); int get_selected_index() const { return sel_index; }