@@ -189,11 +189,10 @@ void GUIScrollBar::draw()
189
189
IGUIElement::draw ();
190
190
}
191
191
192
+ #include < iostream>
192
193
f32 GUIScrollBar::interpolate_scroll (f32 from, f32 to, f32 amount)
193
194
{
194
195
f32 step = /* core::round32*/ ((to - from) * (amount * (last_delta_ms / 16 .667f )));
195
- if (core::round32 (step) == 0 )
196
- return to;
197
196
return from + step;
198
197
}
199
198
@@ -264,17 +263,18 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
264
263
265
264
bool is_elastic = g_settings->getBool (" elastic_smooth_scrolling" );
266
265
int elastic_overscroll = is_elastic ? 20 : 0 ;
267
- thumb_size = core::s32_clamp (thumb_size, thumb_min, thumb_area);
268
- scroll_pos = core::s32_clamp (pos, min_pos-elastic_overscroll, max_pos+elastic_overscroll);
266
+ thumb_size = core::clamp<f32> (thumb_size, thumb_min, thumb_area);
267
+ scroll_pos = core::clamp<f32> (pos, min_pos-elastic_overscroll, max_pos+elastic_overscroll);
269
268
269
+ constexpr f32 elastic_change = 0 .15f ;
270
270
if (!is_dragging)
271
271
{
272
272
// TODO support deltatime
273
- if (scroll_pos < 0 ) {
274
- target_pos = is_elastic ? (target_pos * 0.9 ) : min_pos;
273
+ if (scroll_pos < 0 . 0f ) {
274
+ target_pos = is_elastic ? interpolate_scroll (target_pos, 0 , elastic_change ) : min_pos;
275
275
}
276
276
else if (scroll_pos > max_pos) {
277
- target_pos = is_elastic ? max_pos+(( target_pos - max_pos) * 0.9 ) : max_pos;
277
+ target_pos = is_elastic ? interpolate_scroll ( target_pos, max_pos, elastic_change ) : max_pos;
278
278
}
279
279
}
280
280
0 commit comments