#91 get and set values for all controls/indicators and textbox

This commit is contained in:
Mikayla Fischler
2022-09-12 12:59:28 -04:00
parent d9be5ccb47
commit 10c53ac4b3
16 changed files with 192 additions and 60 deletions

View File

@@ -26,9 +26,6 @@ local function switch_button(args)
-- single line
args.height = 1
-- button state (convert nil to false if missing)
local state = args.default or false
-- determine widths
local text_width = string.len(args.text)
args.width = math.max(text_width + 2, args.min_width)
@@ -36,12 +33,15 @@ local function switch_button(args)
-- create new graphics element base object
local e = element.new(args)
-- button state (convert nil to false if missing)
e.value = args.default or false
local h_pad = math.floor((e.frame.w - text_width) / 2)
local v_pad = math.floor(e.frame.h / 2) + 1
-- show the button state
local function draw_state()
if state then
if e.value then
-- show as pressed
e.window.setTextColor(args.active_fg_bg.fgd)
e.window.setBackgroundColor(args.active_fg_bg.bkg)
@@ -64,11 +64,22 @@ local function switch_button(args)
---@diagnostic disable-next-line: unused-local
function e.handle_touch(event)
-- toggle state
state = not state
e.value = not e.value
draw_state()
-- call the touch callback with state
args.callback(state)
args.callback(e.value)
end
-- set the value
---@param val boolean new value
function e.set_value(val)
-- set state
e.value = val
draw_state()
-- call the touch callback with state
args.callback(e.value)
end
return e.get()