@@ -81,8 +81,8 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
8181 utki::assert (event.action == button_action::release, SL);
8282 this ->cur_state = state::inertial_scrolling;
8383
84- this ->velocity = this ->calculate_touch_velocity_px_per_ms ();
85- std::cout << " touch release, vel = " << this ->velocity << std::endl;
84+ this ->velocity_px_per_ms = this ->calculate_touch_velocity_px_per_ms ();
85+ // std::cout << "touch release, vel = " << this->velocity_px_per_ms << std::endl;
8686
8787 this ->touch_history .clear ();
8888
@@ -194,24 +194,30 @@ void flickable::update(uint32_t dt_ms)
194194{
195195 utki::assert (this ->cur_state == state::inertial_scrolling, SL);
196196
197- auto scrolled_by = this ->flickable_scroll_by (-this ->velocity * dt_ms);
197+ auto scrolled_by = this ->flickable_scroll_by (-this ->velocity_px_per_ms * ruis::real ( dt_ms) );
198198
199199 using std::copysign;
200- auto velocity_sign = this ->velocity .comp_op ([](const auto & e){return copysign (real (1 ), e);});
200+ auto velocity_sign = this ->velocity_px_per_ms .comp_op ([](const auto & e){return copysign (real (1 ), e);});
201201
202- auto prev_velocity = this ->velocity ;
202+ auto prev_velocity_px_per_ms = this ->velocity_px_per_ms ;
203203
204- this ->velocity -= velocity_sign * this ->friction * dt_ms;
204+ // std::cout << "velocity_sign = " << velocity_sign << ", this->friction = " << this->friction << ", dt_ms = " << dt_ms << std::endl;
205+ auto dv = velocity_sign * this ->friction * ruis::real (dt_ms);
206+ // std::cout << "dv = " << dv << std::endl;
207+ this ->velocity_px_per_ms -= dv;
205208
206- for (auto [prev, cur, scrolled] : utki::views::zip (prev_velocity, this ->velocity , scrolled_by)){
209+ // std::cout << "this->velocity_px_per_ms = " << this->velocity_px_per_ms << std::endl;
210+
211+ for (auto [prev, cur, scrolled_px] : utki::views::zip (prev_velocity_px_per_ms, this ->velocity_px_per_ms , scrolled_by)){
207212 using std::signbit;
208- if (signbit (prev) != signbit (cur) || scrolled == 0 ){
213+ if (signbit (prev) != signbit (cur) || scrolled_px == 0 ){
209214 cur = ruis::real (0 );
210215 }
211216 }
212217
213- if (this ->velocity .is_zero ()){
218+ if (this ->velocity_px_per_ms .is_zero ()){
214219 this ->context .get ().updater .get ().stop (*this );
220+ this ->cur_state = state::idle;
215221 }
216222}
217223
0 commit comments