From 3e83c8e2c6099fcee740eb9576d29987b66d6660 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 18 Feb 2024 13:00:18 -0500 Subject: [PATCH] #309 moved monitor block size to ppm and fixed size estimation for monitor requirements --- coordinator/configure.lua | 13 ++++--------- scada-common/ppm.lua | 13 +++++++++++++ scada-common/util.lua | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/coordinator/configure.lua b/coordinator/configure.lua index 7446477..88267cc 100644 --- a/coordinator/configure.lua +++ b/coordinator/configure.lua @@ -587,9 +587,10 @@ local function config_view(display) if tmp_cfg.UnitCount <= 2 then tool_ctl.main_mon_h = util.trinary(row1_tall, 5, 4) else + -- is only one tall and the other short, or are both tall? -> 5 or 6; are neither tall? -> 5 if row1_tall or row2_tall then tool_ctl.main_mon_h = util.trinary((row1_short and row2_tall) or (row1_tall and row2_short), 5, 6) - else tool_ctl.main_mon_h = 6 end + else tool_ctl.main_mon_h = 5 end end else tool_ctl.main_mon_h = util.trinary(tmp_cfg.UnitCount <= 2, 4, 5) @@ -629,12 +630,6 @@ local function config_view(display) local mon_list = ListBox{parent=mon_c_2,x=1,y=6,height=7,width=51,scroll_height=100,fg_bg=bw_fg_bg,nav_fg_bg=g_lg_fg_bg,nav_active=cpair(colors.black,colors.gray)} - local function to_block_size(w, h) - local width = math.floor((w - 15) / 21) + 1 - local height = math.floor((h - 10) / 14) + 1 - return width, height - end - local assign_err = TextBox{parent=mon_c_2,x=8,y=14,height=1,width=35,text="",fg_bg=cpair(colors.red,colors.lightGray),hidden=true} local function submit_monitors() @@ -1052,7 +1047,7 @@ local function config_view(display) tool_ctl.mon_iface = iface local dev = device.dev - local w, h = to_block_size(dev.getSize()) + local w, h = ppm.monitor_block_size(dev.getSize()) local msg = "This size doesn't match a required screen. Please go back and resize it, or configure below at the risk of it not working." @@ -1139,7 +1134,7 @@ local function config_view(display) TextBox{parent=line,x=1,y=1,width=6,height=1,text=assignment,fg_bg=cpair(util.trinary(assignment=="Unused",colors.red,colors.blue),colors.white)} TextBox{parent=line,x=8,y=1,height=1,text=iface} - local w, h = to_block_size(dev.getSize()) + local w, h = ppm.monitor_block_size(dev.getSize()) local function unset_mon() purge_assignments(iface) diff --git a/scada-common/ppm.lua b/scada-common/ppm.lua index d54fec8..37a2ecb 100644 --- a/scada-common/ppm.lua +++ b/scada-common/ppm.lua @@ -421,4 +421,17 @@ function ppm.get_monitor_list() return list end +-- HELPER FUNCTIONS + +-- get the block size of a monitor given its width and height at a text scale of 0.5 +---@nodiscard +---@param w integer character width +---@param h integer character width +---@return integer block_width, integer block_height +function ppm.monitor_block_size(w, h) + local width = math.floor((w - 15) / 21) + 1 + local height = math.floor((h - 10) / 14) + 1 + return width, height +end + return ppm diff --git a/scada-common/util.lua b/scada-common/util.lua index c067c62..f407e36 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -22,7 +22,7 @@ local t_pack = table.pack local util = {} -- scada-common version -util.version = "1.1.12" +util.version = "1.1.13" util.TICK_TIME_S = 0.05 util.TICK_TIME_MS = 50