@@ -10,6 +10,7 @@ which includes automatic scaling of the thumb slider and hiding of
10
10
the arrow buttons where there is insufficient space.
11
11
*/
12
12
13
+ #include < iostream>
13
14
#include " guiScrollBar.h"
14
15
#include " guiButton.h"
15
16
#include " porting.h"
@@ -188,9 +189,10 @@ void GUIScrollBar::draw()
188
189
IGUIElement::draw ();
189
190
}
190
191
191
- static inline s32 interpolate_scroll (s32 from, s32 to, f32 amount)
192
+ static inline f32 interpolate_scroll (f32 from, f32 to, f32 amount)
192
193
{
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 << " " ;
194
196
if (step == 0 )
195
197
return to;
196
198
return from + step;
@@ -201,10 +203,11 @@ void GUIScrollBar::interpolatePos()
201
203
if (target_pos.has_value ()) {
202
204
// Adjust to match 60 FPS. This also means that interpolation is
203
205
// 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 );
205
207
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;
208
211
209
212
SEvent e;
210
213
e.EventType = EET_GUI_EVENT;
@@ -267,7 +270,18 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
267
270
thumb_area / (f32 (page_size) / f32 (thumb_area + border_size * 2 )));
268
271
269
272
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
+ }
271
285
272
286
f32 f = core::isnotzero (range ()) ? (f32 (thumb_area) - f32 (thumb_size)) / range ()
273
287
: 1 .0f ;
@@ -278,7 +292,8 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
278
292
void GUIScrollBar::setPos (const s32 &pos)
279
293
{
280
294
setPosRaw (pos);
281
- target_pos = std::nullopt;
295
+ target_pos = pos;
296
+ // target_pos = std::nullopt;
282
297
}
283
298
284
299
void GUIScrollBar::setPosAndSend (const s32 &pos)
@@ -302,12 +317,12 @@ void GUIScrollBar::setPosInterpolated(const s32 &pos)
302
317
return ;
303
318
}
304
319
305
- s32 clamped = core::s32_clamp (pos, min_pos, max_pos);
320
+ s32 clamped = pos; // core::s32_clamp(pos, min_pos, max_pos);
306
321
if (scroll_pos != clamped) {
307
322
target_pos = clamped;
308
323
interpolatePos ();
309
324
} else {
310
- target_pos = std::nullopt;
325
+ // target_pos = std::nullopt;
311
326
}
312
327
}
313
328
@@ -365,8 +380,7 @@ s32 GUIScrollBar::getPos() const
365
380
s32 GUIScrollBar::getTargetPos () const
366
381
{
367
382
if (target_pos.has_value ()) {
368
- s32 clamped = core::s32_clamp (*target_pos, min_pos, max_pos);
369
- return clamped;
383
+ return *target_pos;
370
384
}
371
385
return scroll_pos;
372
386
}
0 commit comments