kineticscrolling: Add stop function

Move the logic to stop kinetic scrolling to its own function and allow
to call it from the outside.

Part-of: <!3454>
This commit is contained in:
José Expósito 2021-06-22 18:44:05 +02:00 committed by Carlos Garnacho
parent f09338c8de
commit 62808722d2
2 changed files with 13 additions and 3 deletions

View File

@ -202,9 +202,7 @@ gtk_kinetic_scrolling_tick (GtkKineticScrolling *data,
else if (fabs(data->velocity) < 1 ||
(last_time != 0.0 && fabs(data->position - last_position) < 1))
{
data->phase = GTK_KINETIC_SCROLLING_PHASE_FINISHED;
data->position = round(data->position);
data->velocity = 0;
gtk_kinetic_scrolling_stop (data);
}
break;
}
@ -249,3 +247,13 @@ gtk_kinetic_scrolling_tick (GtkKineticScrolling *data,
return data->phase != GTK_KINETIC_SCROLLING_PHASE_FINISHED;
}
void
gtk_kinetic_scrolling_stop (GtkKineticScrolling *data)
{
if (data->phase == GTK_KINETIC_SCROLLING_PHASE_DECELERATING)
{
data->phase = GTK_KINETIC_SCROLLING_PHASE_FINISHED;
data->position = round (data->position);
data->velocity = 0;
}
}

View File

@ -50,6 +50,8 @@ gboolean gtk_kinetic_scrolling_tick (GtkKineticScrolling *data,
double *position,
double *velocity);
void gtk_kinetic_scrolling_stop (GtkKineticScrolling *data);
G_END_DECLS
#endif /* __GTK_KINETIC_SCROLLING_H__ */