X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdropdown.cpp;h=bcd501950a08aee01f584c925725717c5b83223b;hb=91997dd3189b93a67179822ec2fed5f2a7bddb74;hp=b911df370de3579e89d3430a8882362346071e14;hpb=0af3c2393bd00f39db3bfaf5b78a7a44f0fd5ff1;p=libs%2Fgltk.git diff --git a/source/dropdown.cpp b/source/dropdown.cpp index b911df3..bcd5019 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -18,16 +18,11 @@ using namespace std; namespace Msp { namespace GLtk { -Dropdown::Dropdown(const Resources &r): - Widget(r), - Container(r), - list(r), +Dropdown::Dropdown(): dropped(false) { add(list); list.signal_item_selected.connect(sigc::mem_fun(this, &Dropdown::list_item_selected)); - - update_style(); } void Dropdown::append(const string &item) @@ -110,20 +105,16 @@ void Dropdown::on_geometry_change() resize_list(); } +void Dropdown::on_style_change() +{ + resize_list(); +} + void Dropdown::resize_list() { - // XXX This is a hack. - unsigned n_items = list.get_n_items(); - const Style &stl = list.get_style(); - const GL::Font &font = *stl.get_font(); - unsigned h = min(max(n_items, 1U), 10U)*static_cast((font.get_ascent()-font.get_descent())*font.get_default_size()); - for(std::list::const_iterator i=stl.get_parts().begin(); i!=stl.get_parts().end(); ++i) - if(i->get_name()=="items") - { - const Sides &margin = i->get_margin(); - h += margin.top+margin.bottom; - } - list.set_geometry(Geometry(0, -h, geom.w, h)); + list.autosize(); + const Geometry &lgeom = list.get_geometry(); + list.set_geometry(Geometry(0, -lgeom.h, max(geom.w, lgeom.w), lgeom.h)); } void Dropdown::list_item_selected(unsigned index, const std::string &item)