From 57dc20692b09b238b6bc35dead741656043bd194 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 13 Apr 2024 16:15:20 -0400 Subject: [PATCH] need to use a compact signal bar due to how edge extensions work --- graphics/elements/indicators/signal.lua | 29 ++++++++++++++++++------- pocket/ui/main.lua | 6 ++--- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/graphics/elements/indicators/signal.lua b/graphics/elements/indicators/signal.lua index fb21ca0..7e9c1b8 100644 --- a/graphics/elements/indicators/signal.lua +++ b/graphics/elements/indicators/signal.lua @@ -5,6 +5,7 @@ local util = require("scada-common.util") local element = require("graphics.element") ---@class signal_bar_args +---@field compact? boolean true to use a single character (works better against edges that extend out colors) ---@field colors_low_med? cpair color a for low signal quality, color b for medium signal quality ---@field disconnect_color? color color for the 'x' on disconnect ---@field parent graphics_element @@ -20,7 +21,7 @@ local element = require("graphics.element") ---@return graphics_element element, element_id id local function signal_bar(args) args.height = 1 - args.width = 2 + args.width = util.trinary(args.compact, 1, 2) -- create new graphics element base object local e = element.new(args) @@ -52,14 +53,26 @@ local function signal_bar(args) function e.redraw() e.w_set_cur(1, 1) - if e.value == 1 then - e.w_blit("\x9f ", blit_bkg .. blit_bkg, blit_1 .. blit_bkg) - elseif e.value == 2 then - e.w_blit("\x9f\x94", blit_bkg .. blit_2, blit_2 .. blit_bkg) - elseif e.value == 3 then - e.w_blit("\x9f\x81", blit_bkg .. blit_bkg, blit_3 .. blit_3) + if args.compact then + if e.value == 1 then + e.w_blit("\x90", blit_1, blit_bkg) + elseif e.value == 2 then + e.w_blit("\x94", blit_2, blit_bkg) + elseif e.value == 3 then + e.w_blit("\x95", blit_3, blit_bkg) + else + e.w_blit("x", blit_0, blit_bkg) + end else - e.w_blit(" x", blit_0 .. blit_0, blit_bkg .. blit_bkg) + if e.value == 1 then + e.w_blit("\x9f ", blit_bkg .. blit_bkg, blit_1 .. blit_bkg) + elseif e.value == 2 then + e.w_blit("\x9f\x94", blit_bkg .. blit_2, blit_2 .. blit_bkg) + elseif e.value == 3 then + e.w_blit("\x9f\x81", blit_bkg .. blit_bkg, blit_3 .. blit_3) + else + e.w_blit(" x", blit_0 .. blit_0, blit_bkg .. blit_bkg) + end end end diff --git a/pocket/ui/main.lua b/pocket/ui/main.lua index 110998f..1667693 100644 --- a/pocket/ui/main.lua +++ b/pocket/ui/main.lua @@ -37,9 +37,9 @@ local function init(main) local db = iocontrol.get_db() -- window header message - TextBox{parent=main,y=1,text="DEV ALPHA APP S C ",alignment=ALIGN.LEFT,height=1,fg_bg=style.header} - local svr_conn = SignalBar{parent=main,y=1,x=20,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.white,colors.gray)} - local crd_conn = SignalBar{parent=main,y=1,x=24,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.white,colors.gray)} + TextBox{parent=main,y=1,text="DEV 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)} db.ps.subscribe("svr_conn_quality", svr_conn.set_value) db.ps.subscribe("crd_conn_quality", crd_conn.set_value)