cc-mek-scada/graphics/elements/controls/scram_button.lua

79 lines
2.1 KiB
Lua
Raw Normal View History

2022-06-16 16:17:41 +00:00
-- SCRAM Button Graphics Element
local tcd = require("scada-common.tcallbackdsp")
local core = require("graphics.core")
local element = require("graphics.element")
2022-10-03 01:17:13 +00:00
local accent = colors.yellow
2022-06-16 16:17:41 +00:00
---@class scram_button_args
---@field callback function function to call on touch
---@field parent graphics_element
---@field id? string element id
2022-06-16 16:17:41 +00:00
---@field x? integer 1 if omitted
---@field y? integer 1 if omitted
2022-07-16 17:25:07 +00:00
---@field fg_bg? cpair foreground/background colors
2022-06-16 16:17:41 +00:00
-- new scram button
---@param args scram_button_args
---@return graphics_element element, element_id id
2022-06-16 16:17:41 +00:00
local function scram_button(args)
assert(type(args.callback) == "function", "graphics.elements.controls.scram_button: callback is a required field")
-- static dimensions
args.height = 3
args.width = 9
-- create new graphics element base object
local e = element.new(args)
-- write the button text
e.window.setCursorPos(3, 2)
e.window.write("SCRAM")
-- draw border
-- top
2022-10-03 01:17:13 +00:00
e.window.setTextColor(accent)
2022-07-16 17:25:07 +00:00
e.window.setBackgroundColor(args.fg_bg.bkg)
2022-06-16 16:17:41 +00:00
e.window.setCursorPos(1, 1)
e.window.write("\x99\x89\x89\x89\x89\x89\x89\x89\x99")
-- center left
e.window.setCursorPos(1, 2)
2022-07-16 17:25:07 +00:00
e.window.setTextColor(args.fg_bg.bkg)
2022-10-03 01:17:13 +00:00
e.window.setBackgroundColor(accent)
2022-06-16 16:17:41 +00:00
e.window.write("\x99")
-- center right
2022-07-16 17:25:07 +00:00
e.window.setTextColor(args.fg_bg.bkg)
2022-10-03 01:17:13 +00:00
e.window.setBackgroundColor(accent)
2022-06-16 16:17:41 +00:00
e.window.setCursorPos(9, 2)
e.window.write("\x99")
-- bottom
2022-10-03 01:17:13 +00:00
e.window.setTextColor(accent)
2022-07-16 17:25:07 +00:00
e.window.setBackgroundColor(args.fg_bg.bkg)
2022-06-16 16:17:41 +00:00
e.window.setCursorPos(1, 3)
e.window.write("\x99\x98\x98\x98\x98\x98\x98\x98\x99")
-- handle touch
---@param event monitor_touch monitor touch event
---@diagnostic disable-next-line: unused-local
function e.handle_touch(event)
-- call the touch callback
args.callback()
end
-- set the value
---@param val boolean new value
function e.set_value(val)
if val then e.handle_touch(core.events.touch("", 1, 1)) end
end
return e.get()
2022-06-16 16:17:41 +00:00
end
return scram_button