@@ -398,7 +398,7 @@ real list::scroll_by(real delta)
398398 break ;
399399 }
400400
401- // delta is big enough that scrolling by it will make the first visible widget to scroll away upwards
401+ // delta is big enough that scrolling by it will make the first visible widget to scroll away upwards
402402
403403 std::cout << " dim <= delta, delta = " << delta << " , dim = " << dim << std::endl;
404404
@@ -410,6 +410,9 @@ real list::scroll_by(real delta)
410410
411411 // if there is still distance to scroll, then go through the rest of the widgets
412412 if (delta > 0 ) {
413+ // We have scrolled away upwards all the previously visible widgets,
414+ // so this->pos_index currently points to a widget which is not added to the container as child.
415+
413416 std::cout << " delta > 0: delta = " << delta << std::endl;
414417 utki::assert (
415418 this ->pos_index > this ->added_index + this ->children ().size (),
@@ -419,19 +422,23 @@ real list::scroll_by(real delta)
419422 },
420423 SL
421424 );
425+
422426 for (; this ->pos_index < this ->first_tail_item_index ;) {
423427 auto w = this ->get_provider ().get_widget (this ->pos_index );
424- vec2 d = dims_for_widget (w.get (), this ->rect ().d );
428+ vec2 dims = dims_for_widget (w.get (), this ->rect ().d );
429+ auto long_dim = dims[long_index];
425430
426431 // this is just optimization, to avoid creating same widget twice
427432 this ->push_back (std::move (w));
428433
429- if (d[long_index] > delta) {
434+ if (delta < long_dim) {
435+ // The delta is smaller than widget's dimension, so the scroll is only within that widget.
430436 this ->pos_offset = delta;
437+ scrolled_by += delta;
431438 break ;
432439 }
433- delta -= d[long_index] ;
434- scrolled_by += d[long_index] ;
440+ delta -= long_dim ;
441+ scrolled_by += long_dim ;
435442 utki::assert (this ->pos_offset == 0 , SL);
436443 ++this ->pos_index ;
437444 }
0 commit comments