cc-mek-scada/pocket/ui/main.lua

100 lines
3.4 KiB
Lua
Raw Normal View History

--
-- Pocket GUI Root
--
2024-06-04 00:52:59 +00:00
local util = require("scada-common.util")
local iocontrol = require("pocket.iocontrol")
2024-06-14 01:43:56 +00:00
local pocket = require("pocket.pocket")
2023-04-18 17:47:06 +00:00
2024-04-13 18:47:20 +00:00
local diag_apps = require("pocket.ui.apps.diag_apps")
local dummy_app = require("pocket.ui.apps.dummy_app")
2024-06-04 00:52:59 +00:00
local guide_app = require("pocket.ui.apps.guide")
2024-04-13 20:18:27 +00:00
local sys_apps = require("pocket.ui.apps.sys_apps")
local unit_app = require("pocket.ui.apps.unit")
local conn_waiting = require("pocket.ui.components.conn_waiting")
2023-04-30 03:48:50 +00:00
local home_page = require("pocket.ui.pages.home_page")
2023-04-16 19:05:28 +00:00
2024-04-13 18:47:20 +00:00
local style = require("pocket.ui.style")
local core = require("graphics.core")
local Div = require("graphics.elements.div")
local MultiPane = require("graphics.elements.multipane")
local TextBox = require("graphics.elements.textbox")
2023-12-31 17:58:24 +00:00
local PushButton = require("graphics.elements.controls.push_button")
local Sidebar = require("graphics.elements.controls.sidebar")
2024-01-14 19:20:59 +00:00
local SignalBar = require("graphics.elements.indicators.signal")
2023-10-04 03:16:46 +00:00
local ALIGN = core.ALIGN
2023-05-07 01:27:36 +00:00
local cpair = core.cpair
2024-06-14 01:43:56 +00:00
local LINK_STATE = iocontrol.LINK_STATE
local APP_ID = pocket.APP_ID
-- create new main view
---@param main graphics_element main displaybox
local function init(main)
2023-12-31 17:58:24 +00:00
local db = iocontrol.get_db()
-- window header message
TextBox{parent=main,y=1,text="WIP ALPHA APP S C ",alignment=ALIGN.LEFT,height=1,fg_bg=style.header}
local svr_conn = SignalBar{parent=main,y=1,x=22,compact=true,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.green,colors.gray)}
local crd_conn = SignalBar{parent=main,y=1,x=26,compact=true,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.green,colors.gray)}
2024-01-14 19:20:59 +00:00
db.ps.subscribe("svr_conn_quality", svr_conn.set_value)
db.ps.subscribe("crd_conn_quality", crd_conn.set_value)
2023-04-18 17:47:06 +00:00
2023-12-22 16:12:47 +00:00
--#region root panel panes (connection screens + main screen)
2023-04-18 17:47:06 +00:00
local root_pane_div = Div{parent=main,x=1,y=2}
local conn_sv_wait = conn_waiting(root_pane_div, 6, false)
local conn_api_wait = conn_waiting(root_pane_div, 6, true)
local main_pane = Div{parent=main,x=1,y=2}
2023-12-22 16:12:47 +00:00
local root_pane = MultiPane{parent=root_pane_div,x=1,y=1,panes={conn_sv_wait,conn_api_wait,main_pane}}
2023-12-31 17:58:24 +00:00
root_pane.register(db.ps, "link_state", function (state)
if state == LINK_STATE.UNLINKED or state == LINK_STATE.API_LINK_ONLY then
2023-04-18 17:47:06 +00:00
root_pane.set_value(1)
elseif state == LINK_STATE.SV_LINK_ONLY then
2023-04-18 17:47:06 +00:00
root_pane.set_value(2)
else
root_pane.set_value(3)
end
end)
2023-12-22 16:12:47 +00:00
--#endregion
--#region main page panel panes & sidebar
2023-04-18 17:47:06 +00:00
local page_div = Div{parent=main_pane,x=4,y=1}
2024-04-13 18:47:20 +00:00
home_page(page_div)
unit_app(page_div)
2024-06-04 00:52:59 +00:00
guide_app(page_div)
2024-04-13 20:18:27 +00:00
sys_apps(page_div)
2024-06-04 00:52:59 +00:00
diag_apps(page_div)
2024-04-13 18:47:20 +00:00
dummy_app(page_div)
2024-06-14 01:43:56 +00:00
assert(util.table_len(db.nav.get_containers()) == APP_ID.NUM_APPS, "app IDs were not sequential or some apps weren't registered")
2023-12-22 16:12:47 +00:00
db.nav.set_pane(MultiPane{parent=page_div,x=1,y=1,panes=db.nav.get_containers()})
db.nav.set_sidebar(Sidebar{parent=main_pane,x=1,y=1,height=18,fg_bg=cpair(colors.white,colors.gray)})
2023-12-31 17:58:24 +00:00
PushButton{parent=main_pane,x=1,y=19,text="\x1b",min_width=3,fg_bg=cpair(colors.white,colors.gray),active_fg_bg=cpair(colors.gray,colors.black),callback=db.nav.nav_up}
2024-06-14 01:43:56 +00:00
db.nav.open_app(APP_ID.ROOT)
2023-12-22 16:12:47 +00:00
--#endregion
end
return init