You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- keyboard update
local key_up = opt.vertical and 'up' or 'right'
local key_down = opt.vertical and 'down' or 'left'
if core:getPressedKey() == key_up then
info.value = math.min(info.max, info.value + info.step)
value_changed = true
elseif core:getPressedKey() == key_down then
info.value = math.max(info.min, info.value - info.step)
value_changed = true
end
It seems can't use mouse with step variable. And it also not work with keyboard beacuse there is no way to active slider when you want to use keyboard.
The text was updated successfully, but these errors were encountered:
It's a pretty simple fix, here's what I personally do.
In mouse update, between the declaration of v and the if after it, add the following two lines:
v = math.floor((v/info.step) + 0.5) * info.step
fraction = v / (info.max - info.min) + info.min
Note, the second line is because fraction is passed into the theme to decide where to draw the slider. If you remove it, the slider will always follow the mouse when held, but the value will only update on step intervals, and the slider will snap into place once released.
Note: math.floor(x + 0.5) is used to round the value to the nearest position, if you remove the +0.5 it will always snap down.
Here's the full mouse update after the change:
-- mouse update
local mx,my = core:getMousePosition()
if opt.vertical then
fraction = math.min(1, math.max(0, (y+h - my) / h))
else
fraction = math.min(1, math.max(0, (mx - x) / w))
end
local v = fraction * (info.max - info.min) + info.min
v = math.floor((v/info.step) + 0.5) * info.step --Changed line.
fraction = v / (info.max - info.min) + info.min --Changed line.
if v ~= info.value then
info.value = v
value_changed = true
end
It seems can't use mouse with step variable. And it also not work with keyboard beacuse there is no way to active slider when you want to use keyboard.
The text was updated successfully, but these errors were encountered: