Skip to content

Commit 2bd9952

Browse files
committed
round list::scroll_by()
1 parent 162ecf4 commit 2bd9952

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ruis/widget/base/touch/flickable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ void flickable::update(uint32_t dt_ms)
200200
utki::assert(this->cur_state == state::inertial_scrolling, SL);
201201

202202
auto scrolled_by = this->flickable_scroll_by(-this->velocity_px_per_ms * ruis::real(dt_ms));
203+
std::cout << "flickable::update(): scroled_by = " << scrolled_by << std::endl;
203204

204205
using std::copysign;
205206
auto velocity_sign = this->velocity_px_per_ms.comp_op([](const auto& e) {

src/ruis/widget/group/list.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void list::update_children_list()
293293

294294
// remove rest
295295
if (iter_index < iter_end_index) {
296-
ASSERT(iter != this->children().end())
296+
utki::assert(iter != this->children().end(), SL);
297297
for (; iter != this->children().end(); ++iter_index) {
298298
iter = this->erase(iter);
299299
}
@@ -355,6 +355,9 @@ void list::notify_scroll_pos_changed(size_t old_index, real old_offset)
355355

356356
real list::scroll_by(real delta)
357357
{
358+
using std::round;
359+
delta = round(delta);
360+
358361
size_t old_index = this->pos_index;
359362
real old_offset = this->pos_offset;
360363

@@ -364,6 +367,7 @@ real list::scroll_by(real delta)
364367
real scrolled_by = 0;
365368

366369
if (delta >= 0) {
370+
// go through visible widgets first
367371
for (auto& c : this->children()) {
368372
auto wd = c.get().rect().d[long_index] - this->pos_offset;
369373
if (wd > delta) {
@@ -379,6 +383,7 @@ real list::scroll_by(real delta)
379383
++this->pos_index;
380384
}
381385

386+
// if there is still distance to scroll, then go through the rest of the widgets
382387
if (delta > 0) {
383388
utki::assert(
384389
this->pos_index > this->added_index + this->children().size(),
@@ -438,10 +443,15 @@ real list::scroll_by(real delta)
438443
}
439444
}
440445

446+
// this will update the scrolling position to the bottom of the list if we have scrolled past the end of the list
441447
this->update_children_list();
442448

449+
// TODO: detect the situation when we have scrolled past the list's end and update the scrolled_by value accordingly
450+
443451
this->notify_scroll_pos_changed(old_index, old_offset);
444452

453+
std::cout << "list: scrolled_by = " << scrolled_by << std::endl;
454+
445455
return scrolled_by;
446456
}
447457

0 commit comments

Comments
 (0)