@@ -372,35 +372,56 @@ real list::scroll_by(real delta)
372372
373373 real scrolled_by = 0 ;
374374
375- std::cout << " delta = " << delta << std::endl;
375+ // std::cout << "delta = " << delta << std::endl;
376376
377- // TODO: added for now as delta of 0 causes unexpected scrolled_by valu returned.
377+ // TODO: added for now as delta of 0 causes unexpected scrolled_by value returned.
378378 // figure out if this can be handled as delta >= 0 condition.
379379 if (delta == 0 ) {
380380 return scrolled_by;
381381 }
382382
383383 if (delta > 0 ) {
384- std::cout << " delta > 0" << std::endl;
384+ // std::cout << "delta > 0" << std::endl;
385385
386386 // go through visible widgets first
387387 for (auto & c : this ->children ()) {
388+ utki::assert (this ->pos_index <= this ->first_tail_item_index , SL);
389+
390+ // if we are already at the end of the list, within the last item
391+ if (this ->pos_index == this ->first_tail_item_index ) {
392+ // std::cout << "1111111111111111111111111111111111" << std::endl;
393+ utki::assert (this ->pos_offset <= this ->first_tail_item_offset , SL);
394+ auto max_scroll_till_end = this ->first_tail_item_offset - this ->pos_offset ;
395+ using std::min;
396+ delta = min (this ->first_tail_item_dim , max_scroll_till_end);
397+ this ->pos_offset += delta;
398+ scrolled_by += delta;
399+
400+ // Stop scrolling on this.
401+ delta = 0 ;
402+
403+ break ;
404+ }
405+
388406 // Since we are scrolling 'up', assume we are dealing with the first visible widget on each iteration,
389407 // because previous one which was first visible is aready scrolled away upwards.
390408 auto dim = c.get ().rect ().d [long_index] - this ->pos_offset ;
391409 if (delta <= dim) {
392410 // We can scroll the whole delta and the same widget remains the first visible one,
393411 // only its position offset changes.
394- std::cout << " delta <= dim, delta = " << delta << " , dim = " << dim << std::endl;
412+ // std::cout << "delta <= dim, delta = " << delta << ", dim = " << dim << std::endl;
395413 this ->pos_offset += delta;
396414 scrolled_by += delta;
415+
416+ // Stop scrolling on this.
397417 delta = 0 ;
418+
398419 break ;
399420 }
400421
401422 // delta is big enough that scrolling by it will make the first visible widget to scroll away upwards
402423
403- std::cout << " dim <= delta, delta = " << delta << " , dim = " << dim << std::endl;
424+ // std::cout << "dim <= delta, delta = " << delta << ", dim = " << dim << std::endl;
404425
405426 delta -= dim;
406427 scrolled_by += dim;
@@ -413,7 +434,7 @@ real list::scroll_by(real delta)
413434 // We have scrolled away upwards all the previously visible widgets,
414435 // so this->pos_index currently points to a widget which is not added to the container as child.
415436
416- std::cout << " delta > 0: delta = " << delta << std::endl;
437+ // std::cout << "delta > 0: delta = " << delta << std::endl;
417438 utki::assert (
418439 this ->pos_index > this ->added_index + this ->children ().size (),
419440 [&](auto & o) {
@@ -442,12 +463,22 @@ real list::scroll_by(real delta)
442463 utki::assert (this ->pos_offset == 0 , SL);
443464 ++this ->pos_index ;
444465 }
466+
467+ if (this ->pos_index == this ->first_tail_item_index ) {
468+ // we have scrolled till the end of the list, and are within the last item
469+ // std::cout << "222222222222222222222222222" << std::endl;
470+ utki::assert (this ->pos_offset <= this ->first_tail_item_offset , SL);
471+ auto max_scroll_till_end = this ->first_tail_item_offset - this ->pos_offset ;
472+ using std::min;
473+ delta = min (this ->first_tail_item_dim , max_scroll_till_end);
474+ utki::assert (delta < this ->first_tail_item_dim , SL);
475+ }
445476 }
446477 } else {
447478 utki::assert (delta < 0 , SL);
448479 delta = -delta;
449480 if (delta <= this ->pos_offset ) {
450- std::cout << " delta <= this->pos_offset" << std::endl;
481+ // std::cout << "delta <= this->pos_offset" << std::endl;
451482 this ->pos_offset -= delta;
452483 scrolled_by -= delta;
453484 } else {
@@ -478,12 +509,12 @@ real list::scroll_by(real delta)
478509 --this ->added_index ;
479510
480511 if (delta <= long_dim) {
481- std::cout << " delta <= long_dim: delta = " << delta << std::endl;
512+ // std::cout << "delta <= long_dim: delta = " << delta << std::endl;
482513 this ->pos_offset = long_dim - delta;
483514 scrolled_by -= delta;
484515 break ;
485516 }
486- std::cout << " delta > long_dim: delta = " << delta << std::endl;
517+ // std::cout << "delta > long_dim: delta = " << delta << std::endl;
487518 delta -= long_dim;
488519 scrolled_by -= long_dim;
489520 }
@@ -497,7 +528,7 @@ real list::scroll_by(real delta)
497528
498529 this ->notify_scroll_pos_changed (old_index, old_offset);
499530
500- std::cout << " list: scrolled_by = " << scrolled_by << std::endl;
531+ // std::cout << "list: scrolled_by = " << scrolled_by << std::endl;
501532
502533 return scrolled_by;
503534}
0 commit comments