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));
}
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"))
void Dropdown::resize_list()
{
- list.autosize_all();
+ list.autosize();
Geometry lgeom = list.get_geometry();
lgeom.x = 0;
lgeom.y = -lgeom.h;
sel_index = -1;
first = 0;
max_scroll = 0;
+ view_size = 5;
observer = new DataObserver(*this);
}
void List::autosize()
-{
- autosize_rows(5);
-}
-
-void List::autosize_rows(unsigned n)
{
if(!style)
return;
items[i]->autosize();
const Geometry &igeom = items[i]->get_geometry();
max_w = max(max_w, igeom.w);
- if(i<n)
+ if(view_size==0 || i<view_size)
total_h += igeom.h;
}
- if(!items.empty() && items.size()<n)
- total_h = total_h*n/items.size();
+ if(!items.empty() && items.size()<view_size)
+ total_h = total_h*view_size/items.size();
geom.w = max(geom.w, max_w+margin.left+margin.right);
geom.h = max(geom.h, total_h+margin.top+margin.bottom);
rebuild();
}
-void List::autosize_all()
-{
- autosize_rows(data->size());
-}
-
void List::set_data(ListData &d)
{
delete observer;
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<int>(data->size()))
int sel_index;
unsigned first;
unsigned max_scroll;
+ unsigned view_size;
VSlider slider;
std::vector<Item *> items;
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; }
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; }