#63 cleanup and assertions

This commit is contained in:
Mikayla Fischler
2022-06-11 17:06:32 -04:00
parent 4488a0594f
commit 89437b2be9
12 changed files with 46 additions and 23 deletions

View File

@@ -11,7 +11,7 @@ local util = require("scada-common.util")
---@field parent graphics_element
---@field x? integer 1 if omitted
---@field y? integer 1 if omitted
---@field fg_bg cpair foreground/background colors
---@field fg_bg? cpair foreground/background colors
-- new spinbox control
---@param args spinbox_args
@@ -26,6 +26,8 @@ local function spinbox(args)
assert(util.is_int(wn_prec), "graphics.element.spinbox_numeric: whole number precision must be an integer")
assert(util.is_int(fr_prec), "graphics.element.spinbox_numeric: fractional precision must be an integer")
assert(type(args.arrow_fg_bg) == "table", "graphics.element.spinbox_numeric: arrow_fg_bg is a required field")
local initial_str = util.sprintf("%" .. wn_prec .. "." .. fr_prec .. "f", value)
---@diagnostic disable-next-line: discard-returns
@@ -69,11 +71,10 @@ local function spinbox(args)
-- update value
value = 0
for i = 1, #digits do
local pow = math.abs(wn_prec - i)
if i <= wn_prec then
local pow = wn_prec - i
value = value + (digits[i] * (10 ^ pow))
else
local pow = i - wn_prec
value = value + (digits[i] * (10 ^ -pow))
end
end