]> git.tdb.fi Git - libs/gltk.git/commitdiff
Cache the items part in List
authorMikko Rasa <tdb@tdb.fi>
Thu, 19 Sep 2019 19:04:41 +0000 (22:04 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 19 Sep 2019 19:08:39 +0000 (22:08 +0300)
source/list.cpp
source/list.h

index 9be88e52c9ce65acecdf98b550d78a5db9a672ee..5d765008765c9ccbece8c28e77c9a62da5a4cecb 100644 (file)
@@ -44,6 +44,7 @@ void List::init()
        first = 0;
        max_scroll = 0;
        view_size = 5;
+       items_part = 0;
        ignore_slider_change = false;
        dragging = false;
        drag_start_x = 0;
@@ -349,6 +350,11 @@ bool List::navigate(Navigation nav)
        return true;
 }
 
+void List::on_style_change()
+{
+       items_part = (style ? style->get_part("items") : 0);
+}
+
 void List::move_focus(Navigation nav, bool select)
 {
        if(nav==NAV_UP)
@@ -386,15 +392,11 @@ void List::item_autosize_changed(Item *item)
 
 unsigned List::last_to_first(unsigned last) const
 {
-       if(!style)
+       if(!items_part)
                return last;
 
-       unsigned view_h = geom.h;
-       if(const Part *items_part = style->get_part("items"))
-       {
-               const Sides &margin = items_part->get_margin();
-               view_h -= margin.top+margin.bottom;
-       }
+       const Sides &margin = items_part->get_margin();
+       unsigned view_h = geom.h-min(geom.h, margin.top+margin.bottom);
 
        unsigned items_h = 0;
        for(unsigned i=last; i<items.size(); --i)
index 25001d18f7948dcab5af79e8671feddf538a61ae..43a24576a1ecf1904d29d1a58eb104c61a790d00 100644 (file)
@@ -145,6 +145,7 @@ private:
        unsigned first;
        unsigned max_scroll;
        unsigned view_size;
+       const Part *items_part;
        bool ignore_slider_change;
        bool dragging;
        int drag_start_x;
@@ -205,6 +206,8 @@ public:
        virtual void focus_in();
        virtual bool navigate(Navigation);
 private:
+       virtual void on_style_change();
+
        void move_focus(Navigation, bool);
        void set_focus_index(int);