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));
}
-void Dropdown::autosize()
+void Dropdown::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
- list.autosize_all();
- geom.w = max(geom.w, list.get_geometry().w);
-
- if(const Part *text_part = style->get_part("text"))
+ if(part.get_name()=="list")
{
- const Sides &margin = text_part->get_margin();
+ list.autosize();
+ ageom.w = max(ageom.w, list.get_geometry().w);
+ }
+ else if(part.get_name()=="text")
+ {
+ const Sides &margin = part.get_margin();
const GL::Font &font = style->get_font();
float font_size = style->get_font_size();
unsigned w = static_cast<unsigned>(font.get_string_width(data.get_string(i))*font_size);
max_w = max(max_w, w);
}
- geom.w = max(geom.w, max_w+margin.left+margin.right);
+ ageom.w = max(ageom.w, max_w+margin.left+margin.right);
unsigned line_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font_size);
- geom.h = max(geom.h, line_height+margin.top+margin.bottom);
+ ageom.h = max(ageom.h, line_height+margin.top+margin.bottom);
}
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
void Dropdown::on_style_change()
{
+ text.set_style(style);
resize_list();
}
void Dropdown::resize_list()
{
- list.autosize_all();
+ list.autosize();
Geometry lgeom = list.get_geometry();
lgeom.x = 0;
lgeom.y = -lgeom.h;
signal_ungrab_pointer.emit();
}
+ text.set(list.get_data().get_string(index));
+
signal_item_selected.emit(index);
rebuild();
}
Dropdown::Loader::Loader(Dropdown &d):
- Widget::Loader(d)
+ DataFile::DerivedObjectLoader<Dropdown, Widget::Loader>(d)
{
add("item", &Loader::item);
}
void Dropdown::Loader::item(const string &v)
{
- dynamic_cast<BasicListData<string> &>(dynamic_cast<Dropdown &>(obj).list.get_data()).append(v);
+ dynamic_cast<BasicListData<string> &>(obj.list.get_data()).append(v);
}
} // namespace GLtk