Skip to content

Commit 12fc0d3

Browse files
author
Swagtoy
committed
Throw up some demo-like code
1 parent 6569fdd commit 12fc0d3

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/gui/guiScrollBar.cpp

+25-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ which includes automatic scaling of the thumb slider and hiding of
1010
the arrow buttons where there is insufficient space.
1111
*/
1212

13+
#include <iostream>
1314
#include "guiScrollBar.h"
1415
#include "guiButton.h"
1516
#include "porting.h"
@@ -188,9 +189,10 @@ void GUIScrollBar::draw()
188189
IGUIElement::draw();
189190
}
190191

191-
static inline s32 interpolate_scroll(s32 from, s32 to, f32 amount)
192+
static inline f32 interpolate_scroll(f32 from, f32 to, f32 amount)
192193
{
193-
s32 step = core::round32((to - from) * core::clamp(amount, 0.001f, 1.0f));
194+
f32 step = /*core::round32*/((to - from) * amount);
195+
std::cout << "step: " << step << " ";
194196
if (step == 0)
195197
return to;
196198
return from + step;
@@ -201,10 +203,11 @@ void GUIScrollBar::interpolatePos()
201203
if (target_pos.has_value()) {
202204
// Adjust to match 60 FPS. This also means that interpolation is
203205
// effectively disabled at <= 30 FPS.
204-
f32 amount = 0.5f * (last_delta_ms / 16.667f);
206+
f32 amount = 0.1f * (last_delta_ms / 16.667f);
205207
setPosRaw(interpolate_scroll(scroll_pos, *target_pos, amount));
206-
if (scroll_pos == target_pos)
207-
target_pos = std::nullopt;
208+
std::cout << "Amount: " << amount << " | at:" << scroll_pos << ", want:" << *target_pos << std::endl;
209+
// if (scroll_pos == target_pos)
210+
// target_pos = std::nullopt;
208211

209212
SEvent e;
210213
e.EventType = EET_GUI_EVENT;
@@ -267,7 +270,18 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
267270
thumb_area / (f32(page_size) / f32(thumb_area + border_size * 2)));
268271

269272
thumb_size = core::s32_clamp(thumb_size, thumb_min, thumb_area);
270-
scroll_pos = core::s32_clamp(pos, min_pos, max_pos);
273+
scroll_pos = core::s32_clamp(pos, min_pos-20, max_pos+20);
274+
//scroll_pos = pos;
275+
276+
if (!is_dragging)
277+
{
278+
if (scroll_pos < 0) {
279+
*target_pos = (*target_pos * 0.9);
280+
}
281+
else if (scroll_pos > max_pos) {
282+
*target_pos += ((*target_pos) - max_pos) * -0.3;
283+
}
284+
}
271285

272286
f32 f = core::isnotzero(range()) ? (f32(thumb_area) - f32(thumb_size)) / range()
273287
: 1.0f;
@@ -278,7 +292,8 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
278292
void GUIScrollBar::setPos(const s32 &pos)
279293
{
280294
setPosRaw(pos);
281-
target_pos = std::nullopt;
295+
target_pos = pos;
296+
//target_pos = std::nullopt;
282297
}
283298

284299
void GUIScrollBar::setPosAndSend(const s32 &pos)
@@ -302,12 +317,12 @@ void GUIScrollBar::setPosInterpolated(const s32 &pos)
302317
return;
303318
}
304319

305-
s32 clamped = core::s32_clamp(pos, min_pos, max_pos);
320+
s32 clamped = pos;//core::s32_clamp(pos, min_pos, max_pos);
306321
if (scroll_pos != clamped) {
307322
target_pos = clamped;
308323
interpolatePos();
309324
} else {
310-
target_pos = std::nullopt;
325+
//target_pos = std::nullopt;
311326
}
312327
}
313328

@@ -365,8 +380,7 @@ s32 GUIScrollBar::getPos() const
365380
s32 GUIScrollBar::getTargetPos() const
366381
{
367382
if (target_pos.has_value()) {
368-
s32 clamped = core::s32_clamp(*target_pos, min_pos, max_pos);
369-
return clamped;
383+
return *target_pos;
370384
}
371385
return scroll_pos;
372386
}

src/gui/guiScrollBar.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class GUIScrollBar : public IGUIElement
9494

9595
void setPosRaw(const s32 &pos);
9696
void updatePos();
97-
std::optional<s32> target_pos;
97+
std::optional<f32> target_pos;
9898
u32 last_time_ms = 0;
9999
u32 last_delta_ms = 17; // assume 60 FPS
100100
void interpolatePos();

0 commit comments

Comments
 (0)