updated type hints and comments

This commit is contained in:
Mikayla 2024-09-26 21:00:57 +00:00
parent e4cb1f6c70
commit 69855af861
8 changed files with 52 additions and 31 deletions

View File

@ -57,7 +57,7 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
offset_x = 0, offset_x = 0,
offset_y = 0, offset_y = 0,
next_y = 1, -- next child y coordinate next_y = 1, -- next child y coordinate
next_id = 0, -- next child ID[ next_id = 0, -- next child ID
subscriptions = {}, ---@type { ps: psil, key: string, func: function }[] subscriptions = {}, ---@type { ps: psil, key: string, func: function }[]
button_down = { events.new_coord_2d(-1, -1), events.new_coord_2d(-1, -1), events.new_coord_2d(-1, -1) }, button_down = { events.new_coord_2d(-1, -1), events.new_coord_2d(-1, -1), events.new_coord_2d(-1, -1) },
focused = false, focused = false,
@ -87,9 +87,9 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
setmetatable(public, self.mt) setmetatable(public, self.mt)
----------------------- ------------------------------
-- PRIVATE FUNCTIONS -- --#region PRIVATE FUNCTIONS --
----------------------- ------------------------------
-- use tab to jump to the next focusable field -- use tab to jump to the next focusable field
---@param reverse boolean ---@param reverse boolean
@ -150,9 +150,11 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
end end
end end
------------------------- --#endregion
-- PROTECTED FUNCTIONS --
------------------------- --------------------------------
--#region PROTECTED FUNCTIONS --
--------------------------------
-- prepare the template -- prepare the template
---@param offset_x integer x offset for mouse events ---@param offset_x integer x offset for mouse events
@ -371,7 +373,8 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
function protected.on_update(...) end function protected.on_update(...) end
--#endregion --#endregion
--#region Accessors and Control --
--#region Accessors and Control
-- get value -- get value
---@nodiscard ---@nodiscard
@ -409,9 +412,13 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
-- stop animations -- stop animations
function protected.stop_anim() end function protected.stop_anim() end
----------- --#endregion
-- SETUP --
----------- --#endregion
------------------
--#region SETUP --
------------------
-- get the parent window -- get the parent window
self.p_window = args.window self.p_window = args.window
@ -430,9 +437,11 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
self.id = args.parent.__add_child(args.id, protected) self.id = args.parent.__add_child(args.id, protected)
end end
---------------------- --#endregion
-- PUBLIC FUNCTIONS --
---------------------- -----------------------------
--#region PUBLIC FUNCTIONS --
-----------------------------
-- get the window object -- get the window object
---@nodiscard ---@nodiscard
@ -474,7 +483,7 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
end end
end end
-- ELEMENT TREE -- --#region ELEMENT TREE
-- add a child element -- add a child element
---@package ---@package
@ -590,14 +599,18 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
else return ({ protected.children[index].get() })[1] end else return ({ protected.children[index].get() })[1] end
end end
-- AUTO-PLACEMENT -- --#endregion
--#region AUTO-PLACEMENT
-- skip a line for automatically placed elements -- skip a line for automatically placed elements
function public.line_break() function public.line_break()
self.next_y = self.next_y + 1 self.next_y = self.next_y + 1
end end
-- PROPERTIES -- --#endregion
--#region PROPERTIES
-- get element ID -- get element ID
---@nodiscard ---@nodiscard
@ -724,7 +737,9 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
self.bounds.y2 = self.position.y + protected.frame.h - 1 self.bounds.y2 = self.position.y + protected.frame.h - 1
end end
-- FUNCTION CALLBACKS -- --#endregion
--#region FUNCTION CALLBACKS
-- handle a monitor touch or mouse click if this element is visible -- handle a monitor touch or mouse click if this element is visible
---@param event mouse_interaction mouse interaction event ---@param event mouse_interaction mouse interaction event
@ -799,7 +814,9 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
ps.subscribe(key, func) ps.subscribe(key, func)
end end
-- VISIBILITY & ANIMATIONS -- --#endregion
--#region VISIBILITY & ANIMATIONS
-- check if this element is visible -- check if this element is visible
function public.is_visible() return protected.window.isVisible() end function public.is_visible() return protected.window.isVisible() end
@ -865,6 +882,10 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
end end
end end
--#endregion
--#endregion
return protected return protected
end end

View File

@ -20,7 +20,7 @@ local MOUSE_CLICK = core.events.MOUSE_CLICK
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
---@field hidden? boolean true to hide on initial draw ---@field hidden? boolean true to hide on initial draw
-- Create a new 'app' style button control element, like on a phone. -- Create a new app icon style button control element, like on a mobile device.
---@param args app_button_args ---@param args app_button_args
---@return App element, element_id id ---@return App element, element_id id
return function (args) return function (args)

View File

@ -23,7 +23,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
---@field hidden? boolean true to hide on initial draw ---@field hidden? boolean true to hide on initial draw
-- Create a new 2D radio button list control element (latch selection, exclusively one color at a time). -- Create a new 2-dimensional (rows and columns of options) radio button list control element (latch selection, exclusively one color at a time).
---@param args radio_2d_args ---@param args radio_2d_args
---@return Radio2D element, element_id id ---@return Radio2D element, element_id id
return function (args) return function (args)

View File

@ -13,7 +13,7 @@ local element = require("graphics.element")
---@field x? integer 1 if omitted ---@field x? integer 1 if omitted
---@field y? integer auto incremented if omitted ---@field y? integer auto incremented if omitted
-- Create a new core map box element. -- Create a new core map diagram indicator element.
---@nodiscard ---@nodiscard
---@param args core_map_args ---@param args core_map_args
---@return CoreMap element, element_id id ---@return CoreMap element, element_id id

View File

@ -63,7 +63,7 @@ local system = {}
---@param tool_ctl _plc_cfg_tool_ctl ---@param tool_ctl _plc_cfg_tool_ctl
---@param main_pane graphics_element ---@param main_pane graphics_element
---@param cfg_sys [ plc_config, plc_config, plc_config, table, function ] ---@param cfg_sys [ plc_config, plc_config, plc_config, table, function ]
---@param divs graphics_element[] ---@param divs Div[]
---@param style { [string]: cpair } ---@param style { [string]: cpair }
---@param exit function ---@param exit function
function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit)

