Skip to content

Commit d0568dd

Browse files
author
Swagtoy
committed
Add settings and scrollbar configuration
1 parent fb1b987 commit d0568dd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

builtin/settingtypes.txt

+8
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,14 @@ gui_scaling (GUI scaling) float 1.0 0.5 20
703703
# Enables smooth scrolling.
704704
smooth_scrolling (Smooth scrolling) bool true
705705

706+
# Enables elastic smooth scrolling.
707+
elastic_smooth_scrolling (Elastic smooth scrolling) bool true
708+
709+
# Enables precise scrolling.
710+
# Helpful for most modern trackpads that have pixel-perfect scroll precision. (and even some mice)
711+
# Keep this disabled if your trackpad is scrolling too slowly.
712+
precision_scrolling (Precision scrolling) bool false
713+
706714
# Enables animation of inventory items.
707715
inventory_items_animations (Inventory items animations) bool false
708716

src/defaultsettings.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ void set_default_settings()
295295
settings->setDefault("gui_scaling_filter", "false");
296296
settings->setDefault("gui_scaling_filter_txr2img", "true");
297297
settings->setDefault("smooth_scrolling", "true");
298+
settings->setDefault("elastic_smooth_scrolling", "true");
299+
settings->setDefault("precision_scrolling", "false");
298300
settings->setDefault("desynchronize_mapblock_texture_animation", "false");
299301
settings->setDefault("hud_hotbar_max_width", "1.0");
300302
settings->setDefault("enable_local_map_saving", "false");

src/gui/guiScrollBar.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,17 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
263263
thumb_size = (s32)std::fmin(S32_MAX,
264264
thumb_area / (f32(page_size) / f32(thumb_area + border_size * 2)));
265265

266+
bool is_elastic = g_settings->getBool("elastic_smooth_scrolling");
267+
int elastic_amount = is_elastic ? 20 : 0;
266268
thumb_size = core::s32_clamp(thumb_size, thumb_min, thumb_area);
267-
scroll_pos = core::s32_clamp(pos, min_pos-20, max_pos+20);
269+
scroll_pos = core::s32_clamp(pos, min_pos-elastic_amount, max_pos+elastic_amount);
268270
//scroll_pos = pos;
269271

270272
if (!is_dragging)
271273
{
272274
// TODO support deltatime
273275
if (scroll_pos < 0) {
274-
target_pos = (target_pos * 0.9);
276+
target_pos = is_elastic ? (target_pos * 0.9) : min_pos;
275277
}
276278
else if (scroll_pos > max_pos) {
277279
target_pos += (target_pos - max_pos) * -0.3;
@@ -306,12 +308,13 @@ void GUIScrollBar::setPosAndSend(const s32 &pos)
306308

307309
void GUIScrollBar::setPosInterpolated(const s32 &pos)
308310
{
311+
bool is_elastic = g_settings->getBool("elastic_smooth_scrolling");
309312
if (!g_settings->getBool("smooth_scrolling")) {
310313
setPosAndSend(pos);
311314
return;
312315
}
313316

314-
target_pos = pos;
317+
target_pos = is_elastic ? pos : core::s32_clamp(pos, min_pos, max_pos);
315318
interpolatePos();
316319
}
317320

0 commit comments

Comments
 (0)