X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdropdown.cpp;h=ce0ba71f642c45ca7f672e4bf8e80f78d8fb60ed;hb=c8291177b545ec81930603a5915234a60296db51;hp=ee8ec55b7d1e8d46874e42deb82c947fa4d02ca4;hpb=df07e8f3e239b146cbc458d3cbd69758e590d255;p=libs%2Fgltk.git diff --git a/source/dropdown.cpp b/source/dropdown.cpp index ee8ec55..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")) @@ -63,16 +64,19 @@ void Dropdown::autosize() rebuild(); } -void Dropdown::rebuild_special(const Part &part, CachedPart &cache) +void Dropdown::set_selected_index(int index) +{ + list.set_selected_index(index); + if(index<0) + text.set(string()); +} + +void Dropdown::rebuild_special(const Part &part) { if(part.get_name()=="text") - { - int sel = list.get_selected_index(); - if(sel>=0) - Text(*style, list.get_data().get_string(sel)).build(part, geom, cache); - else - cache.texture = 0; - } + text.build(part, geom, part_cache); + else + Widget::rebuild_special(part); } void Dropdown::render_special(const Part &part, GL::Renderer &renderer) const @@ -108,6 +112,7 @@ void Dropdown::on_geometry_change() void Dropdown::on_style_change() { + text.set_style(style); resize_list(); } @@ -119,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; @@ -156,6 +161,8 @@ void Dropdown::list_item_selected(unsigned index) signal_ungrab_pointer.emit(); } + text.set(list.get_data().get_string(index)); + signal_item_selected.emit(index); rebuild(); }