View File

@ -18,7 +18,7 @@ local logger = {
mode = MODE.APPEND, mode = MODE.APPEND,
debug = false, debug = false,
file = nil, ---@type table|nil file = nil, ---@type table|nil
dmesg_out = nil, ---@type table|nil dmesg_out = nil, ---@type Redirect|nil
dmesg_restore_coord = { 1, 1 }, dmesg_restore_coord = { 1, 1 },
dmesg_scroll_count = 0 dmesg_scroll_count = 0
} }
@ -80,7 +80,7 @@ end
---@param path string file path ---@param path string file path
---@param write_mode MODE file write mode ---@param write_mode MODE file write mode
---@param include_debug boolean whether or not to include debug logs ---@param include_debug boolean whether or not to include debug logs
---@param dmesg_redirect? table terminal/window to direct dmesg to ---@param dmesg_redirect? Redirect terminal/window to direct dmesg to
function log.init(path, write_mode, include_debug, dmesg_redirect) function log.init(path, write_mode, include_debug, dmesg_redirect)
logger.path = path logger.path = path
logger.mode = write_mode logger.mode = write_mode
@ -107,7 +107,7 @@ function log.close()
end end
-- direct dmesg output to a monitor/window -- direct dmesg output to a monitor/window
---@param window table window or terminal reference ---@param window Window window or terminal reference
function log.direct_dmesg(window) logger.dmesg_out = window end function log.direct_dmesg(window) logger.dmesg_out = window end
-- dmesg style logging for boot because I like linux-y things -- dmesg style logging for boot because I like linux-y things

View File

@ -105,11 +105,11 @@ function facility.new(config)
sps_low_power = false, sps_low_power = false,
disabled_sps = false, disabled_sps = false,
-- alarm tones -- alarm tones
tone_states = {}, ---@type boolean[] tone_states = {}, ---@type { [TONE]: boolean }
test_tone_set = false, test_tone_set = false,
test_tone_reset = false, test_tone_reset = false,
test_tone_states = {}, ---@type boolean[] test_tone_states = {}, ---@type { [TONE]: boolean }
test_alarm_states = {}, ---@type boolean[] test_alarm_states = {}, ---@type { [ALARM]: boolean }
-- statistics -- statistics
im_stat_init = false, im_stat_init = false,
avg_charge = util.mov_avg(3), -- 3 seconds avg_charge = util.mov_avg(3), -- 3 seconds

View File

@ -56,8 +56,8 @@ local self = {
next_ids = { rtu = 0, plc = 0, crd = 0, pdg = 0 }, next_ids = { rtu = 0, plc = 0, crd = 0, pdg = 0 },
-- rtu device tracking and invalid assignment detection -- rtu device tracking and invalid assignment detection
dev_dbg = { dev_dbg = {
duplicate = {}, ---@type unit_session duplicate = {}, ---@type unit_session[]
out_of_range = {}, ---@type unit_session out_of_range = {}, ---@type unit_session[]
connected = {} ---@type { induction: boolean, sps: boolean, tanks: boolean[], units: unit_connections[] } connected = {} ---@type { induction: boolean, sps: boolean, tanks: boolean[], units: unit_connections[] }
} }
} }