mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
automatically show current burn rate in burn rate spinbox
This commit is contained in:
parent
573c263548
commit
529951f998
@ -16,7 +16,7 @@ local config = require("coordinator.config")
|
|||||||
local coordinator = require("coordinator.coordinator")
|
local coordinator = require("coordinator.coordinator")
|
||||||
local renderer = require("coordinator.renderer")
|
local renderer = require("coordinator.renderer")
|
||||||
|
|
||||||
local COORDINATOR_VERSION = "alpha-v0.5.2"
|
local COORDINATOR_VERSION = "alpha-v0.5.3"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
|
@ -246,9 +246,12 @@ local function init(parent, id)
|
|||||||
local burn_control = Div{parent=main,x=12,y=40,width=19,height=3,fg_bg=cpair(colors.gray,colors.white)}
|
local burn_control = Div{parent=main,x=12,y=40,width=19,height=3,fg_bg=cpair(colors.gray,colors.white)}
|
||||||
local burn_rate = SpinboxNumeric{parent=burn_control,x=2,y=1,whole_num_precision=4,fractional_precision=1,arrow_fg_bg=cpair(colors.gray,colors.white),fg_bg=cpair(colors.black,colors.white)}
|
local burn_rate = SpinboxNumeric{parent=burn_control,x=2,y=1,whole_num_precision=4,fractional_precision=1,arrow_fg_bg=cpair(colors.gray,colors.white),fg_bg=cpair(colors.black,colors.white)}
|
||||||
TextBox{parent=burn_control,x=9,y=2,text="mB/t"}
|
TextBox{parent=burn_control,x=9,y=2,text="mB/t"}
|
||||||
|
|
||||||
local set_burn = function () unit.set_burn(burn_rate.get_value()) end
|
local set_burn = function () unit.set_burn(burn_rate.get_value()) end
|
||||||
PushButton{parent=burn_control,x=14,y=2,text="SET",min_width=5,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=cpair(colors.white,colors.gray),callback=set_burn}
|
PushButton{parent=burn_control,x=14,y=2,text="SET",min_width=5,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=cpair(colors.white,colors.gray),callback=set_burn}
|
||||||
|
|
||||||
|
r_ps.subscribe("burn_rate", function (v) burn_rate.set_value(v) end)
|
||||||
|
|
||||||
local opts = {
|
local opts = {
|
||||||
{
|
{
|
||||||
text = "Auto",
|
text = "Auto",
|
||||||
|
@ -43,11 +43,6 @@ local function spinbox(args)
|
|||||||
-- set initial value
|
-- set initial value
|
||||||
e.value = args.default or 0.0
|
e.value = args.default or 0.0
|
||||||
|
|
||||||
local initial_str = util.sprintf(fmt_init, e.value)
|
|
||||||
|
|
||||||
---@diagnostic disable-next-line: discard-returns
|
|
||||||
initial_str:gsub("%d", function (char) table.insert(digits, char) end)
|
|
||||||
|
|
||||||
-- draw the arrows
|
-- draw the arrows
|
||||||
e.window.setBackgroundColor(args.arrow_fg_bg.bkg)
|
e.window.setBackgroundColor(args.arrow_fg_bg.bkg)
|
||||||
e.window.setTextColor(args.arrow_fg_bg.fgd)
|
e.window.setTextColor(args.arrow_fg_bg.fgd)
|
||||||
@ -62,18 +57,12 @@ local function spinbox(args)
|
|||||||
e.window.write(" " .. util.strrep("\x1f", fr_prec))
|
e.window.write(" " .. util.strrep("\x1f", fr_prec))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- zero the value
|
-- populate digits from current value
|
||||||
local function zero()
|
local function set_digits()
|
||||||
for i = 1, #digits do digits[i] = 0 end
|
local initial_str = util.sprintf(fmt_init, e.value)
|
||||||
e.value = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- print out the current value
|
---@diagnostic disable-next-line: discard-returns
|
||||||
local function show_num()
|
initial_str:gsub("%d", function (char) table.insert(digits, char) end)
|
||||||
e.window.setBackgroundColor(e.fg_bg.bkg)
|
|
||||||
e.window.setTextColor(e.fg_bg.fgd)
|
|
||||||
e.window.setCursorPos(1, 2)
|
|
||||||
e.window.write(util.sprintf(fmt, e.value))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update the value per digits table
|
-- update the value per digits table
|
||||||
@ -89,11 +78,13 @@ local function spinbox(args)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- enforce numeric limits
|
-- print out the current value
|
||||||
local function enforce_limits()
|
local function show_num()
|
||||||
|
-- enforce limits
|
||||||
-- min 0
|
-- min 0
|
||||||
if e.value < 0 then
|
if e.value < 0 then
|
||||||
zero()
|
for i = 1, #digits do digits[i] = 0 end
|
||||||
|
e.value = 0
|
||||||
-- max printable
|
-- max printable
|
||||||
elseif string.len(util.sprintf(fmt, e.value)) > args.width then
|
elseif string.len(util.sprintf(fmt, e.value)) > args.width then
|
||||||
-- max out
|
-- max out
|
||||||
@ -102,13 +93,12 @@ local function spinbox(args)
|
|||||||
-- re-update value
|
-- re-update value
|
||||||
update_value()
|
update_value()
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- update value and show
|
-- draw
|
||||||
local function parse_and_show()
|
e.window.setBackgroundColor(e.fg_bg.bkg)
|
||||||
update_value()
|
e.window.setTextColor(e.fg_bg.fgd)
|
||||||
enforce_limits()
|
e.window.setCursorPos(1, 2)
|
||||||
show_num()
|
e.window.write(util.sprintf(fmt, e.value))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- init with the default value
|
-- init with the default value
|
||||||
@ -128,7 +118,8 @@ local function spinbox(args)
|
|||||||
digits[idx] = digits[idx] - 1
|
digits[idx] = digits[idx] - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
parse_and_show()
|
update_value()
|
||||||
|
show_num()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,7 +127,9 @@ local function spinbox(args)
|
|||||||
---@param val number number to show
|
---@param val number number to show
|
||||||
function e.set_value(val)
|
function e.set_value(val)
|
||||||
e.value = val
|
e.value = val
|
||||||
parse_and_show()
|
|
||||||
|
set_digits()
|
||||||
|
show_num()
|
||||||
end
|
end
|
||||||
|
|
||||||
return e.get()
|
return e.get()
|
||||||
|
Loading…
Reference in New Issue
Block a user