void Dropdown::resize_list()
{
- // XXX This is a hack.
- unsigned n_items = list.get_n_items();
- const Style &stl = list.get_style();
- const GL::Font &font = *stl.get_font();
- unsigned h = min(max(n_items, 1U), 10U)*static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
- if(const Part *items_part = stl.get_part("items"))
- {
- const Sides &margin = items_part->get_margin();
- h += margin.top+margin.bottom;
- }
- list.set_geometry(Geometry(0, -h, geom.w, h));
+ list.autosize();
+ const Geometry &lgeom = list.get_geometry();
+ list.set_geometry(Geometry(0, -lgeom.h, max(geom.w, lgeom.w), lgeom.h));
}
void Dropdown::list_item_selected(unsigned index, const std::string &item)
{
text = t;
edit_pos = text.size();
+
+ if(multiline)
+ check_view_range();
}
void Entry::set_multiline(bool m)
{
multiline = m;
- if(multiline && !slider)
+ if(multiline)
{
- slider = new VSlider(res);
- add(*slider);
- slider->set_step(1);
- slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed));
- reposition_slider();
+ if(!slider)
+ {
+ slider = new VSlider(res);
+ add(*slider);
+ slider->set_step(1);
+ slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed));
+ reposition_slider();
+ }
+ check_view_range();
}
}
void Entry::on_geometry_change()
{
reposition_slider();
+
+ if(multiline)
+ check_view_range();
}
void Entry::on_style_change()
text.set_style(style);
reposition_slider();
+
+ if(multiline)
+ check_view_range();
}
void Entry::reposition_slider()
#include "list.h"
#include "part.h"
#include "style.h"
+#include "text.h"
#include "vslider.h"
using namespace std;
update_style();
}
+void List::autosize()
+{
+ float font_size = style->get_font()->get_default_size();
+
+ geom.w = 0;
+ for(vector<string>::iterator i=items.begin(); i!=items.end(); ++i)
+ {
+ unsigned w = static_cast<unsigned>(style->get_font()->get_string_width(*i)*font_size);
+ geom.w = max(geom.w, w);
+ }
+
+ geom.h = items.size()*row_height;
+
+ if(items_part)
+ {
+ const Sides &margin = items_part->get_margin();
+ geom.w += margin.left+margin.right;
+ geom.h += margin.top+margin.bottom;
+ }
+}
+
void List::append(const string &v)
{
items.push_back(v);
- recalculate_parameters();
+ check_view_range();
}
void List::insert(unsigned i, const string &v)
throw InvalidParameterValue("Index out of range");
items.insert(items.begin()+i, v);
- recalculate_parameters();
+ check_view_range();
}
void List::remove(unsigned i)
else if(sel_index==static_cast<int>(i))
sel_index = -1;
- recalculate_parameters();
+ check_view_range();
}
void List::clear()
items.clear();
sel_index = -1;
- recalculate_parameters();
+ check_view_range();
}
void List::set_selected_index(int i)
{
if(part.get_name()=="items")
{
- const GL::Font &font = *style->get_font();
- const float font_size = font.get_default_size();
- const GL::Color &color = style->get_font_color();
const Sides &margin = part.get_margin();
-
Geometry pgeom = geom;
- pgeom.h = row_height;
- pgeom.w -= margin.left+margin.right;
+ pgeom.h = row_height+margin.top+margin.bottom;
+
+ GL::PushMatrix push_mtx;
+ GL::translate(0, geom.h-pgeom.h, 0);
for(unsigned i=0; (i<n_visible && first+i<items.size()); ++i)
{
- Geometry rgeom;
- rgeom.w = static_cast<unsigned>(font.get_string_width(items[first+i])*font_size);
- rgeom.h = row_height;
- rgeom.x = margin.left;
- rgeom.y = geom.h-margin.top-(i+1)*row_height-static_cast<int>(font.get_descent()*font_size);
- part.get_alignment().apply(rgeom, pgeom);
-
- GL::push_matrix();
- GL::translate(rgeom.x, rgeom.y, 0);
- GL::scale_uniform(font_size);
- GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
- imm.color(color.r, color.g, color.b);
- font.draw_string(items[first+i], imm);
- GL::pop_matrix();
+ if(i!=0)
+ GL::translate(0, -static_cast<int>(row_height), 0);
+ Text(*style, items[first+i]).render(part, pgeom);
}
}
else if(part.get_name()=="selection")
{
reposition_slider();
- recalculate_parameters();
+ check_view_range();
}
void List::on_style_change()
const GL::Font &font = *style->get_font();
row_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
- recalculate_parameters();
+ check_view_range();
}
void List::reposition_slider()
}
}
-void List::recalculate_parameters()
+void List::check_view_range()
{
unsigned h = geom.h;
if(items_part)