Skip to content

Commit 8a17417

Browse files
author
Swagtoy
committed
Use interpolate_scroll method now
1 parent 0f7089e commit 8a17417

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/gui/guiScrollBar.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,10 @@ void GUIScrollBar::draw()
189189
IGUIElement::draw();
190190
}
191191

192+
#include <iostream>
192193
f32 GUIScrollBar::interpolate_scroll(f32 from, f32 to, f32 amount)
193194
{
194195
f32 step = /*core::round32*/((to - from) * (amount * (last_delta_ms / 16.667f)));
195-
if (core::round32(step) == 0)
196-
return to;
197196
return from + step;
198197
}
199198

@@ -264,17 +263,18 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
264263

265264
bool is_elastic = g_settings->getBool("elastic_smooth_scrolling");
266265
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);
269268

269+
constexpr f32 elastic_change = 0.15f;
270270
if (!is_dragging)
271271
{
272272
// 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;
275275
}
276276
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;
278278
}
279279
}
280280

0 commit comments

Comments
 (0)