Skip to content

Commit 1e9f89e

Browse files
committed
clamp Slider indices when stepping with clicks
Clicking left and right only did -1 & +1 without checking the validity of the result.
1 parent c92ca2a commit 1e9f89e

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Template for new versions:
5959
## New Features
6060

6161
## Fixes
62+
- GUI: Fix sliders allowing values outside their number of stops (num_stops) when incremented with mouse clicks.
6263

6364
## Misc Improvements
6465

library/lua/gui/widgets/slider.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function Slider:onInput(keys)
4141
local left_pos = width_per_idx*(left_idx-1)
4242
local right_pos = width_per_idx*(right_idx-1) + 4
4343
if x < left_pos then
44-
self.on_change(self.get_idx_fn() - 1)
44+
self.on_change(math.max(1, self.get_idx_fn() - 1))
4545
elseif x < left_pos+3 then
4646
self.is_dragging_target = 'left'
4747
self.is_dragging_idx = x - left_pos
@@ -52,7 +52,7 @@ function Slider:onInput(keys)
5252
self.is_dragging_target = 'right'
5353
self.is_dragging_idx = x - right_pos
5454
else
55-
self.on_change(self.get_idx_fn() + 1)
55+
self.on_change(math.min(self.num_stops, self.get_idx_fn() + 1))
5656
end
5757
return true
5858
end

0 commit comments

Comments
 (0)