#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

@@ -116,15 +116,18 @@ local function core_map(args)
end
end
-- initial draw at base temp
draw(300)
-- on state change
---@param temperature number temperature in Kelvin
function e.on_update(temperature)
e.value = temperature
draw(temperature)
end
function e.set_value(val) e.on_update(val) end
-- initial draw at base temp
e.on_update(300)
return e.get()
end

View File

@@ -70,6 +70,8 @@ local function data(args)
-- on state change
---@param value any new value
function e.on_update(value)
e.value = value
local data_str = util.sprintf(args.format, value)
-- write data
@@ -90,6 +92,8 @@ local function data(args)
end
end
function e.set_value(val) e.on_update(val) end
-- initial value draw
e.on_update(args.value)

View File

@@ -42,6 +42,8 @@ local function hbar(args)
-- handle data changes
function e.on_update(fraction)
e.value = fraction
-- enforce minimum and maximum
if fraction < 0 then
fraction = 0.0
@@ -96,6 +98,18 @@ local function hbar(args)
end
end
---@param bar_fg_bg cpair new bar colors
function e.recolor(bar_fg_bg)
bar_bkg = bar_fg_bg.blit_bkg
bar_fgd = bar_fg_bg.blit_fgd
-- re-draw
last_num_bars = 0
e.on_update(e.value)
end
function e.set_value(val) e.on_update(val) end
-- initialize to 0
e.on_update(0)

View File

@@ -55,10 +55,13 @@ local function icon(args)
---@param new_state integer indicator state
function e.on_update(new_state)
local blit_cmd = state_blit_cmds[new_state]
e.value = new_state
e.window.setCursorPos(1, 1)
e.window.blit(blit_cmd.text, blit_cmd.fgd, blit_cmd.bkg)
end
function e.set_value(val) e.on_update(val) end
-- initial icon draw
e.on_update(args.value or 1)

View File

@@ -31,6 +31,7 @@ local function indicator_light(args)
-- on state change
---@param new_state boolean indicator state
function e.on_update(new_state)
e.value = new_state
e.window.setCursorPos(1, 1)
if new_state then
e.window.blit(" \x95", "0" .. args.colors.blit_a, args.colors.blit_a .. e.fg_bg.blit_bkg)
@@ -39,6 +40,8 @@ local function indicator_light(args)
end
end
function e.set_value(val) e.on_update(val) end
-- write label and initial indicator light
e.on_update(false)
e.window.write(args.label)

View File

@@ -61,10 +61,13 @@ local function state_indicator(args)
---@param new_state integer indicator state
function e.on_update(new_state)
local blit_cmd = state_blit_cmds[new_state]
e.value = new_state
e.window.setCursorPos(1, 1)
e.window.blit(blit_cmd.text, blit_cmd.fgd, blit_cmd.bkg)
end
function e.set_value(val) e.on_update(val) end
-- initial draw
e.on_update(args.value or 1)

View File

@@ -40,6 +40,7 @@ local function tristate_indicator_light(args)
-- on state change
---@param new_state integer indicator state
function e.on_update(new_state)
e.value = new_state
e.window.setCursorPos(1, 1)
if new_state == 2 then
e.window.blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
@@ -50,6 +51,8 @@ local function tristate_indicator_light(args)
end
end
function e.set_value(val) e.on_update(val) end
-- write label and initial indicator light
e.on_update(0)
e.window.write(args.label)

View File

@@ -33,6 +33,8 @@ local function vbar(args)
-- handle data changes
function e.on_update(fraction)
e.value = fraction
-- enforce minimum and maximum
if fraction < 0 then
fraction = 0.0
@@ -78,6 +80,8 @@ local function vbar(args)
end
end
function e.set_value(val) e.on_update(val) end
return e.get()
end