From 510995b04f6a3811a12a1819dc67031979fb426e Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 6 Mar 2024 23:35:30 -0500 Subject: [PATCH] #405 #340 coordinator configurator control of theme and color mode --- coordinator/configure.lua | 173 ++++++++++++++++++++-- coordinator/coordinator.lua | 12 +- coordinator/startup.lua | 3 + coordinator/ui/components/boiler.lua | 6 +- coordinator/ui/components/imatrix.lua | 6 +- coordinator/ui/components/pkt_entry.lua | 10 +- coordinator/ui/components/process_ctl.lua | 16 +- coordinator/ui/components/reactor.lua | 6 +- coordinator/ui/components/turbine.lua | 6 +- coordinator/ui/components/unit_detail.lua | 20 +-- coordinator/ui/components/unit_flow.lua | 12 +- coordinator/ui/layout/flow_view.lua | 12 +- coordinator/ui/layout/main_view.lua | 4 +- coordinator/ui/style.lua | 30 +++- graphics/themes.lua | 10 -- 15 files changed, 248 insertions(+), 78 deletions(-) diff --git a/coordinator/configure.lua b/coordinator/configure.lua index 7c3fe58..ed8a3df 100644 --- a/coordinator/configure.lua +++ b/coordinator/configure.lua @@ -24,6 +24,8 @@ local RadioButton = require("graphics.elements.controls.radio_button") local NumberField = require("graphics.elements.form.number_field") local TextField = require("graphics.elements.form.text_field") +local IndLight = require("graphics.elements.indicators.light") + local println = util.println local tri = util.trinary @@ -40,7 +42,8 @@ local RIGHT = core.ALIGN.RIGHT -- changes to the config data/format to let the user know local changes = { - {"v1.2.4", { "Added temperature scale options" } } + {"v1.2.4", { "Added temperature scale options" } }, + {"v1.2.12", { "Added main UI theme", "Added front panel UI theme", "Added color accessibility modes" } } } ---@class crd_configurator @@ -73,6 +76,7 @@ local nav_fg_bg = bw_fg_bg local btn_act_fg_bg = cpair(colors.white, colors.gray) local dis_fg_bg = cpair(colors.lightGray,colors.white) +---@class _crd_cfg_tool_ctl local tool_ctl = { nic = nil, ---@type nic net_listen = false, @@ -86,8 +90,12 @@ local tool_ctl = { has_config = false, viewing_config = false, importing_legacy = false, + jumped_to_color = false, view_cfg = nil, ---@type graphics_element + color_cfg = nil, ---@type graphics_element + color_next = nil, ---@type graphics_element + color_apply = nil, ---@type graphics_element settings_apply = nil, ---@type graphics_element gen_summary = nil, ---@type function @@ -136,6 +144,9 @@ local tmp_cfg = { LogMode = 0, LogPath = "", LogDebug = false, + MainTheme = 1, + FrontPanelTheme = 1, + ColorMode = 1 } ---@class crd_config @@ -162,7 +173,10 @@ local fields = { { "AuthKey", "Facility Auth Key" , ""}, { "LogMode", "Log Mode", log.MODE.APPEND }, { "LogPath", "Log Path", "/log.txt" }, - { "LogDebug","Log Debug Messages", false } + { "LogDebug","Log Debug Messages", false }, + { "MainTheme", "Main UI Theme", 1 }, + { "FrontPanelTheme", "Front Panel Theme", 1 }, + { "ColorMode", "Color Mode", 1 } } -- check if a value is an integer within a range (inclusive) @@ -313,10 +327,11 @@ local function config_view(display) local spkr_cfg = Div{parent=root_pane_div,x=1,y=1} local crd_cfg = Div{parent=root_pane_div,x=1,y=1} local log_cfg = Div{parent=root_pane_div,x=1,y=1} + local clr_cfg = Div{parent=root_pane_div,x=1,y=1} local summary = Div{parent=root_pane_div,x=1,y=1} local changelog = Div{parent=root_pane_div,x=1,y=1} - local main_pane = MultiPane{parent=root_pane_div,x=1,y=1,panes={main_page,net_cfg,fac_cfg,mon_cfg,spkr_cfg,crd_cfg,log_cfg,summary,changelog}} + local main_pane = MultiPane{parent=root_pane_div,x=1,y=1,panes={main_page,net_cfg,fac_cfg,mon_cfg,spkr_cfg,crd_cfg,log_cfg,clr_cfg,summary,changelog}} -- Main Page @@ -337,7 +352,7 @@ local function config_view(display) tool_ctl.viewing_config = true tool_ctl.gen_summary(settings_cfg) tool_ctl.settings_apply.hide(true) - main_pane.set_value(8) + main_pane.set_value(9) end if fs.exists("/coordinator/config.lua") then @@ -348,10 +363,21 @@ local function config_view(display) PushButton{parent=main_page,x=2,y=y_start,min_width=18,text="Configure System",callback=function()main_pane.set_value(2)end,fg_bg=cpair(colors.black,colors.blue),active_fg_bg=btn_act_fg_bg} tool_ctl.view_cfg = PushButton{parent=main_page,x=2,y=y_start+2,min_width=20,text="View Configuration",callback=view_config,fg_bg=cpair(colors.black,colors.blue),active_fg_bg=btn_act_fg_bg,dis_fg_bg=dis_fg_bg} - if not tool_ctl.has_config then tool_ctl.view_cfg.disable() end + local function jump_color() + tool_ctl.jumped_to_color = true + tool_ctl.color_next.hide() + tool_ctl.color_apply.show(true) + main_pane.set_value(8) + end PushButton{parent=main_page,x=2,y=17,min_width=6,text="Exit",callback=exit,fg_bg=cpair(colors.black,colors.red),active_fg_bg=btn_act_fg_bg} - PushButton{parent=main_page,x=39,y=17,min_width=12,text="Change Log",callback=function()main_pane.set_value(9)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + tool_ctl.color_cfg = PushButton{parent=main_page,x=23,y=17,min_width=15,text="Color Options",callback=jump_color,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + PushButton{parent=main_page,x=39,y=17,min_width=12,text="Change Log",callback=function()main_pane.set_value(10)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + + if not tool_ctl.has_config then + tool_ctl.view_cfg.disable() + tool_ctl.color_cfg.disable() + end --#region Network @@ -697,7 +723,7 @@ local function config_view(display) mon_pane.set_value(1) end - PushButton{parent=mon_c_4,x=1,y=14,text="\x1b Back",callback=back_from_legacy,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + PushButton{parent=mon_c_4,x=44,y=14,min_width=6,text="Done",callback=back_from_legacy,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} --#endregion @@ -734,8 +760,6 @@ local function config_view(display) local crd_c_1 = Div{parent=crd_cfg,x=2,y=4,width=49} - local crd_pane = MultiPane{parent=crd_cfg,x=1,y=4,panes={crd_c_1}} - TextBox{parent=crd_cfg,x=1,y=2,height=1,text=" Coordinator UI Configuration",fg_bg=cpair(colors.black,colors.lime)} TextBox{parent=crd_c_1,x=1,y=1,height=3,text="Configure the UI interface options below if you wish to customize formats."} @@ -782,10 +806,8 @@ local function config_view(display) tmp_cfg.LogMode = mode.get_value() - 1 tmp_cfg.LogPath = path.get_value() tmp_cfg.LogDebug = en_dbg.get_value() - tool_ctl.gen_summary(tmp_cfg) - tool_ctl.viewing_config = false - tool_ctl.importing_legacy = false - tool_ctl.settings_apply.show() + tool_ctl.color_apply.hide() + tool_ctl.color_next.show(true) main_pane.set_value(8) else path_err.show() end end @@ -795,6 +817,115 @@ local function config_view(display) --#endregion + --#region Color Options + + local clr_c_1 = Div{parent=clr_cfg,x=2,y=4,width=49} + local clr_c_2 = Div{parent=clr_cfg,x=2,y=4,width=49} + local clr_c_3 = Div{parent=clr_cfg,x=2,y=4,width=49} + local clr_c_4 = Div{parent=clr_cfg,x=2,y=4,width=49} + + local clr_pane = MultiPane{parent=clr_cfg,x=1,y=4,panes={clr_c_1,clr_c_2,clr_c_3,clr_c_4}} + + TextBox{parent=clr_cfg,x=1,y=2,height=1,text=" Color Configuration",fg_bg=cpair(colors.black,colors.magenta)} + + TextBox{parent=clr_c_1,x=1,y=1,height=2,text="Here you can select the color themes for the different UI displays."} + TextBox{parent=clr_c_1,x=1,y=4,height=2,text="Click 'Accessibility' below to access color blind assistive options.",fg_bg=g_lg_fg_bg} + + TextBox{parent=clr_c_1,x=1,y=7,height=1,text="Main UI Theme"} + local main_theme = RadioButton{parent=clr_c_1,x=1,y=8,default=ini_cfg.MainTheme,options={"Smooth Stone","Deepslate"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + + TextBox{parent=clr_c_1,x=18,y=7,height=1,text="Front Panel Theme"} + local fp_theme = RadioButton{parent=clr_c_1,x=18,y=8,default=ini_cfg.FrontPanelTheme,options={"Sandstone","Basalt"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + + TextBox{parent=clr_c_2,x=1,y=1,height=6,text="By default, this project uses green/red heavily to distinguish ok and not, with some indicators also using multiple colors. By selecting a color blindness below, blues will be used instead of greens on indicators and multi-color indicators will be split up as space permits."} + + local function recolor(value) + if value == 1 then + for i = 1, #style.colors do term.setPaletteColor(style.colors[i].c, style.colors[i].hex) end + elseif value == 2 then + term.setPaletteColor(colors.green, 0x1081ff) + term.setPaletteColor(colors.yellow, 0xf5e633) + term.setPaletteColor(colors.red, 0xff521a) + elseif value == 3 then + term.setPaletteColor(colors.green, 0x1081ff) + term.setPaletteColor(colors.yellow, 0xf7c311) + term.setPaletteColor(colors.red, 0xfb5615) + elseif value == 4 then + term.setPaletteColor(colors.green, 0x00ecff) + term.setPaletteColor(colors.yellow, 0xffbc00) + term.setPaletteColor(colors.red, 0xff0000) + end + end + + local c_mode = RadioButton{parent=clr_c_2,x=1,y=8,default=ini_cfg.ColorMode,options={"None","Protanopia","Deuteranopia","Tritanopia"},callback=recolor,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.magenta} + + local _ = IndLight{parent=clr_c_2,x=20,y=8,label="Good",colors=cpair(colors.black,colors.green),value=true} + _ = IndLight{parent=clr_c_2,x=20,y=9,label="Warning",colors=cpair(colors.black,colors.yellow),value=true} + _ = IndLight{parent=clr_c_2,x=20,y=10,label="Bad",colors=cpair(colors.black,colors.red),value=true} + + TextBox{parent=clr_c_2,x=20,y=12,height=6,text="Exact color varies by theme.",fg_bg=g_lg_fg_bg} + + PushButton{parent=clr_c_2,x=44,y=14,min_width=6,text="Done",callback=function()clr_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + + local function back_from_colors() + main_pane.set_value(util.trinary(tool_ctl.jumped_to_color, 1, 7)) + tool_ctl.jumped_to_color = false + recolor(1) + end + + local function show_access() + clr_pane.set_value(2) + recolor(c_mode.get_value()) + end + + local function submit_colors() + tmp_cfg.MainTheme = main_theme.get_value() + tmp_cfg.FrontPanelTheme = fp_theme.get_value() + tmp_cfg.ColorMode = c_mode.get_value() + + if tool_ctl.jumped_to_color then + settings.set("MainTheme", tmp_cfg.MainTheme) + settings.set("FrontPanelTheme", tmp_cfg.FrontPanelTheme) + settings.set("ColorMode", tmp_cfg.ColorMode) + + if settings.save("/coordinator.settings") then + load_settings(settings_cfg, true) + load_settings(ini_cfg) + clr_pane.set_value(3) + else + clr_pane.set_value(4) + end + else + tool_ctl.gen_summary(tmp_cfg) + tool_ctl.viewing_config = false + tool_ctl.importing_legacy = false + tool_ctl.settings_apply.show() + main_pane.set_value(9) + end + end + + PushButton{parent=clr_c_1,x=1,y=14,text="\x1b Back",callback=back_from_colors,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + PushButton{parent=clr_c_1,x=8,y=14,min_width=15,text="Accessibility",callback=show_access,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + tool_ctl.color_next = PushButton{parent=clr_c_1,x=44,y=14,text="Next \x1a",callback=submit_colors,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + tool_ctl.color_apply = PushButton{parent=clr_c_1,x=43,y=14,min_width=7,text="Apply",callback=submit_colors,fg_bg=cpair(colors.black,colors.green),active_fg_bg=btn_act_fg_bg} + + tool_ctl.color_apply.hide() + + local function c_go_home() + main_pane.set_value(1) + clr_pane.set_value(1) + end + + TextBox{parent=clr_c_3,x=1,y=1,height=1,text="Settings saved!"} + PushButton{parent=clr_c_3,x=1,y=14,min_width=6,text="Exit",callback=exit,fg_bg=cpair(colors.black,colors.red),active_fg_bg=cpair(colors.white,colors.gray)} + PushButton{parent=clr_c_3,x=44,y=14,min_width=6,text="Home",callback=c_go_home,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + + TextBox{parent=clr_c_4,x=1,y=1,height=5,text="Failed to save the settings file.\n\nThere may not be enough space for the modification or server file permissions may be denying writes."} + PushButton{parent=clr_c_4,x=1,y=14,min_width=6,text="Exit",callback=exit,fg_bg=cpair(colors.black,colors.red),active_fg_bg=cpair(colors.white,colors.gray)} + PushButton{parent=clr_c_4,x=44,y=14,min_width=6,text="Home",callback=c_go_home,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + + --#endregion + --#region Summary and Saving local sum_c_1 = Div{parent=summary,x=2,y=4,width=49} @@ -815,7 +946,7 @@ local function config_view(display) tool_ctl.importing_legacy = false tool_ctl.settings_apply.show() else - main_pane.set_value(7) + main_pane.set_value(8) end end @@ -846,12 +977,16 @@ local function config_view(display) try_set(mode, ini_cfg.LogMode) try_set(path, ini_cfg.LogPath) try_set(en_dbg, ini_cfg.LogDebug) + try_set(main_theme, ini_cfg.MainTheme) + try_set(fp_theme, ini_cfg.FrontPanelTheme) + try_set(c_mode, ini_cfg.ColorMode) preset_monitor_fields() tool_ctl.gen_mon_list() tool_ctl.view_cfg.enable() + tool_ctl.color_cfg.enable() if tool_ctl.importing_legacy then tool_ctl.importing_legacy = false @@ -875,7 +1010,7 @@ local function config_view(display) net_pane.set_value(1) fac_pane.set_value(1) mon_pane.set_value(1) - crd_pane.set_value(1) + clr_pane.set_value(1) sum_pane.set_value(1) end @@ -972,7 +1107,7 @@ local function config_view(display) tool_ctl.gen_summary(tmp_cfg) sum_pane.set_value(1) - main_pane.set_value(8) + main_pane.set_value(9) tool_ctl.importing_legacy = true end @@ -1196,6 +1331,12 @@ local function config_view(display) elseif f[1] == "LogMode" then val = util.trinary(raw == log.MODE.APPEND, "append", "replace") elseif f[1] == "TempScale" then if raw == 1 then val = "Kelvin" elseif raw == 2 then val = "Celsius" elseif raw == 3 then val = "Fahrenheit" else val = "Rankine" end + elseif f[1] == "MainTheme" then + if raw == 1 then val = "Smooth Stone" else val = "Deepslate" end + elseif f[1] == "FrontPanelTheme" then + if raw == 1 then val = "Sandstone" else val = "Basalt" end + elseif f[1] == "ColorMode" then + if raw == 1 then val = "Standard" elseif raw == 2 then val = "Protanopia" elseif raw == 3 then val = "Deuteranopia" else val = "Tritanopia" end elseif f[1] == "UnitDisplays" and type(cfg.UnitDisplays) == "table" then val = "" for idx = 1, #cfg.UnitDisplays do diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index bc97c99..61b854b 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -54,6 +54,10 @@ function coordinator.load_config() config.LogPath = settings.get("LogPath") config.LogDebug = settings.get("LogDebug") + config.MainTheme = settings.get("MainTheme") + config.FrontPanelTheme = settings.get("FrontPanelTheme") + config.ColorMode = settings.get("ColorMode") + local cfv = util.new_validator() cfv.assert_type_int(config.UnitCount) @@ -89,7 +93,13 @@ function coordinator.load_config() cfv.assert_type_int(config.LogMode) cfv.assert_range(config.LogMode, 0, 1) cfv.assert_type_str(config.LogPath) - cfv.assert_type_bool(config.LogDebug) + + cfv.assert_type_int(config.MainTheme) + cfv.assert_range(config.MainTheme, 1, 2) + cfv.assert_type_int(config.FrontPanelTheme) + cfv.assert_range(config.FrontPanelTheme, 1, 2) + cfv.assert_type_int(config.ColorMode) + cfv.assert_range(config.ColorMode, 1, 4) -- Monitor Setup diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 45583b9..feeafd0 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -22,6 +22,8 @@ local sounder = require("coordinator.sounder") local apisessions = require("coordinator.session.apisessions") +local style = require("coordinator.ui.style") + local COORDINATOR_VERSION = "v1.2.12" local CHUNK_LOAD_DELAY_S = 30.0 @@ -120,6 +122,7 @@ local function main() iocontrol.init_fp(COORDINATOR_VERSION, comms.version) -- init renderer + style.set_themes(config.MainTheme, config.FrontPanelTheme) renderer.legacy_disable_flow_view(config.DisableFlowView) renderer.set_displays(monitors) renderer.init_displays() diff --git a/coordinator/ui/components/boiler.lua b/coordinator/ui/components/boiler.lua index e29b188..0b7843f 100644 --- a/coordinator/ui/components/boiler.lua +++ b/coordinator/ui/components/boiler.lua @@ -14,15 +14,15 @@ local VerticalBar = require("graphics.elements.indicators.vbar") local cpair = core.cpair local border = core.border -local text_fg = style.theme.text_fg -local lu_col = style.lu_colors - -- new boiler view ---@param root graphics_element parent ---@param x integer top left x ---@param y integer top left y ---@param ps psil ps interface local function new_view(root, x, y, ps) + local text_fg = style.theme.text_fg + local lu_col = style.lu_colors + local db = iocontrol.get_db() local boiler = Rectangle{parent=root,border=border(1,colors.gray,true),width=31,height=7,x=x,y=y} diff --git a/coordinator/ui/components/imatrix.lua b/coordinator/ui/components/imatrix.lua index 6d8fc38..078661a 100644 --- a/coordinator/ui/components/imatrix.lua +++ b/coordinator/ui/components/imatrix.lua @@ -18,9 +18,6 @@ local border = core.border local ALIGN = core.ALIGN -local text_fg = style.theme.text_fg -local lu_col = style.lu_colors - -- new induction matrix view ---@param root graphics_element parent ---@param x integer top left x @@ -29,6 +26,9 @@ local lu_col = style.lu_colors ---@param ps psil ps interface ---@param id number? matrix ID local function new_view(root, x, y, data, ps, id) + local text_fg = style.theme.text_fg + local lu_col = style.lu_colors + local title = "INDUCTION MATRIX" if type(id) == "number" then title = title .. id end diff --git a/coordinator/ui/components/pkt_entry.lua b/coordinator/ui/components/pkt_entry.lua index 42f19a4..760f406 100644 --- a/coordinator/ui/components/pkt_entry.lua +++ b/coordinator/ui/components/pkt_entry.lua @@ -17,15 +17,15 @@ local ALIGN = core.ALIGN local cpair = core.cpair -local s_hi_box = style.fp_theme.highlight_box -local s_hi_bright = style.fp_theme.highlight_box_bright - -local label_fg = style.fp.label_fg - -- create a pocket list entry ---@param parent graphics_element parent ---@param id integer PKT session ID local function init(parent, id) + local s_hi_box = style.fp_theme.highlight_box + local s_hi_bright = style.fp_theme.highlight_box_bright + + local label_fg = style.fp.label_fg + local ps = iocontrol.get_db().fp.ps -- root div diff --git a/coordinator/ui/components/process_ctl.lua b/coordinator/ui/components/process_ctl.lua index 572be85..32286c8 100644 --- a/coordinator/ui/components/process_ctl.lua +++ b/coordinator/ui/components/process_ctl.lua @@ -28,14 +28,6 @@ local ALIGN = core.ALIGN local cpair = core.cpair local border = core.border -local s_hi_box = style.theme.highlight_box -local s_field = style.theme.field_box - -local lu_cpair = style.lu_colors -local hzd_fg_bg = style.hzd_fg_bg -local dis_colors = style.dis_colors -local arrow_fg_bg = cpair(style.theme.label, s_hi_box.bkg) - local bw_fg_bg = style.bw_fg_bg local ind_grn = style.ind_grn @@ -50,6 +42,14 @@ local period = core.flasher.PERIOD ---@param x integer top left x ---@param y integer top left y local function new_view(root, x, y) + local s_hi_box = style.theme.highlight_box + local s_field = style.theme.field_box + + local lu_cpair = style.lu_colors + local hzd_fg_bg = style.hzd_fg_bg + local dis_colors = style.dis_colors + local arrow_fg_bg = cpair(style.theme.label, s_hi_box.bkg) + assert(root.get_height() >= (y + 24), "main display not of sufficient vertical resolution (add an additional row of monitors)") local black = cpair(colors.black, colors.black) diff --git a/coordinator/ui/components/reactor.lua b/coordinator/ui/components/reactor.lua index 3e2026c..8e6005d 100644 --- a/coordinator/ui/components/reactor.lua +++ b/coordinator/ui/components/reactor.lua @@ -16,15 +16,15 @@ local StateIndicator = require("graphics.elements.indicators.state") local cpair = core.cpair local border = core.border -local text_fg = style.theme.text_fg -local lu_col = style.lu_colors - -- create new reactor view ---@param root graphics_element parent ---@param x integer top left x ---@param y integer top left y ---@param ps psil ps interface local function new_view(root, x, y, ps) + local text_fg = style.theme.text_fg + local lu_col = style.lu_colors + local db = iocontrol.get_db() local reactor = Rectangle{parent=root,border=border(1,colors.gray,true),width=30,height=7,x=x,y=y} diff --git a/coordinator/ui/components/turbine.lua b/coordinator/ui/components/turbine.lua index 236dbbb..75cbabd 100644 --- a/coordinator/ui/components/turbine.lua +++ b/coordinator/ui/components/turbine.lua @@ -15,15 +15,15 @@ local VerticalBar = require("graphics.elements.indicators.vbar") local cpair = core.cpair local border = core.border -local text_fg = style.theme.text_fg -local lu_col = style.lu_colors - -- new turbine view ---@param root graphics_element parent ---@param x integer top left x ---@param y integer top left y ---@param ps psil ps interface local function new_view(root, x, y, ps) + local text_fg = style.theme.text_fg + local lu_col = style.lu_colors + local turbine = Rectangle{parent=root,border=border(1,colors.gray,true),width=23,height=7,x=x,y=y} local status = StateIndicator{parent=turbine,x=7,y=1,states=style.turbine.states,value=1,min_width=12} diff --git a/coordinator/ui/components/unit_detail.lua b/coordinator/ui/components/unit_detail.lua index 363470e..d76c9d8 100644 --- a/coordinator/ui/components/unit_detail.lua +++ b/coordinator/ui/components/unit_detail.lua @@ -34,16 +34,6 @@ local ALIGN = core.ALIGN local cpair = core.cpair local border = core.border -local s_hi_box = style.theme.highlight_box -local s_hi_bright = style.theme.highlight_box_bright -local s_field = style.theme.field_box - -local hc_text = style.hc_text -local lu_cpair = style.lu_colors -local hzd_fg_bg = style.hzd_fg_bg -local dis_colors = style.dis_colors -local arrow_fg_bg = cpair(style.theme.label, s_hi_box.bkg) - local bw_fg_bg = style.bw_fg_bg local gry_wht = style.gray_white @@ -58,6 +48,16 @@ local period = core.flasher.PERIOD ---@param parent graphics_element parent ---@param id integer local function init(parent, id) + local s_hi_box = style.theme.highlight_box + local s_hi_bright = style.theme.highlight_box_bright + local s_field = style.theme.field_box + + local hc_text = style.hc_text + local lu_cpair = style.lu_colors + local hzd_fg_bg = style.hzd_fg_bg + local dis_colors = style.dis_colors + local arrow_fg_bg = cpair(style.theme.label, s_hi_box.bkg) + local db = iocontrol.get_db() local unit = db.units[id] ---@type ioctl_unit local f_ps = db.facility.ps diff --git a/coordinator/ui/components/unit_flow.lua b/coordinator/ui/components/unit_flow.lua index 9dfd4c1..115450b 100644 --- a/coordinator/ui/components/unit_flow.lua +++ b/coordinator/ui/components/unit_flow.lua @@ -27,12 +27,6 @@ local border = core.border local cpair = core.cpair local pipe = core.pipe -local s_field = style.theme.field_box - -local text_c = style.text_colors -local lu_c = style.lu_colors -local lu_c_d = style.lu_colors_dark - local wh_gray = style.wh_gray local lg_gray = style.lg_gray @@ -46,6 +40,12 @@ local ind_wht = style.ind_wht ---@param wide boolean whether to render wide version ---@param unit ioctl_unit unit database entry local function make(parent, x, y, wide, unit) + local s_field = style.theme.field_box + + local text_c = style.text_colors + local lu_c = style.lu_colors + local lu_c_d = style.lu_colors_dark + local height = 16 local v_start = 1 + ((unit.unit_id - 1) * 5) diff --git a/coordinator/ui/layout/flow_view.lua b/coordinator/ui/layout/flow_view.lua index 39e51f8..98d16e9 100644 --- a/coordinator/ui/layout/flow_view.lua +++ b/coordinator/ui/layout/flow_view.lua @@ -31,17 +31,17 @@ local cpair = core.cpair local border = core.border local pipe = core.pipe -local s_hi_bright = style.theme.highlight_box_bright -local s_field = style.theme.field_box - local wh_gray = style.wh_gray -local text_col = style.text_colors -local lu_col = style.lu_colors -local lu_c_d = style.lu_colors_dark -- create new flow view ---@param main graphics_element main displaybox local function init(main) + local s_hi_bright = style.theme.highlight_box_bright + local s_field = style.theme.field_box + local text_col = style.text_colors + local lu_col = style.lu_colors + local lu_c_d = style.lu_colors_dark + local facility = iocontrol.get_db().facility local units = iocontrol.get_db().units diff --git a/coordinator/ui/layout/main_view.lua b/coordinator/ui/layout/main_view.lua index 9598e42..f31c200 100644 --- a/coordinator/ui/layout/main_view.lua +++ b/coordinator/ui/layout/main_view.lua @@ -18,11 +18,11 @@ local DataIndicator = require("graphics.elements.indicators.data") local ALIGN = core.ALIGN -local s_header = style.theme.header - -- create new main view ---@param main graphics_element main displaybox local function init(main) + local s_header = style.theme.header + local facility = iocontrol.get_db().facility local units = iocontrol.get_db().units diff --git a/coordinator/ui/style.lua b/coordinator/ui/style.lua index baad776..fc8a77f 100644 --- a/coordinator/ui/style.lua +++ b/coordinator/ui/style.lua @@ -105,8 +105,7 @@ local deepslate = { } } -style.theme = deepslate --- style.theme = smooth_stone +style.theme = smooth_stone style.root = cpair(style.theme.text, style.theme.bg) style.label = cpair(style.theme.label, style.theme.bg) @@ -120,6 +119,33 @@ style.lu_colors = cpair(style.theme.label, style.theme.label) -- label & unit colors (darker if set) style.lu_colors_dark = cpair(style.theme.label_dark, style.theme.label_dark) +-- set themes per configurations +---@param main integer main theme ID (1 = smooth_stone, 2 = deepslate) +---@param fp integer fp theme ID (1 = sandstone, 2 = basalt) +function style.set_themes(main, fp) + if main == 1 then + style.theme = smooth_stone + elseif main == 2 then + style.theme = deepslate + end + + style.root = cpair(style.theme.text, style.theme.bg) + style.label = cpair(style.theme.label, style.theme.bg) + + style.hc_text = cpair(style.theme.text, style.theme.text_inv) + style.text_colors = cpair(style.theme.text, style.theme.bg) + style.lu_colors = cpair(style.theme.label, style.theme.label) + style.lu_colors_dark = cpair(style.theme.label_dark, style.theme.label_dark) + + if fp == 1 then + style.fp_theme = themes.sandstone + elseif fp == 2 then + style.fp_theme = themes.basalt + end + + style.fp = themes.get_fp_style(style.fp_theme) +end + -- COMMON COLOR PAIRS -- style.wh_gray = cpair(colors.white, colors.gray) diff --git a/graphics/themes.lua b/graphics/themes.lua index 0da2037..1be7238 100644 --- a/graphics/themes.lua +++ b/graphics/themes.lua @@ -103,14 +103,4 @@ function themes.get_fp_style(theme) return style end - - - - - - - - - - return themes