bugfixes to graphics elements

This commit is contained in:
Mikayla Fischler
2022-07-16 13:25:07 -04:00
parent 525dedb830
commit c3d6d900a1
5 changed files with 51 additions and 42 deletions

View File

@@ -21,11 +21,12 @@ local function spinbox(args)
local digits = {}
local wn_prec = args.whole_num_precision
local fr_prec = args.fractional_precision
local dec_point_x = args.whole_num_precision + 1
assert(util.is_int(wn_prec), "graphics.element.controls.spinbox_numeric: whole number precision must be an integer")
assert(util.is_int(fr_prec), "graphics.element.controls.spinbox_numeric: fractional precision must be an integer")
local dec_point_x = args.whole_num_precision + 1
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)
@@ -48,12 +49,23 @@ local function spinbox(args)
e.window.setCursorPos(1, 3)
e.window.write(util.strrep("\x1f", wn_prec))
if fr_prec > 0 then
e.window.setCursorPos(1, 1)
e.window.setCursorPos(1 + wn_prec, 1)
e.window.write(" " .. util.strrep("\x1e", fr_prec))
e.window.setCursorPos(1, 3)
e.window.setCursorPos(1 + wn_prec, 3)
e.window.write(" " .. util.strrep("\x1f", fr_prec))
end
-- print out the current value
local function show_num()
e.window.setBackgroundColor(e.fg_bg.bkg)
e.window.setTextColor(e.fg_bg.fgd)
e.window.setCursorPos(1, 2)
e.window.write(util.sprintf("%" .. wn_prec + fr_prec + 1 .. "." .. fr_prec .. "f", value))
end
-- init with the default value
show_num()
-- handle touch
---@param event monitor_touch monitor touch event
function e.handle_touch(event)
@@ -78,6 +90,8 @@ local function spinbox(args)
value = value + (digits[i] * (10 ^ -pow))
end
end
show_num()
end
end