mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#344 graphics assertion overhaul
This commit is contained in:
parent
ed4180a072
commit
625feb3fd1
@ -111,6 +111,14 @@ function core.pipe(x1, y1, x2, y2, color, thin, align_tr)
|
||||
}
|
||||
end
|
||||
|
||||
-- Assertion Handling
|
||||
|
||||
-- extract the custom element assert message, dropping the path to the element file
|
||||
function core.extract_assert_msg(msg)
|
||||
local start = string.find(msg, "@") or 1
|
||||
return string.sub(msg, start)
|
||||
end
|
||||
|
||||
-- Interactive Field Manager
|
||||
|
||||
---@param e graphics_base
|
||||
|
@ -2,6 +2,8 @@
|
||||
-- Generic Graphics Element
|
||||
--
|
||||
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local core = require("graphics.core")
|
||||
|
||||
local events = core.events
|
||||
@ -65,6 +67,16 @@ local element = {}
|
||||
---@field key string data key
|
||||
---@field func function callback
|
||||
|
||||
-- more detailed assert message for element verification
|
||||
---@param condition any assert condition
|
||||
---@param msg string assert message
|
||||
---@param callstack_offset? integer shift value to change targets of debug.getinfo()
|
||||
function element.assert(condition, msg, callstack_offset)
|
||||
callstack_offset = callstack_offset or 0
|
||||
local caller = debug.getinfo(3 + callstack_offset)
|
||||
assert(condition, util.c(caller.source, ":", caller.currentline, "{", debug.getinfo(2 + callstack_offset).name, "}: ", msg))
|
||||
end
|
||||
|
||||
-- a base graphics element, should not be created on its own
|
||||
---@nodiscard
|
||||
---@param args graphics_args arguments
|
||||
@ -77,7 +89,7 @@ function element.new(args, child_offset_x, child_offset_y)
|
||||
elem_type = debug.getinfo(2).name,
|
||||
define_completed = false,
|
||||
p_window = nil, ---@type table
|
||||
position = { x = 1, y = 1 }, ---@type coordinate_2d
|
||||
position = events.new_coord_2d(1, 1),
|
||||
bounds = { x1 = 1, y1 = 1, x2 = 1, y2 = 1 }, ---@class element_bounds
|
||||
next_y = 1, -- next child y coordinate
|
||||
next_id = 0, -- next child ID
|
||||
@ -99,11 +111,9 @@ function element.new(args, child_offset_x, child_offset_y)
|
||||
child_id_map = {}
|
||||
}
|
||||
|
||||
local name_brief = "graphics.element{" .. self.elem_type .. "}: "
|
||||
|
||||
-- element as string
|
||||
function self.mt.__tostring()
|
||||
return "graphics.element{" .. self.elem_type .. "} @ " .. tostring(self)
|
||||
return util.c("graphics.element{", self.elem_type, "} @ ", self)
|
||||
end
|
||||
|
||||
---@class graphics_element
|
||||
@ -207,10 +217,10 @@ function element.new(args, child_offset_x, child_offset_y)
|
||||
end
|
||||
|
||||
-- check frame
|
||||
assert(f.x >= 1, name_brief .. "frame x not >= 1")
|
||||
assert(f.y >= 1, name_brief .. "frame y not >= 1")
|
||||
assert(f.w >= 1, name_brief .. "frame width not >= 1")
|
||||
assert(f.h >= 1, name_brief .. "frame height not >= 1")
|
||||
element.assert(f.x >= 1, "frame x not >= 1", 2)
|
||||
element.assert(f.y >= 1, "frame y not >= 1", 2)
|
||||
element.assert(f.w >= 1, "frame width not >= 1", 2)
|
||||
element.assert(f.h >= 1, "frame height not >= 1", 2)
|
||||
|
||||
-- create window
|
||||
protected.window = window.create(self.p_window, f.x, f.y, f.w, f.h, args.hidden ~= true)
|
||||
@ -409,7 +419,7 @@ function element.new(args, child_offset_x, child_offset_y)
|
||||
end
|
||||
|
||||
-- check window
|
||||
assert(self.p_window, name_brief .. "no parent window provided")
|
||||
element.assert(self.p_window, "no parent window provided", 1)
|
||||
|
||||
-- prepare the template
|
||||
if args.parent == nil then
|
||||
|
@ -24,10 +24,10 @@ local MOUSE_CLICK = core.events.MOUSE_CLICK
|
||||
---@param args app_button_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function app_button(args)
|
||||
assert(type(args.text) == "string", "controls.app: text is a required field")
|
||||
assert(type(args.title) == "string", "controls.app: title is a required field")
|
||||
assert(type(args.callback) == "function", "controls.app: callback is a required field")
|
||||
assert(type(args.app_fg_bg) == "table", "controls.app: app_fg_bg is a required field")
|
||||
element.assert(type(args.text) == "string", "text is a required field")
|
||||
element.assert(type(args.title) == "string", "title is a required field")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
element.assert(type(args.app_fg_bg) == "table", "app_fg_bg is a required field")
|
||||
|
||||
args.height = 4
|
||||
args.width = 5
|
||||
|
@ -18,8 +18,8 @@ local element = require("graphics.element")
|
||||
---@param args checkbox_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function checkbox(args)
|
||||
assert(type(args.label) == "string", "controls.checkbox: label is a required field")
|
||||
assert(type(args.box_fg_bg) == "table", "controls.checkbox: box_fg_bg is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.box_fg_bg) == "table", "box_fg_bg is a required field")
|
||||
|
||||
args.can_focus = true
|
||||
args.height = 1
|
||||
|
@ -21,9 +21,9 @@ local element = require("graphics.element")
|
||||
---@param args hazard_button_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function hazard_button(args)
|
||||
assert(type(args.text) == "string", "controls.hazard_button: text is a required field")
|
||||
assert(type(args.accent) == "number", "controls.hazard_button: accent is a required field")
|
||||
assert(type(args.callback) == "function", "controls.hazard_button: callback is a required field")
|
||||
element.assert(type(args.text) == "string", "text is a required field")
|
||||
element.assert(type(args.accent) == "number", "accent is a required field")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
|
||||
args.height = 3
|
||||
args.width = string.len(args.text) + 4
|
||||
|
@ -29,11 +29,11 @@ local element = require("graphics.element")
|
||||
---@param args multi_button_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function multi_button(args)
|
||||
assert(type(args.options) == "table", "controls.multi_button: options is a required field")
|
||||
assert(#args.options > 0, "controls.multi_button: at least one option is required")
|
||||
assert(type(args.callback) == "function", "controls.multi_button: callback is a required field")
|
||||
assert(type(args.default) == "nil" or (type(args.default) == "number" and args.default > 0), "controls.multi_button: default must be nil or a number > 0")
|
||||
assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "controls.multi_button: min_width must be nil or a number > 0")
|
||||
element.assert(type(args.options) == "table", "options is a required field")
|
||||
element.assert(#args.options > 0, "at least one option is required")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
element.assert(type(args.default) == "nil" or (type(args.default) == "number" and args.default > 0), "default must be nil or a number > 0")
|
||||
element.assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "min_width must be nil or a number > 0")
|
||||
|
||||
-- single line
|
||||
args.height = 1
|
||||
|
@ -26,9 +26,9 @@ local KEY_CLICK = core.events.KEY_CLICK
|
||||
---@param args push_button_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function push_button(args)
|
||||
assert(type(args.text) == "string", "controls.push_button: text is a required field")
|
||||
assert(type(args.callback) == "function", "controls.push_button: callback is a required field")
|
||||
assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "controls.push_button: min_width must be nil or a number > 0")
|
||||
element.assert(type(args.text) == "string", "text is a required field")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
element.assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "min_width must be nil or a number > 0")
|
||||
|
||||
local text_width = string.len(args.text)
|
||||
|
||||
|
@ -27,12 +27,12 @@ local element = require("graphics.element")
|
||||
---@param args radio_2d_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function radio_2d_button(args)
|
||||
assert(type(args.options) == "table" and #args.options > 0, "controls.radio_2d: options should be a table with length >= 1")
|
||||
assert(util.is_int(args.rows) and util.is_int(args.columns), "controls.radio_2d: rows/columns must be integers")
|
||||
assert((args.rows * args.columns) >= #args.options, "controls.radio_2d: rows x columns size insufficient for provided number of options")
|
||||
assert(type(args.radio_colors) == "table", "controls.radio_2d: radio_colors is a required field")
|
||||
assert(type(args.select_color) == "number" or type(args.color_map) == "table", "controls.radio_2d: select_color or color_map is required")
|
||||
assert(type(args.default) == "nil" or (type(args.default) == "number" and args.default > 0), "controls.radio_2d: default must be nil or a number > 0")
|
||||
element.assert(type(args.options) == "table" and #args.options > 0, "options should be a table with length >= 1")
|
||||
element.assert(util.is_int(args.rows) and util.is_int(args.columns), "rows/columns must be integers")
|
||||
element.assert((args.rows * args.columns) >= #args.options, "rows x columns size insufficient for provided number of options")
|
||||
element.assert(type(args.radio_colors) == "table", "radio_colors is a required field")
|
||||
element.assert(type(args.select_color) == "number" or type(args.color_map) == "table", "select_color or color_map is required")
|
||||
element.assert(type(args.default) == "nil" or (type(args.default) == "number" and args.default > 0), "default must be nil or a number > 0")
|
||||
|
||||
local array = {}
|
||||
local col_widths = {}
|
||||
|
@ -25,14 +25,12 @@ local KEY_CLICK = core.events.KEY_CLICK
|
||||
---@param args radio_button_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function radio_button(args)
|
||||
assert(type(args.options) == "table", "controls.radio_button: options is a required field")
|
||||
assert(#args.options > 0, "controls.radio_button: at least one option is required")
|
||||
assert(type(args.radio_colors) == "table", "controls.radio_button: radio_colors is a required field")
|
||||
assert(type(args.select_color) == "number", "controls.radio_button: select_color is a required field")
|
||||
assert(type(args.default) == "nil" or (type(args.default) == "number" and args.default > 0),
|
||||
"controls.radio_button: default must be nil or a number > 0")
|
||||
assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0),
|
||||
"controls.radio_button: min_width must be nil or a number > 0")
|
||||
element.assert(type(args.options) == "table", "options is a required field")
|
||||
element.assert(#args.options > 0, "at least one option is required")
|
||||
element.assert(type(args.radio_colors) == "table", "radio_colors is a required field")
|
||||
element.assert(type(args.select_color) == "number", "select_color is a required field")
|
||||
element.assert(type(args.default) == "nil" or (type(args.default) == "number" and args.default > 0), "default must be nil or a number > 0")
|
||||
element.assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "min_width must be nil or a number > 0")
|
||||
|
||||
-- determine widths
|
||||
local max_width = 1
|
||||
|
@ -27,16 +27,16 @@ local MOUSE_CLICK = core.events.MOUSE_CLICK
|
||||
---@param args sidebar_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function sidebar(args)
|
||||
assert(type(args.tabs) == "table", "controls.sidebar: tabs is a required field")
|
||||
assert(#args.tabs > 0, "controls.sidebar: at least one tab is required")
|
||||
assert(type(args.callback) == "function", "controls.sidebar: callback is a required field")
|
||||
element.assert(type(args.tabs) == "table", "tabs is a required field")
|
||||
element.assert(#args.tabs > 0, "at least one tab is required")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
|
||||
args.width = 3
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
||||
assert(e.frame.h >= (#args.tabs * 3), "graphics.elements.controls.sidebar: height insufficent to display all tabs")
|
||||
element.assert(e.frame.h >= (#args.tabs * 3), "height insufficent to display all tabs")
|
||||
|
||||
-- default to 1st tab
|
||||
e.value = 1
|
||||
|
@ -29,8 +29,8 @@ local function spinbox(args)
|
||||
local wn_prec = args.whole_num_precision
|
||||
local fr_prec = args.fractional_precision
|
||||
|
||||
assert(util.is_int(wn_prec), "controls.spinbox_numeric: whole number precision must be an integer")
|
||||
assert(util.is_int(fr_prec), "controls.spinbox_numeric: fractional precision must be an integer")
|
||||
element.assert(util.is_int(wn_prec), "whole number precision must be an integer")
|
||||
element.assert(util.is_int(fr_prec), "fractional precision must be an integer")
|
||||
|
||||
local fmt, fmt_init ---@type string, string
|
||||
|
||||
@ -44,7 +44,7 @@ local function spinbox(args)
|
||||
|
||||
local dec_point_x = args.whole_num_precision + 1
|
||||
|
||||
assert(type(args.arrow_fg_bg) == "table", "controls.spinbox_numeric: arrow_fg_bg is a required field")
|
||||
element.assert(type(args.arrow_fg_bg) == "table", "arrow_fg_bg is a required field")
|
||||
|
||||
-- determine widths
|
||||
args.width = wn_prec + fr_prec + util.trinary(fr_prec > 0, 1, 0)
|
||||
|
@ -21,10 +21,10 @@ local element = require("graphics.element")
|
||||
---@param args switch_button_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function switch_button(args)
|
||||
assert(type(args.text) == "string", "controls.switch_button: text is a required field")
|
||||
assert(type(args.callback) == "function", "controls.switch_button: callback is a required field")
|
||||
assert(type(args.active_fg_bg) == "table", "controls.switch_button: active_fg_bg is a required field")
|
||||
assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "controls.switch_button: min_width must be nil or a number > 0")
|
||||
element.assert(type(args.text) == "string", "text is a required field")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
element.assert(type(args.active_fg_bg) == "table", "active_fg_bg is a required field")
|
||||
element.assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "min_width must be nil or a number > 0")
|
||||
|
||||
local text_width = string.len(args.text)
|
||||
|
||||
|
@ -27,10 +27,10 @@ local element = require("graphics.element")
|
||||
---@param args tabbar_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function tabbar(args)
|
||||
assert(type(args.tabs) == "table", "controls.tabbar: tabs is a required field")
|
||||
assert(#args.tabs > 0, "controls.tabbar: at least one tab is required")
|
||||
assert(type(args.callback) == "function", "controls.tabbar: callback is a required field")
|
||||
assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "controls.tabbar: min_width must be nil or a number > 0")
|
||||
element.assert(type(args.tabs) == "table", "tabs is a required field")
|
||||
element.assert(#args.tabs > 0, "at least one tab is required")
|
||||
element.assert(type(args.callback) == "function", "callback is a required field")
|
||||
element.assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0), "min_width must be nil or a number > 0")
|
||||
|
||||
args.height = 1
|
||||
|
||||
@ -48,7 +48,7 @@ local function tabbar(args)
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
||||
assert(e.frame.w >= (button_width * #args.tabs), "graphics.elements.controls.tabbar: width insufficent to display all tabs")
|
||||
element.assert(e.frame.w >= (button_width * #args.tabs), "width insufficent to display all tabs")
|
||||
|
||||
-- default to 1st tab
|
||||
e.value = 1
|
||||
|
@ -25,13 +25,13 @@ local flasher = require("graphics.flasher")
|
||||
---@param args alarm_indicator_light
|
||||
---@return graphics_element element, element_id id
|
||||
local function alarm_indicator_light(args)
|
||||
assert(type(args.label) == "string", "indicators.alight: label is a required field")
|
||||
assert(type(args.c1) == "number", "indicators.alight: c1 is a required field")
|
||||
assert(type(args.c2) == "number", "indicators.alight: c2 is a required field")
|
||||
assert(type(args.c3) == "number", "indicators.alight: c3 is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.c1) == "number", "c1 is a required field")
|
||||
element.assert(type(args.c2) == "number", "c2 is a required field")
|
||||
element.assert(type(args.c3) == "number", "c3 is a required field")
|
||||
|
||||
if args.flash then
|
||||
assert(util.is_int(args.period), "indicators.alight: period is a required field if flash is enabled")
|
||||
element.assert(util.is_int(args.period), "period is a required field if flash is enabled")
|
||||
end
|
||||
|
||||
-- single line
|
||||
|
@ -18,8 +18,8 @@ local element = require("graphics.element")
|
||||
---@param args core_map_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function core_map(args)
|
||||
assert(util.is_int(args.reactor_l), "indicators.coremap: reactor_l is a required field")
|
||||
assert(util.is_int(args.reactor_w), "indicators.coremap: reactor_w is a required field")
|
||||
element.assert(util.is_int(args.reactor_l), "reactor_l is a required field")
|
||||
element.assert(util.is_int(args.reactor_w), "reactor_w is a required field")
|
||||
|
||||
-- require max dimensions
|
||||
args.width = 18
|
||||
|
@ -24,10 +24,10 @@ local element = require("graphics.element")
|
||||
---@param args data_indicator_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function data(args)
|
||||
assert(type(args.label) == "string", "indicators.data: label is a required field")
|
||||
assert(type(args.format) == "string", "indicators.data: format is a required field")
|
||||
assert(args.value ~= nil, "indicators.data: value is a required field")
|
||||
assert(util.is_int(args.width), "indicators.data: width is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.format) == "string", "format is a required field")
|
||||
element.assert(args.value ~= nil, "value is a required field")
|
||||
element.assert(util.is_int(args.width), "width is a required field")
|
||||
|
||||
args.height = 1
|
||||
|
||||
|
@ -22,9 +22,6 @@ local element = require("graphics.element")
|
||||
---@param args hbar_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function hbar(args)
|
||||
-- properties/state
|
||||
local last_num_bars = -1
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
||||
@ -33,7 +30,9 @@ local function hbar(args)
|
||||
-- bar width is width - 5 characters for " 100%" if showing percent
|
||||
local bar_width = util.trinary(args.show_percent, e.frame.w - 5, e.frame.w)
|
||||
|
||||
assert(bar_width > 0, "indicators.hbar: too small for bar")
|
||||
element.assert(bar_width > 0, "too small for bar")
|
||||
|
||||
local last_num_bars = -1
|
||||
|
||||
-- determine bar colors
|
||||
local bar_bkg = e.fg_bg.blit_bkg
|
||||
|
@ -23,8 +23,8 @@ local element = require("graphics.element")
|
||||
---@param args icon_indicator_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function icon(args)
|
||||
assert(type(args.label) == "string", "indicators.icon: label is a required field")
|
||||
assert(type(args.states) == "table", "indicators.icon: states is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.states) == "table", "states is a required field")
|
||||
|
||||
args.height = 1
|
||||
args.width = math.max(args.min_label_width or 1, string.len(args.label)) + 4
|
||||
|
@ -23,11 +23,11 @@ local flasher = require("graphics.flasher")
|
||||
---@param args indicator_led_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function indicator_led(args)
|
||||
assert(type(args.label) == "string", "indicators.led: label is a required field")
|
||||
assert(type(args.colors) == "table", "indicators.led: colors is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.colors) == "table", "colors is a required field")
|
||||
|
||||
if args.flash then
|
||||
assert(util.is_int(args.period), "indicators.led: period is a required field if flash is enabled")
|
||||
element.assert(util.is_int(args.period), "period is a required field if flash is enabled")
|
||||
end
|
||||
|
||||
args.height = 1
|
||||
|
@ -25,13 +25,13 @@ local flasher = require("graphics.flasher")
|
||||
---@param args indicator_led_pair_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function indicator_led_pair(args)
|
||||
assert(type(args.label) == "string", "indicators.ledpair: label is a required field")
|
||||
assert(type(args.off) == "number", "indicators.ledpair: off is a required field")
|
||||
assert(type(args.c1) == "number", "indicators.ledpair: c1 is a required field")
|
||||
assert(type(args.c2) == "number", "indicators.ledpair: c2 is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.off) == "number", "off is a required field")
|
||||
element.assert(type(args.c1) == "number", "c1 is a required field")
|
||||
element.assert(type(args.c2) == "number", "c2 is a required field")
|
||||
|
||||
if args.flash then
|
||||
assert(util.is_int(args.period), "indicators.ledpair: period is a required field if flash is enabled")
|
||||
element.assert(util.is_int(args.period), "period is a required field if flash is enabled")
|
||||
end
|
||||
|
||||
args.height = 1
|
||||
|
@ -18,8 +18,8 @@ local element = require("graphics.element")
|
||||
---@param args indicator_led_rgb_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function indicator_led_rgb(args)
|
||||
assert(type(args.label) == "string", "indicators.ledrgb: label is a required field")
|
||||
assert(type(args.colors) == "table", "indicators.ledrgb: colors is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.colors) == "table", "colors is a required field")
|
||||
|
||||
args.height = 1
|
||||
args.width = math.max(args.min_label_width or 0, string.len(args.label)) + 2
|
||||
|
@ -23,11 +23,11 @@ local flasher = require("graphics.flasher")
|
||||
---@param args indicator_light_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function indicator_light(args)
|
||||
assert(type(args.label) == "string", "indicators.light: label is a required field")
|
||||
assert(type(args.colors) == "table", "indicators.light: colors is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.colors) == "table", "colors is a required field")
|
||||
|
||||
if args.flash then
|
||||
assert(util.is_int(args.period), "indicators.light: period is a required field if flash is enabled")
|
||||
element.assert(util.is_int(args.period), "period is a required field if flash is enabled")
|
||||
end
|
||||
|
||||
args.height = 1
|
||||
|
@ -23,8 +23,8 @@ local element = require("graphics.element")
|
||||
---@param args power_indicator_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function power(args)
|
||||
assert(type(args.value) == "number", "indicators.power: value is a required number field")
|
||||
assert(util.is_int(args.width), "indicators.power: width is a required field")
|
||||
element.assert(type(args.value) == "number", "value is a required number field")
|
||||
element.assert(util.is_int(args.width), "width is a required field")
|
||||
|
||||
args.height = 1
|
||||
|
||||
|
@ -24,10 +24,10 @@ local element = require("graphics.element")
|
||||
---@param args rad_indicator_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function rad(args)
|
||||
assert(type(args.value) ~= "number", "indicators.rad: value is a required number field")
|
||||
assert(type(args.label) == "string", "indicators.rad: label is a required field")
|
||||
assert(type(args.format) == "string", "indicators.rad: format is a required field")
|
||||
assert(util.is_int(args.width), "indicators.rad: width is a required field")
|
||||
element.assert(type(args.value) ~= "number", "value is a required number field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.format) == "string", "format is a required field")
|
||||
element.assert(util.is_int(args.width), "width is a required field")
|
||||
|
||||
args.height = 1
|
||||
|
||||
|
@ -25,13 +25,11 @@ local element = require("graphics.element")
|
||||
---@param args state_indicator_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function state_indicator(args)
|
||||
assert(type(args.states) == "table", "indicators.state: states is a required field")
|
||||
element.assert(type(args.states) == "table", "states is a required field")
|
||||
|
||||
if util.is_int(args.height) then
|
||||
assert(args.height % 2 == 1, "indicators.state: height should be an odd number")
|
||||
else
|
||||
args.height = 1
|
||||
end
|
||||
element.assert(args.height % 2 == 1, "height should be an odd number")
|
||||
else args.height = 1 end
|
||||
|
||||
args.width = args.min_width or 1
|
||||
|
||||
|
@ -25,13 +25,13 @@ local flasher = require("graphics.flasher")
|
||||
---@param args tristate_indicator_light_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function tristate_indicator_light(args)
|
||||
assert(type(args.label) == "string", "indicators.trilight: label is a required field")
|
||||
assert(type(args.c1) == "number", "indicators.trilight: c1 is a required field")
|
||||
assert(type(args.c2) == "number", "indicators.trilight: c2 is a required field")
|
||||
assert(type(args.c3) == "number", "indicators.trilight: c3 is a required field")
|
||||
element.assert(type(args.label) == "string", "label is a required field")
|
||||
element.assert(type(args.c1) == "number", "c1 is a required field")
|
||||
element.assert(type(args.c2) == "number", "c2 is a required field")
|
||||
element.assert(type(args.c3) == "number", "c3 is a required field")
|
||||
|
||||
if args.flash then
|
||||
assert(util.is_int(args.period), "indicators.trilight: period is a required field if flash is enabled")
|
||||
element.assert(util.is_int(args.period), "period is a required field if flash is enabled")
|
||||
end
|
||||
|
||||
args.height = 1
|
||||
|
@ -19,7 +19,7 @@ local element = require("graphics.element")
|
||||
---@param args multipane_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function multipane(args)
|
||||
assert(type(args.panes) == "table", "multipane: panes is a required field")
|
||||
element.assert(type(args.panes) == "table", "panes is a required field")
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
@ -24,7 +24,7 @@ local element = require("graphics.element")
|
||||
---@param args pipenet_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function pipenet(args)
|
||||
assert(type(args.pipes) == "table", "pipenet: pipes is a required field")
|
||||
element.assert(type(args.pipes) == "table", "pipes is a required field")
|
||||
|
||||
args.width = 0
|
||||
args.height = 0
|
||||
|
@ -22,7 +22,7 @@ local element = require("graphics.element")
|
||||
---@param args rectangle_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function rectangle(args)
|
||||
assert(args.border ~= nil or args.thin ~= true, "rectangle: thin requires border to be provided")
|
||||
element.assert(args.border ~= nil or args.thin ~= true, "thin requires border to be provided")
|
||||
|
||||
-- if thin, then width will always need to be 1
|
||||
if args.thin == true then
|
||||
@ -65,8 +65,8 @@ local function rectangle(args)
|
||||
local inner_width = e.frame.w - width_x2
|
||||
|
||||
-- check dimensions
|
||||
assert(width_x2 <= e.frame.w, "rectangle: border too thick for width")
|
||||
assert(width_x2 <= e.frame.h, "rectangle: border too thick for height")
|
||||
element.assert(width_x2 <= e.frame.w, "border too thick for width")
|
||||
element.assert(width_x2 <= e.frame.h, "border too thick for height")
|
||||
|
||||
-- form the basic line strings and top/bottom blit strings
|
||||
local spaces = util.spaces(e.frame.w)
|
||||
|
@ -24,7 +24,7 @@ local TEXT_ALIGN = core.TEXT_ALIGN
|
||||
---@param args textbox_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function textbox(args)
|
||||
assert(type(args.text) == "string", "textbox: text is a required field")
|
||||
element.assert(type(args.text) == "string", "text is a required field")
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
@ -22,7 +22,7 @@ local element = require("graphics.element")
|
||||
---@param args tiling_args
|
||||
---@return graphics_element element, element_id id
|
||||
local function tiling(args)
|
||||
assert(type(args.fill_c) == "table", "tiling: fill_c is a required field")
|
||||
element.assert(type(args.fill_c) == "table", "fill_c is a required field")
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
@ -47,10 +47,10 @@ local function tiling(args)
|
||||
end
|
||||
|
||||
-- check dimensions
|
||||
assert(inner_width > 0, "tiling: inner_width <= 0")
|
||||
assert(inner_height > 0, "tiling: inner_height <= 0")
|
||||
assert(start_x <= inner_width, "tiling: start_x > inner_width")
|
||||
assert(start_y <= inner_height, "tiling: start_y > inner_height")
|
||||
element.assert(inner_width > 0, "inner_width <= 0")
|
||||
element.assert(inner_height > 0, "inner_height <= 0")
|
||||
element.assert(start_x <= inner_width, "start_x > inner_width")
|
||||
element.assert(start_y <= inner_height, "start_y > inner_height")
|
||||
|
||||
-- draw tiling box
|
||||
function e.redraw()
|
||||
|
Loading…
Reference in New Issue
Block a user