X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=blobdiff_plain;f=source%2Flist.cpp;h=b9713422f11236fa86bc23a87a64f59523365569;hp=0f887f3a6641316a6610da9f403a4bc5abefb7f4;hb=db2a069cd5ec4c8809c2ba6ddeec2ddcd32d49ef;hpb=4b52d16bc895f9d969383d7a7d6a3558c1972cc5 diff --git a/source/list.cpp b/source/list.cpp index 0f887f3..b971342 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -254,29 +254,39 @@ void List::item_autosize_changed(Item *item) rebuild(); } -void List::check_view_range() +unsigned List::last_to_first(unsigned last) const { if(!style) - return; + return last; - unsigned h = geom.h; + unsigned view_h = geom.h; if(const Part *items_part = style->get_part("items")) { const Sides &margin = items_part->get_margin(); - h -= margin.top+margin.bottom; + view_h -= margin.top+margin.bottom; } - max_scroll = items.size(); - for(unsigned i=items.size(); i-->0; ) + unsigned items_h = 0; + for(unsigned i=last; iget_geometry().h; - if(ih<=h) - { - h -= ih; - --max_scroll; - } + items_h += items[i]->get_geometry().h; + if(items_h>view_h) + return min(i+1, last); } + return 0; +} + +void List::check_view_range() +{ + if(!style) + return; + + if(items.empty()) + max_scroll = 0; + else + max_scroll = last_to_first(items.size()-1); + if(first>max_scroll) first = max_scroll;