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()
29 geom.w = max(geom.w, list.get_geometry().w);
31 if(const Part *text_part = style->get_part("text"))
33 const Sides &margin = text_part->get_margin();
34 const GL::Font &font = style->get_font();
35 float font_size = style->get_font_size();
36 unsigned line_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font_size);
37 geom.h = max(geom.h, line_height+margin.top+margin.bottom);
43 void Dropdown::append(const string &item)
48 void Dropdown::insert(unsigned i, const string &v)
53 void Dropdown::remove(unsigned i)
58 void Dropdown::clear()
63 unsigned Dropdown::get_n_items() const
65 return list.get_n_items();
68 void Dropdown::set_selected_index(int i)
70 list.set_selected_index(i);
73 const string &Dropdown::get_selected() const
75 return list.get_selected();
78 int Dropdown::get_selected_index() const
80 return list.get_selected_index();
83 void Dropdown::rebuild_special(const Part &part, CachedPart &cache)
85 if(part.get_name()=="text")
87 if(list.get_selected_index()>=0)
88 Text(*style, list.get_selected()).build(part, geom, cache);
94 void Dropdown::render_special(const Part &part, GL::Renderer &renderer) const
96 if(part.get_name()=="list" && dropped)
97 list.render(renderer);
100 void Dropdown::button_press(int x, int y, unsigned btn)
104 Container::button_press(x, y, btn);
109 signal_ungrab_pointer.emit();
116 signal_grab_pointer.emit();
120 void Dropdown::on_geometry_change()
125 void Dropdown::on_style_change()
130 void Dropdown::list_autosize_changed()
133 signal_autosize_changed.emit();
136 void Dropdown::resize_list()
139 Geometry lgeom = list.get_geometry();
142 lgeom.w = max(geom.w, lgeom.w);
145 for(Widget *p=parent; p; p=p->get_parent())
147 root_x += p->get_geometry().x;
148 root_y += p->get_geometry().y;
149 if(Root *root = dynamic_cast<Root *>(p))
151 const Geometry &rgeom = root->get_geometry();
152 if(lgeom.h*2>rgeom.h)
156 if(root_y+lgeom.y+lgeom.h>rgeom.h)
157 lgeom.y = rgeom.h-lgeom.h-root_y;
158 if(root_x+lgeom.x+lgeom.w>rgeom.w)
159 lgeom.x = rgeom.w-lgeom.w-root_x;
163 list.set_geometry(lgeom);
166 void Dropdown::list_item_selected(unsigned index, const std::string &item)
172 signal_ungrab_pointer.emit();
175 signal_item_selected.emit(index, item);
179 Dropdown::Loader::Loader(Dropdown &d):
182 add("item", &Loader::item);
185 void Dropdown::Loader::item(const string &str)
187 dynamic_cast<Dropdown &>(obj).append(str);