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);
41 void Dropdown::append(const string &item)
46 void Dropdown::insert(unsigned i, const string &v)
51 void Dropdown::remove(unsigned i)
56 void Dropdown::clear()
61 unsigned Dropdown::get_n_items() const
63 return list.get_n_items();
66 void Dropdown::set_selected_index(int i)
68 list.set_selected_index(i);
71 const string &Dropdown::get_selected() const
73 return list.get_selected();
76 int Dropdown::get_selected_index() const
78 return list.get_selected_index();
81 void Dropdown::render_special(const Part &part) const
83 if(part.get_name()=="text")
85 if(list.get_selected_index()>=0)
86 Text(*style, list.get_selected()).render(part, geom);
88 else if(part.get_name()=="list" && dropped)
92 void Dropdown::button_press(int x, int y, unsigned btn)
96 Container::button_press(x, y, btn);
101 signal_ungrab_pointer.emit();
108 signal_grab_pointer.emit();
112 void Dropdown::on_geometry_change()
117 void Dropdown::on_style_change()
122 void Dropdown::list_autosize_changed()
125 signal_autosize_changed.emit();
128 void Dropdown::resize_list()
131 Geometry lgeom = list.get_geometry();
134 lgeom.w = max(geom.w, lgeom.w);
137 for(Widget *p=parent; p; p=p->get_parent())
139 root_x += p->get_geometry().x;
140 root_y += p->get_geometry().y;
141 if(Root *root = dynamic_cast<Root *>(p))
143 const Geometry &rgeom = root->get_geometry();
144 if(lgeom.h*2>rgeom.h)
148 if(root_y+lgeom.y+lgeom.h>rgeom.h)
149 lgeom.y = rgeom.h-lgeom.h-root_y;
150 if(root_x+lgeom.x+lgeom.w>rgeom.w)
151 lgeom.x = rgeom.w-lgeom.w-root_x;
155 list.set_geometry(lgeom);
158 void Dropdown::list_item_selected(unsigned index, const std::string &item)
164 signal_ungrab_pointer.emit();
167 signal_item_selected.emit(index, item);
171 Dropdown::Loader::Loader(Dropdown &d):
174 add("item", &Loader::item);
177 void Dropdown::Loader::item(const string &str)
179 dynamic_cast<Dropdown &>(obj).append(str);