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

@@ -24,13 +24,15 @@ local function push_button(args)
-- single line
args.height = 1
args.min_width = args.min_width or 0
local text_width = string.len(args.text)
args.width = math.max(text_width + 2, args.min_width)
-- create new graphics element base object
local e = element.new(args)
local h_pad = math.floor((e.frame.w - text_width) / 2)
local h_pad = math.floor((e.frame.w - text_width) / 2) + 1
local v_pad = math.floor(e.frame.h / 2) + 1
-- write the button text

View File

@@ -11,6 +11,7 @@ local element = require("graphics.element")
---@field parent graphics_element
---@field x? integer 1 if omitted
---@field y? integer 1 if omitted
---@field fg_bg? cpair foreground/background colors
-- new scram button
---@param args scram_button_args
@@ -21,9 +22,6 @@ local function scram_button(args)
args.height = 3
args.width = 9
-- static colors
args.fg_bg = core.graphics.cpair(colors.white, colors.black)
-- create new graphics element base object
local e = element.new(args)
@@ -35,25 +33,25 @@ local function scram_button(args)
-- top
e.window.setTextColor(colors.yellow)
e.window.setBackgroundColor(colors.black)
e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 1)
e.window.write("\x99\x89\x89\x89\x89\x89\x89\x89\x99")
-- center left
e.window.setCursorPos(1, 2)
e.window.setTextColor(colors.black)
e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(colors.yellow)
e.window.write("\x99")
-- center right
e.window.setTextColor(colors.black)
e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(colors.yellow)
e.window.setCursorPos(9, 2)
e.window.write("\x99")
-- bottom
e.window.setTextColor(colors.yellow)
e.window.setBackgroundColor(colors.black)
e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 3)
e.window.write("\x99\x98\x98\x98\x98\x98\x98\x98\x99")

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