checkbox default val and radio type checks for set_value

This commit is contained in:
Mikayla Fischler 2023-10-01 17:06:24 -04:00
parent 02e9c09daf
commit b1446637ad
3 changed files with 4 additions and 3 deletions

View File

@ -6,6 +6,7 @@ local element = require("graphics.element")
---@class checkbox_args ---@class checkbox_args
---@field label string checkbox text ---@field label string checkbox text
---@field box_fg_bg cpair colors for checkbox ---@field box_fg_bg cpair colors for checkbox
---@field default? boolean default value
---@field callback? function function to call on press ---@field callback? function function to call on press
---@field parent graphics_element ---@field parent graphics_element
---@field id? string element id ---@field id? string element id
@ -28,7 +29,7 @@ local function checkbox(args)
-- create new graphics element base object -- create new graphics element base object
local e = element.new(args) local e = element.new(args)
e.value = false e.value = args.default == true
-- show the button state -- show the button state
local function draw() local function draw()

View File

@ -182,7 +182,7 @@ local function radio_2d_button(args)
-- set the value -- set the value
---@param val integer new value ---@param val integer new value
function e.set_value(val) function e.set_value(val)
if val > 0 and val <= #args.options then if type(val) == "number" and val > 0 and val <= #args.options then
e.value = val e.value = val
e.redraw() e.redraw()
end end

View File

@ -126,7 +126,7 @@ local function radio_button(args)
-- set the value -- set the value
---@param val integer new value ---@param val integer new value
function e.set_value(val) function e.set_value(val)
if val > 0 and val <= #args.options then if type(val) == "number" and val > 0 and val <= #args.options then
e.value = val e.value = val
e.redraw() e.redraw()
end end