cc-mek-scada/graphics/elements/multipane.lua

51 lines
1.4 KiB
Lua
Raw Normal View History

2023-04-16 19:05:28 +00:00
-- Multi-Pane Display Graphics Element
local element = require("graphics.element")
---@class multipane_args
---@field panes table panes to swap between
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
2023-07-10 03:42:44 +00:00
---@field y? integer auto incremented if omitted
2023-04-16 19:05:28 +00:00
---@field width? integer parent width if omitted
---@field height? integer parent height if omitted
---@field gframe? graphics_frame frame instead of x/y/width/height
---@field fg_bg? cpair foreground/background colors
---@field hidden? boolean true to hide on initial draw
2023-04-16 19:05:28 +00:00
-- new multipane element
---@nodiscard
---@param args multipane_args
---@return graphics_element element, element_id id
local function multipane(args)
2023-09-30 15:46:47 +00:00
element.assert(type(args.panes) == "table", "panes is a required field")
2023-04-16 19:05:28 +00:00
-- create new graphics element base object
local e = element.new(args)
e.value = 1
-- show the selected pane
function e.redraw()
for i = 1, #args.panes do args.panes[i].hide() end
args.panes[e.value].show()
end
2023-04-16 19:05:28 +00:00
-- select which pane is shown
---@param value integer pane to show
function e.set_value(value)
if (e.value ~= value) and (value > 0) and (value <= #args.panes) then
e.value = value
e.redraw()
2023-04-16 19:05:28 +00:00
end
end
-- initial draw
e.redraw()
2023-04-16 19:05:28 +00:00
return e.complete()
2023-04-16 19:05:28 +00:00
end
return multipane