]> git.tdb.fi Git - libs/gltk.git/commitdiff
Implement set_range and set_step for Slider
authorMikko Rasa <tdb@tdb.fi>
Tue, 10 Jul 2007 19:23:35 +0000 (19:23 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 10 Jul 2007 19:23:35 +0000 (19:23 +0000)
Only emit signal_value_changed from Slider when it actually changed
Use font ascent instead of size to align horizontally

source/slider.cpp
source/widget.cpp

index cb24c002b1a497bb5502f81bb566a434d5abd3c6..11e4c24dc6461c0c49910b030ee18a7a6240a00d 100644 (file)
@@ -9,11 +9,25 @@ Slider::Slider(const Resources &r):
        max(1),
        value(0),
        step(0.1)
+{ }
+
+void Slider::set_range(double a, double b)
 {
+       min=a;
+       max=b;
+       set_value(value);
+}
+
+void Slider::set_step(double s)
+{
+       step=s;
+       set_value(value);
 }
 
 void Slider::set_value(double v)
 {
+       double old_value=value;
+
        if(v<min)
                value=min;
        else if(v>max)
@@ -24,7 +38,8 @@ void Slider::set_value(double v)
                value=min+steps*step;
        }
 
-       signal_value_changed.emit(value);
+       if(value!=old_value)
+               signal_value_changed.emit(value);
 }
 
 } // namespace GLtk
index e1aee846675d3b9e69e37b5d5039bd21f5baa92b..7f153eb5540e4462bfa57645fab2b113cfb06a8b 100644 (file)
@@ -76,7 +76,7 @@ void Widget::render_text(const Part &part, const string &text) const
 
        GL::push_matrix();
 
-       part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font_size));
+       part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
        GL::scale_uniform(font_size);
 
        const Color &color=style->get_font_color();