1 #include <msp/gl/font.h>
19 list.signal_item_selected.connect(sigc::mem_fun(this, &Dropdown::list_item_selected));
20 list.signal_autosize_changed.connect(sigc::mem_fun(this, &Dropdown::list_autosize_changed));
23 void Dropdown::autosize()
30 geom.w = max(geom.w, list.get_geometry().w);
32 if(const Part *text_part = style->get_part("text"))
34 const Sides &margin = text_part->get_margin();
35 const GL::Font &font = style->get_font();
36 float font_size = style->get_font_size();
37 unsigned line_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font_size);
38 geom.h = max(geom.h, line_height+margin.top+margin.bottom);
44 void Dropdown::append(const string &item)
49 void Dropdown::insert(unsigned i, const string &v)
54 void Dropdown::remove(unsigned i)
59 void Dropdown::clear()
64 unsigned Dropdown::get_n_items() const
66 return list.get_n_items();
69 void Dropdown::set_selected_index(int i)
71 list.set_selected_index(i);
74 const string &Dropdown::get_selected() const
76 return list.get_selected();
79 int Dropdown::get_selected_index() const
81 return list.get_selected_index();
84 void Dropdown::rebuild_special(const Part &part, CachedPart &cache)
86 if(part.get_name()=="text")
88 if(list.get_selected_index()>=0)
89 Text(*style, list.get_selected()).build(part, geom, cache);
95 void Dropdown::render_special(const Part &part, GL::Renderer &renderer) const
97 if(part.get_name()=="list" && dropped)
98 list.render(renderer);
101 void Dropdown::button_press(int x, int y, unsigned btn)
105 Container::button_press(x, y, btn);
110 signal_ungrab_pointer.emit();
117 signal_grab_pointer.emit();
121 void Dropdown::on_geometry_change()
126 void Dropdown::on_style_change()
131 void Dropdown::list_autosize_changed()
134 signal_autosize_changed.emit();
137 void Dropdown::resize_list()
140 Geometry lgeom = list.get_geometry();
143 lgeom.w = max(geom.w, lgeom.w);
146 for(Widget *p=parent; p; p=p->get_parent())
148 root_x += p->get_geometry().x;
149 root_y += p->get_geometry().y;
150 if(Root *root = dynamic_cast<Root *>(p))
152 const Geometry &rgeom = root->get_geometry();
153 if(lgeom.h*2>rgeom.h)
157 if(root_y+lgeom.y+lgeom.h>rgeom.h)
158 lgeom.y = rgeom.h-lgeom.h-root_y;
159 if(root_x+lgeom.x+lgeom.w>rgeom.w)
160 lgeom.x = rgeom.w-lgeom.w-root_x;
164 list.set_geometry(lgeom);
167 void Dropdown::list_item_selected(unsigned index, const std::string &item)
173 signal_ungrab_pointer.emit();
176 signal_item_selected.emit(index, item);
181 Dropdown::Loader::Loader(Dropdown &d):
184 add("item", &Loader::item);
187 void Dropdown::Loader::item(const string &str)
189 dynamic_cast<Dropdown &>(obj).append(str);