]> git.tdb.fi Git - libs/gltk.git/commitdiff
Fix a case where rebuild was called recursively
authorMikko Rasa <tdb@tdb.fi>
Sat, 11 Jan 2014 18:06:44 +0000 (20:06 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 11 Jan 2014 18:06:44 +0000 (20:06 +0200)
source/list.cpp
source/list.h

index 14c779f0f579dc236eae5049e5c4720e94760591..f42d573866317c643473e8b678e76cf543a677a5 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/raii.h>
 #include <msp/debug/demangle.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/meshbuilder.h>
@@ -39,6 +40,7 @@ void List::init()
        first = 0;
        max_scroll = 0;
        view_size = 5;
+       ignore_slider_change = false;
 
        observer = new DataObserver(*this);
 
@@ -164,6 +166,9 @@ void List::rebuild_special(const Part &part)
                reposition_child(slider, part);
        else if(part.get_name()=="items")
        {
+               SetFlag flag(ignore_slider_change);
+               check_view_range();
+
                const Sides &margin = part.get_margin();
                unsigned w = geom.w-min(geom.w, margin.left+margin.right);
                unsigned y = geom.h-min(geom.h, margin.top);
@@ -190,8 +195,6 @@ void List::rebuild_special(const Part &part)
                                }
                        }
                }
-
-               check_view_range();
        }
 
        Widget::rebuild_special(part);
@@ -261,7 +264,7 @@ void List::check_view_range()
 
 void List::slider_value_changed(double value)
 {
-       if(max_scroll>0)
+       if(max_scroll>0 && !ignore_slider_change)
        {
                first = max_scroll-static_cast<unsigned>(value);
                rebuild();
index 5b43661668d49ffdabe72f99ccd6d8d906395b7b..8e9a851ca23d8c9dc9bf8e2107c565c1175ea77a 100644 (file)
@@ -140,6 +140,7 @@ private:
        unsigned first;
        unsigned max_scroll;
        unsigned view_size;
+       bool ignore_slider_change;
 
        VSlider slider;
        std::vector<Item *> items;