#344 element redraws and shorter assert messages

This commit is contained in:
Mikayla Fischler
2023-09-29 19:34:10 -04:00
parent 70831b49d2
commit ed4180a072
35 changed files with 610 additions and 556 deletions

View File

@@ -25,35 +25,29 @@ local flasher = require("graphics.flasher")
---@param args tristate_indicator_light_args
---@return graphics_element element, element_id id
local function tristate_indicator_light(args)
assert(type(args.label) == "string", "graphics.elements.indicators.trilight: label is a required field")
assert(type(args.c1) == "number", "graphics.elements.indicators.trilight: c1 is a required field")
assert(type(args.c2) == "number", "graphics.elements.indicators.trilight: c2 is a required field")
assert(type(args.c3) == "number", "graphics.elements.indicators.trilight: c3 is a required field")
assert(type(args.label) == "string", "indicators.trilight: label is a required field")
assert(type(args.c1) == "number", "indicators.trilight: c1 is a required field")
assert(type(args.c2) == "number", "indicators.trilight: c2 is a required field")
assert(type(args.c3) == "number", "indicators.trilight: c3 is a required field")
if args.flash then
assert(util.is_int(args.period), "graphics.elements.indicators.trilight: period is a required field if flash is enabled")
assert(util.is_int(args.period), "indicators.trilight: period is a required field if flash is enabled")
end
-- single line
args.height = 1
-- determine width
args.width = math.max(args.min_label_width or 1, string.len(args.label)) + 2
-- flasher state
local flash_on = true
-- blit translations
local c1 = colors.toBlit(args.c1)
local c2 = colors.toBlit(args.c2)
local c3 = colors.toBlit(args.c3)
-- create new graphics element base object
local e = element.new(args)
-- init value for initial check in on_update
e.value = 1
local flash_on = true
local c1 = colors.toBlit(args.c1)
local c2 = colors.toBlit(args.c2)
local c3 = colors.toBlit(args.c3)
-- called by flasher when enabled
local function flash_callback()
e.w_set_cur(1, 1)
@@ -102,9 +96,14 @@ local function tristate_indicator_light(args)
---@param val integer indicator state
function e.set_value(val) e.on_update(val) end
-- write label and initial indicator light
e.on_update(1)
e.w_write(args.label)
-- draw light and label
function e.redraw()
e.on_update(1)
e.w_write(args.label)
end
-- initial draw
e.redraw()
return e.complete()
end