From f9aa75a1055e6a411ddc9eaa0e636f8aceeddc1a Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Thu, 25 May 2023 17:40:16 -0400 Subject: [PATCH] graphics element hidden on creation option, changed hide/show logic to only hide/show current element --- coordinator/startup.lua | 2 +- graphics/element.lua | 62 ++++++++++--------- graphics/elements/animations/waiting.lua | 1 + graphics/elements/colormap.lua | 1 + graphics/elements/controls/hazard_button.lua | 1 + graphics/elements/controls/multi_button.lua | 1 + graphics/elements/controls/push_button.lua | 1 + graphics/elements/controls/radio_button.lua | 1 + graphics/elements/controls/sidebar.lua | 1 + .../elements/controls/spinbox_numeric.lua | 1 + graphics/elements/controls/switch_button.lua | 1 + graphics/elements/controls/tabbar.lua | 1 + graphics/elements/displaybox.lua | 1 + graphics/elements/div.lua | 1 + graphics/elements/indicators/alight.lua | 1 + graphics/elements/indicators/data.lua | 1 + graphics/elements/indicators/hbar.lua | 1 + graphics/elements/indicators/icon.lua | 1 + graphics/elements/indicators/led.lua | 1 + graphics/elements/indicators/ledpair.lua | 1 + graphics/elements/indicators/ledrgb.lua | 1 + graphics/elements/indicators/light.lua | 1 + graphics/elements/indicators/power.lua | 1 + graphics/elements/indicators/rad.lua | 1 + graphics/elements/indicators/state.lua | 1 + graphics/elements/indicators/trilight.lua | 1 + graphics/elements/indicators/vbar.lua | 1 + graphics/elements/multipane.lua | 1 + graphics/elements/pipenet.lua | 1 + graphics/elements/rectangle.lua | 1 + graphics/elements/textbox.lua | 1 + graphics/elements/tiling.lua | 1 + pocket/startup.lua | 2 +- reactor-plc/startup.lua | 2 +- rtu/startup.lua | 2 +- supervisor/startup.lua | 2 +- 36 files changed, 69 insertions(+), 33 deletions(-) diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 367c1ca..60a0c88 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -20,7 +20,7 @@ local sounder = require("coordinator.sounder") local apisessions = require("coordinator.session.apisessions") -local COORDINATOR_VERSION = "v0.15.2" +local COORDINATOR_VERSION = "v0.15.3" local println = util.println local println_ts = util.println_ts diff --git a/graphics/element.lua b/graphics/element.lua index b865af0..c6dbaa7 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -18,6 +18,7 @@ local element = {} ---@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 ---@alias graphics_args graphics_args_generic ---|waiting_args @@ -153,7 +154,7 @@ function element.new(args) assert(f.h >= 1, name_brief .. "frame height not >= 1") -- create window - protected.window = window.create(self.p_window, f.x, f.y, f.w, f.h, true) + protected.window = window.create(self.p_window, f.x, f.y, f.w, f.h, args.hidden ~= true) -- init colors if args.fg_bg ~= nil then @@ -385,25 +386,6 @@ function element.new(args) return nil end - -- DYNAMIC CHILD ELEMENTS -- - - -- insert an element as a contained child
- -- this is intended to be used dynamically, and depends on the target element type.
- -- not all elements support dynamic children. - ---@param id string|integer element identifier - ---@param elem graphics_element element - function public.insert_element(id, elem) - protected.insert(id, elem) - end - - -- remove an element from contained children
- -- this is intended to be used dynamically, and depends on the target element type.
- -- not all elements support dynamic children. - ---@param id string|integer element identifier - function public.remove_element(id) - protected.remove(id) - end - -- AUTO-PLACEMENT -- -- skip a line for automatically placed elements @@ -545,22 +527,46 @@ function element.new(args) ps.subscribe(key, func) end - -- VISIBILITY -- + -- VISIBILITY & ANIMATIONS -- - -- show the element - function public.show() + -- show the element and enables animations by default + ---@param animate? boolean true (default) to automatically resume animations + function public.show(animate) protected.window.setVisible(true) - protected.start_anim() - for _, child in pairs(self.children) do child.show() end + if animate ~= false then public.animate_all() end end - -- hide the element + -- hide the element and disables animations function public.hide() - protected.stop_anim() - for _, child in pairs(self.children) do child.hide() end + public.freeze_all() -- stop animations for efficiency/performance protected.window.setVisible(false) end + -- start/resume animation(s) + function public.animate() + protected.start_anim() + end + + -- start/resume animation(s) for this element and all its children
+ -- only animates if a window is visible + function public.animate_all() + if protected.window.isVisible() then + public.animate() + for _, child in pairs(self.children) do child.animate_all() end + end + end + + -- freeze animation(s) + function public.freeze() + protected.stop_anim() + end + + -- freeze animation(s) for this element and all its children + function public.freeze_all() + public.freeze() + for _, child in pairs(self.children) do child.freeze_all() end + end + -- re-draw the element function public.redraw() protected.window.redraw() diff --git a/graphics/elements/animations/waiting.lua b/graphics/elements/animations/waiting.lua index a0d7b3e..9d88c91 100644 --- a/graphics/elements/animations/waiting.lua +++ b/graphics/elements/animations/waiting.lua @@ -10,6 +10,7 @@ local element = require("graphics.element") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new waiting animation element ---@param args waiting_args diff --git a/graphics/elements/colormap.lua b/graphics/elements/colormap.lua index 4c7ba94..f494158 100644 --- a/graphics/elements/colormap.lua +++ b/graphics/elements/colormap.lua @@ -9,6 +9,7 @@ local element = require("graphics.element") ---@field id? string element id ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted +---@field hidden? boolean true to hide on initial draw -- new color map ---@param args colormap_args diff --git a/graphics/elements/controls/hazard_button.lua b/graphics/elements/controls/hazard_button.lua index 4dca5c4..844a6c8 100644 --- a/graphics/elements/controls/hazard_button.lua +++ b/graphics/elements/controls/hazard_button.lua @@ -16,6 +16,7 @@ local element = require("graphics.element") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new hazard button ---@param args hazard_button_args diff --git a/graphics/elements/controls/multi_button.lua b/graphics/elements/controls/multi_button.lua index e44bad0..ca6600b 100644 --- a/graphics/elements/controls/multi_button.lua +++ b/graphics/elements/controls/multi_button.lua @@ -23,6 +23,7 @@ local element = require("graphics.element") ---@field y? integer 1 if omitted ---@field height? integer parent height if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new multi button (latch selection, exclusively one button at a time) ---@param args multi_button_args diff --git a/graphics/elements/controls/push_button.lua b/graphics/elements/controls/push_button.lua index 27be991..cfcd772 100644 --- a/graphics/elements/controls/push_button.lua +++ b/graphics/elements/controls/push_button.lua @@ -19,6 +19,7 @@ local CLICK_TYPE = core.events.CLICK_TYPE ---@field y? integer 1 if omitted ---@field height? integer parent height if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new push button ---@param args push_button_args diff --git a/graphics/elements/controls/radio_button.lua b/graphics/elements/controls/radio_button.lua index 050bf39..6fc5d56 100644 --- a/graphics/elements/controls/radio_button.lua +++ b/graphics/elements/controls/radio_button.lua @@ -15,6 +15,7 @@ local element = require("graphics.element") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new radio button list (latch selection, exclusively one button at a time) ---@param args radio_button_args diff --git a/graphics/elements/controls/sidebar.lua b/graphics/elements/controls/sidebar.lua index 45771b2..7dae6ed 100644 --- a/graphics/elements/controls/sidebar.lua +++ b/graphics/elements/controls/sidebar.lua @@ -20,6 +20,7 @@ local CLICK_TYPE = core.events.CLICK_TYPE ---@field y? integer 1 if omitted ---@field height? integer parent height if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new sidebar tab selector ---@param args sidebar_args diff --git a/graphics/elements/controls/spinbox_numeric.lua b/graphics/elements/controls/spinbox_numeric.lua index 6b88c0e..bcdc9e5 100644 --- a/graphics/elements/controls/spinbox_numeric.lua +++ b/graphics/elements/controls/spinbox_numeric.lua @@ -18,6 +18,7 @@ local element = require("graphics.element") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new spinbox control (minimum value is 0) ---@param args spinbox_args diff --git a/graphics/elements/controls/switch_button.lua b/graphics/elements/controls/switch_button.lua index 645bf8a..e02f506 100644 --- a/graphics/elements/controls/switch_button.lua +++ b/graphics/elements/controls/switch_button.lua @@ -15,6 +15,7 @@ local element = require("graphics.element") ---@field y? integer 1 if omitted ---@field height? integer parent height if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new switch button (latch high/low) ---@param args switch_button_args diff --git a/graphics/elements/controls/tabbar.lua b/graphics/elements/controls/tabbar.lua index 6249951..e188174 100644 --- a/graphics/elements/controls/tabbar.lua +++ b/graphics/elements/controls/tabbar.lua @@ -21,6 +21,7 @@ local element = require("graphics.element") ---@field y? integer 1 if omitted ---@field width? integer parent width if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new tab selector ---@param args tabbar_args diff --git a/graphics/elements/displaybox.lua b/graphics/elements/displaybox.lua index c7e5c9f..f6f520a 100644 --- a/graphics/elements/displaybox.lua +++ b/graphics/elements/displaybox.lua @@ -10,6 +10,7 @@ local element = require("graphics.element") ---@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 -- new root display box ---@nodiscard diff --git a/graphics/elements/div.lua b/graphics/elements/div.lua index 5eeef71..53e3e84 100644 --- a/graphics/elements/div.lua +++ b/graphics/elements/div.lua @@ -11,6 +11,7 @@ local element = require("graphics.element") ---@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 -- new div element ---@nodiscard diff --git a/graphics/elements/indicators/alight.lua b/graphics/elements/indicators/alight.lua index 8bb8fa6..2d933d6 100644 --- a/graphics/elements/indicators/alight.lua +++ b/graphics/elements/indicators/alight.lua @@ -18,6 +18,7 @@ local flasher = require("graphics.flasher") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new alarm indicator light ---@nodiscard diff --git a/graphics/elements/indicators/data.lua b/graphics/elements/indicators/data.lua index 748c17a..a2b4ea9 100644 --- a/graphics/elements/indicators/data.lua +++ b/graphics/elements/indicators/data.lua @@ -17,6 +17,7 @@ local element = require("graphics.element") ---@field y? integer 1 if omitted ---@field width integer length ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new data indicator ---@nodiscard diff --git a/graphics/elements/indicators/hbar.lua b/graphics/elements/indicators/hbar.lua index 2d9b110..f69374e 100644 --- a/graphics/elements/indicators/hbar.lua +++ b/graphics/elements/indicators/hbar.lua @@ -15,6 +15,7 @@ local element = require("graphics.element") ---@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 -- new horizontal bar ---@nodiscard diff --git a/graphics/elements/indicators/icon.lua b/graphics/elements/indicators/icon.lua index f31479d..f079178 100644 --- a/graphics/elements/indicators/icon.lua +++ b/graphics/elements/indicators/icon.lua @@ -18,6 +18,7 @@ local element = require("graphics.element") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new icon indicator ---@nodiscard diff --git a/graphics/elements/indicators/led.lua b/graphics/elements/indicators/led.lua index dd2264e..6a6f829 100644 --- a/graphics/elements/indicators/led.lua +++ b/graphics/elements/indicators/led.lua @@ -16,6 +16,7 @@ local flasher = require("graphics.flasher") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new indicator LED ---@nodiscard diff --git a/graphics/elements/indicators/ledpair.lua b/graphics/elements/indicators/ledpair.lua index 727d4cd..94e6955 100644 --- a/graphics/elements/indicators/ledpair.lua +++ b/graphics/elements/indicators/ledpair.lua @@ -18,6 +18,7 @@ local flasher = require("graphics.flasher") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new dual LED indicator light ---@nodiscard diff --git a/graphics/elements/indicators/ledrgb.lua b/graphics/elements/indicators/ledrgb.lua index 266e0ab..b66d102 100644 --- a/graphics/elements/indicators/ledrgb.lua +++ b/graphics/elements/indicators/ledrgb.lua @@ -11,6 +11,7 @@ local element = require("graphics.element") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new RGB LED indicator light ---@nodiscard diff --git a/graphics/elements/indicators/light.lua b/graphics/elements/indicators/light.lua index e764ad9..8213439 100644 --- a/graphics/elements/indicators/light.lua +++ b/graphics/elements/indicators/light.lua @@ -16,6 +16,7 @@ local flasher = require("graphics.flasher") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new indicator light ---@nodiscard diff --git a/graphics/elements/indicators/power.lua b/graphics/elements/indicators/power.lua index 1d727ae..b7137d7 100644 --- a/graphics/elements/indicators/power.lua +++ b/graphics/elements/indicators/power.lua @@ -16,6 +16,7 @@ local element = require("graphics.element") ---@field y? integer 1 if omitted ---@field width integer length ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new power indicator ---@nodiscard diff --git a/graphics/elements/indicators/rad.lua b/graphics/elements/indicators/rad.lua index 2e4ad56..c843cf4 100644 --- a/graphics/elements/indicators/rad.lua +++ b/graphics/elements/indicators/rad.lua @@ -17,6 +17,7 @@ local element = require("graphics.element") ---@field y? integer 1 if omitted ---@field width integer length ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new radiation indicator ---@nodiscard diff --git a/graphics/elements/indicators/state.lua b/graphics/elements/indicators/state.lua index 10d081b..3bb2831 100644 --- a/graphics/elements/indicators/state.lua +++ b/graphics/elements/indicators/state.lua @@ -18,6 +18,7 @@ local element = require("graphics.element") ---@field y? integer 1 if omitted ---@field height? integer 1 if omitted, must be an odd number ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new state indicator ---@nodiscard diff --git a/graphics/elements/indicators/trilight.lua b/graphics/elements/indicators/trilight.lua index 543ebf5..bbc7526 100644 --- a/graphics/elements/indicators/trilight.lua +++ b/graphics/elements/indicators/trilight.lua @@ -18,6 +18,7 @@ local flasher = require("graphics.flasher") ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted ---@field fg_bg? cpair foreground/background colors +---@field hidden? boolean true to hide on initial draw -- new tri-state indicator light ---@nodiscard diff --git a/graphics/elements/indicators/vbar.lua b/graphics/elements/indicators/vbar.lua index fe7f9bc..9c8a8f4 100644 --- a/graphics/elements/indicators/vbar.lua +++ b/graphics/elements/indicators/vbar.lua @@ -13,6 +13,7 @@ local element = require("graphics.element") ---@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 -- new vertical bar ---@nodiscard diff --git a/graphics/elements/multipane.lua b/graphics/elements/multipane.lua index 8e25bab..20da7ed 100644 --- a/graphics/elements/multipane.lua +++ b/graphics/elements/multipane.lua @@ -12,6 +12,7 @@ local element = require("graphics.element") ---@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 -- new multipane element ---@nodiscard diff --git a/graphics/elements/pipenet.lua b/graphics/elements/pipenet.lua index 8a1d29b..8314fd2 100644 --- a/graphics/elements/pipenet.lua +++ b/graphics/elements/pipenet.lua @@ -12,6 +12,7 @@ local element = require("graphics.element") ---@field id? string element id ---@field x? integer 1 if omitted ---@field y? integer 1 if omitted +---@field hidden? boolean true to hide on initial draw -- new pipe network ---@param args pipenet_args diff --git a/graphics/elements/rectangle.lua b/graphics/elements/rectangle.lua index 2f7a68d..b80b37c 100644 --- a/graphics/elements/rectangle.lua +++ b/graphics/elements/rectangle.lua @@ -16,6 +16,7 @@ local element = require("graphics.element") ---@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 -- new rectangle ---@param args rectangle_args diff --git a/graphics/elements/textbox.lua b/graphics/elements/textbox.lua index 9066deb..6e5717f 100644 --- a/graphics/elements/textbox.lua +++ b/graphics/elements/textbox.lua @@ -18,6 +18,7 @@ local TEXT_ALIGN = core.TEXT_ALIGN ---@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 -- new text box ---@param args textbox_args diff --git a/graphics/elements/tiling.lua b/graphics/elements/tiling.lua index a97438a..0dcaaf8 100644 --- a/graphics/elements/tiling.lua +++ b/graphics/elements/tiling.lua @@ -16,6 +16,7 @@ local element = require("graphics.element") ---@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 -- new tiling box ---@param args tiling_args diff --git a/pocket/startup.lua b/pocket/startup.lua index 2ea5958..9265558 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -17,7 +17,7 @@ local coreio = require("pocket.coreio") local pocket = require("pocket.pocket") local renderer = require("pocket.renderer") -local POCKET_VERSION = "alpha-v0.3.2" +local POCKET_VERSION = "alpha-v0.3.3" local println = util.println local println_ts = util.println_ts diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index 1a7f550..89b5b6d 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc") local renderer = require("reactor-plc.renderer") local threads = require("reactor-plc.threads") -local R_PLC_VERSION = "v1.3.2" +local R_PLC_VERSION = "v1.3.3" local println = util.println local println_ts = util.println_ts diff --git a/rtu/startup.lua b/rtu/startup.lua index 27c7c14..0994261 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -28,7 +28,7 @@ local sna_rtu = require("rtu.dev.sna_rtu") local sps_rtu = require("rtu.dev.sps_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "v1.2.2" +local RTU_VERSION = "v1.2.3" local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 1c3f84c..6dc7253 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -19,7 +19,7 @@ local supervisor = require("supervisor.supervisor") local svsessions = require("supervisor.session.svsessions") -local SUPERVISOR_VERSION = "v0.16.2" +local SUPERVISOR_VERSION = "v0.16.3" local println = util.println local println_ts = util.println_ts