@@ -353,77 +353,96 @@ void list::notify_scroll_pos_changed(size_t old_index, real old_offset)
353353 }
354354}
355355
356- void list::scroll_by (real delta)
356+ real list::scroll_by (real delta)
357357{
358358 size_t old_index = this ->pos_index ;
359359 real old_offset = this ->pos_offset ;
360360
361+ // list's longitudinal direction index
361362 unsigned long_index = this ->get_long_index ();
362363
363- // TRACE(<< "delta = " << delta << std::endl)
364+ real scrolled_by = 0 ;
364365
365366 if (delta >= 0 ) {
366367 for (auto & c : this ->children ()) {
367368 auto wd = c.get ().rect ().d [long_index] - this ->pos_offset ;
368369 if (wd > delta) {
369370 this ->pos_offset += delta;
370371 delta -= wd;
372+ scrolled_by += delta;
371373 break ;
372374 }
373375
374376 delta -= wd;
377+ scrolled_by += wd;
375378 this ->pos_offset = 0 ;
376379 ++this ->pos_index ;
377380 }
378381
379382 if (delta > 0 ) {
380- ASSERT (this ->pos_index > this ->added_index + this ->children ().size (), [&](auto & o) {
381- o << " this->pos_index = " << this ->pos_index << " this->added_index = " << this ->added_index
382- << " this->children().size() = " << this ->children ().size ();
383- })
383+ utki::assert (
384+ this ->pos_index > this ->added_index + this ->children ().size (),
385+ [&](auto & o) {
386+ o << " this->pos_index = " << this ->pos_index << " this->added_index = " << this ->added_index
387+ << " this->children().size() = " << this ->children ().size ();
388+ },
389+ SL
390+ );
384391 for (; this ->pos_index < this ->first_tail_item_index ;) {
385392 auto w = this ->get_provider ().get_widget (this ->pos_index );
386393 vec2 d = dims_for_widget (w.get (), this ->rect ().d );
387- this ->push_back (w); // this is just optimization, to avoid creating same widget twice
394+
395+ // this is just optimization, to avoid creating same widget twice
396+ this ->push_back (std::move (w));
397+
388398 if (d[long_index] > delta) {
389399 this ->pos_offset = delta;
390400 break ;
391401 }
392402 delta -= d[long_index];
393- ASSERT (this ->pos_offset == 0 )
403+ scrolled_by += d[long_index];
404+ utki::assert (this ->pos_offset == 0 , SL);
394405 ++this ->pos_index ;
395406 }
396407 }
397408 } else {
398409 delta = -delta;
399410 if (delta <= this ->pos_offset ) {
400411 this ->pos_offset -= delta;
412+ scrolled_by -= delta;
401413 } else {
402- ASSERT (this ->added_index == this ->pos_index )
414+ utki::assert (this ->added_index == this ->pos_index , SL);
403415 delta -= this ->pos_offset ;
416+ scrolled_by -= this ->pos_offset ;
404417 this ->pos_offset = 0 ;
405418 for (; this ->pos_index > 0 ;) {
406- ASSERT (this ->added_index == this ->pos_index )
419+ utki::assert (this ->added_index == this ->pos_index , SL);
407420 --this ->pos_index ;
408421 auto w = this ->get_provider ().get_widget (this ->pos_index );
409422 vec2 d = dims_for_widget (w.get (), this ->rect ().d );
423+
424+ // this is just optimization, to avoid creating same widget twice
410425 this ->insert (
411- w,
426+ std::move (w), //
412427 this ->children ().begin ()
413- ); // this is just optimization, to avoid creating same widget twice
428+ );
429+
414430 --this ->added_index ;
415431 if (d[long_index] > delta) {
416432 this ->pos_offset = d[long_index] - delta;
417433 break ;
418434 }
419435 delta -= d[long_index];
436+ scrolled_by -= d[long_index];
420437 }
421438 }
422439 }
423440
424441 this ->update_children_list ();
425442
426443 this ->notify_scroll_pos_changed (old_index, old_offset);
444+
445+ return scrolled_by;
427446}
428447
429448ruis::vec2 list::measure (const ruis::vec2& quotum) const
0 commit comments