Skip to content

Commit

Permalink
fix: cycle button controls not working properly on floating point val…
Browse files Browse the repository at this point in the history
…ues like `speed`

closes #881
  • Loading branch information
tomasklaen committed Apr 7, 2024
1 parent 6fa34c3 commit e6a5fd9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/uosc/elements/CycleButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ function CycleButton:init(id, props)
end

local function handle_change(name, value)
-- Removes unnecessary floating point digits from values like `2.00000`.
-- This happens when observing properties like `speed`.
if type(value) == 'string' and string.match(value, '^[%+%-]?%d+%.%d+$') then
value = tonumber(value)
end

value = type(value) == 'boolean' and (value and 'yes' or 'no') or tostring(value or '')
local index = itable_find(self.states, function(state) return state.value == value end)
self.current_state_index = index or 1
Expand Down

0 comments on commit e6a5fd9

Please sign in to comment.