+List::Item::Item()
+{
+ input_type = INPUT_NAVIGATION;
+}
+
+void List::Item::autosize_special(const Part &part, Geometry &ageom) const
+{
+ if(part.get_name()=="children")
+ {
+ const Sides &margin = part.get_margin();
+ for(const Child *c: children)
+ {
+ Geometry cgeom;
+ c->widget->autosize(cgeom);
+ ageom.w = max(ageom.w, cgeom.x+cgeom.w+margin.right);
+ ageom.h = max(ageom.h, cgeom.y+cgeom.h+margin.top);
+ }
+ }
+}
+
+void List::Item::set_active(bool a)
+{
+ set_state(ACTIVE, (a ? ACTIVE : NORMAL));
+}
+
+void List::Item::render_special(const Part &part, GL::Renderer &renderer) const
+{
+ if(part.get_name()=="children")
+ {
+ for(const Child *c: children)
+ c->widget->render(renderer);
+ }
+}
+
+
+void List::SimpleItem::on_style_change()
+{
+ if(!style || children.empty())
+ return;
+
+ Widget *child = children.front()->widget;
+ child->autosize();
+ if(const Part *part = style->get_part("children"))
+ {
+ const Sides &margin = part->get_margin();
+ child->set_position(margin.left, margin.bottom);
+ }
+}
+
+
+void List::MultiColumnItem::check_widths(vector<unsigned> &widths) const
+{
+ if(widths.size()<children.size())
+ widths.resize(children.size(), 0);
+
+ unsigned n = 0;
+ for(const Child *c: children)
+ {
+ Geometry cgeom;
+ c->widget->autosize(cgeom);
+ // TODO invent a better way to specify spacings
+ widths[n] = max(widths[n], cgeom.w+8);
+ ++n;
+ }
+}
+
+void List::MultiColumnItem::set_widths(const vector<unsigned> &widths)
+{
+ if(!style)
+ return;
+
+ const Part *part = style->get_part("children");
+ if(!part)
+ return;
+
+ const Sides &margin = part->get_margin();
+ int x = margin.left;
+ unsigned n = 0;
+ for(const Child *c: children)
+ {
+ c->widget->set_position(x, margin.bottom);
+ x += widths[n++];
+ }
+}
+
+void List::MultiColumnItem::on_style_change()
+{
+ if(!style)
+ return;
+
+ for(const Child *c: children)
+ c->widget->autosize();
+
+ vector<unsigned> widths;
+ List *list = static_cast<List *>(parent);
+ for(Item *i: list->items)
+ if(i!=this)
+ if(MultiColumnItem *mci = dynamic_cast<MultiColumnItem *>(i))
+ mci->check_widths(widths);
+
+ vector<unsigned> self_widths(widths);
+ check_widths(self_widths);
+ bool update_all = false;
+ for(unsigned i=0; (!update_all && i<widths.size() && i<self_widths.size()); ++i)
+ update_all = self_widths[i]>widths[i];
+
+ if(update_all)
+ {
+ for(Item *i: list->items)
+ if(MultiColumnItem *mci = dynamic_cast<MultiColumnItem *>(i))
+ mci->set_widths(self_widths);
+ }
+
+ set_widths(self_widths);
+}
+
+
+List::BasicItem::BasicItem(const string &text):
+ label(text)
+{
+ add(label);
+}
+
+