+ const Geometry &igeom = items[i]->get_geometry();
+
+ if(view_mode!=GRID || (x>0 && x+igeom.w>view_w))
+ {
+ x = 0;
+ if(y)
+ y -= row_h;
+ if(record_rows && i>0)
+ {
+ rows.back().height = row_h;
+ rows.push_back(i);
+ }
+ row_h = 0;
+ }
+
+ if(first_row<rows.size() && i==rows[first_row].first)
+ y = geom.h-min(geom.h, margin.top);
+
+ if(!y)
+ items[i]->set_visible(false);
+ else if(igeom.h+margin.bottom<=y)
+ {
+ items[i]->set_visible(true);
+ unsigned iw = (view_mode==GRID ? igeom.w : view_w);
+ items[i]->set_geometry(Geometry(margin.left+x, y-igeom.h, iw, igeom.h));
+ }
+ else
+ {
+ for(size_t j=rows.back().first; j<=i; ++j)
+ items[j]->set_visible(false);
+ y = 0;
+ }
+
+ x += igeom.w;
+ row_h = max(row_h, igeom.h);