#84 improved element creation process for adding children

This commit is contained in:
Mikayla Fischler
2022-07-28 10:09:34 -04:00
parent 01a364b5cf
commit f1a50990f2
18 changed files with 90 additions and 54 deletions

View File

@@ -10,6 +10,7 @@ local element = require("graphics.element")
---@field min_width? integer text length + 2 if omitted
---@field active_fg_bg? cpair foreground/background colors when pressed
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
---@field y? integer 1 if omitted
---@field height? integer parent height if omitted
@@ -17,6 +18,7 @@ local element = require("graphics.element")
-- new push button
---@param args push_button_args
---@return graphics_element element, element_id id
local function push_button(args)
assert(type(args.text) == "string", "graphics.elements.controls.push_button: text is a required field")
assert(type(args.callback) == "function", "graphics.elements.controls.push_button: callback is a required field")
@@ -61,7 +63,7 @@ local function push_button(args)
args.callback()
end
return e.get()
return e.complete()
end
return push_button

View File

@@ -9,12 +9,14 @@ local element = require("graphics.element")
---@class scram_button_args
---@field callback function function to call on touch
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
---@field y? integer 1 if omitted
---@field fg_bg? cpair foreground/background colors
-- new scram button
---@param args scram_button_args
---@return graphics_element element, element_id id
local function scram_button(args)
assert(type(args.callback) == "function", "graphics.elements.controls.scram_button: callback is a required field")
@@ -63,7 +65,7 @@ local function scram_button(args)
args.callback()
end
return e.get()
return e.complete()
end
return scram_button

View File

@@ -9,12 +9,14 @@ local util = require("scada-common.util")
---@field fractional_precision integer number of fractional digits
---@field arrow_fg_bg cpair arrow foreground/background colors
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
---@field y? integer 1 if omitted
---@field fg_bg? cpair foreground/background colors
-- new spinbox control (minimum value is 0)
---@param args spinbox_args
---@return graphics_element element, element_id id
local function spinbox(args)
-- properties
local value = args.default or 0.0
@@ -110,7 +112,7 @@ local function spinbox(args)
---@return number|integer
function e.get_value() return value end
return e.get()
return e.complete()
end
return spinbox

View File

@@ -9,6 +9,7 @@ local element = require("graphics.element")
---@field min_width? integer text length + 2 if omitted
---@field active_fg_bg cpair foreground/background colors when pressed
---@field parent graphics_element
---@field id? string element id
---@field x? integer 1 if omitted
---@field y? integer 1 if omitted
---@field height? integer parent height if omitted
@@ -16,6 +17,7 @@ local element = require("graphics.element")
-- new switch button (latch high/low)
---@param args switch_button_args
---@return graphics_element element, element_id id
local function switch_button(args)
assert(type(args.text) == "string", "graphics.elements.controls.switch_button: text is a required field")
assert(type(args.callback) == "function", "graphics.elements.controls.switch_button: callback is a required field")
@@ -71,7 +73,7 @@ local function switch_button(args)
args.callback(state)
end
return e.get()
return e.complete()
end
return switch_button