#307 fixes and cleanup

This commit is contained in:
Mikayla Fischler
2023-10-03 22:52:13 -04:00
parent b5e0183e54
commit ebabd99f2b
18 changed files with 65 additions and 100 deletions

View File

@ -115,8 +115,7 @@ end
-- extract the custom element assert message, dropping the path to the element file
function core.extract_assert_msg(msg)
local start = (string.find(msg, "@") + 1) or 1
return string.sub(msg, start)
return string.sub(msg, (string.find(msg, "@") + 1) or 1)
end
-- Interactive Field Manager
@ -163,11 +162,8 @@ function core.new_ifield(e, max_len, fg_bg, dis_fg_bg)
function public.censor(censor)
if type(censor) == "string" and string.len(censor) == 1 then
self.censor = censor
public.show()
else
self.censor = nil
public.show()
end
else self.censor = nil end
public.show()
end
-- show the field

View File

@ -315,8 +315,8 @@ function element.new(args, child_offset_x, child_offset_y)
-- defocus this element
function protected.defocus() public.unfocus_all() end
-- request focus management to focus this element
function protected.req_focus() args.parent.__focus_child(public) end
-- focus this element and take away focus from all other elements
function protected.take_focus() args.parent.__focus_child(public) end
-- action handlers --
@ -426,7 +426,7 @@ function element.new(args, child_offset_x, child_offset_y)
self.id = args.id or "__ROOT__"
protected.prepare_template(0, 0, 1)
else
self.id, self.ordinal = args.parent.__add_child(args.id, protected)
self.id = args.parent.__add_child(args.id, protected)
end
----------------------

View File

@ -118,11 +118,8 @@ local function app_button(args)
-- element redraw
function e.redraw()
-- write app title, centered
e.w_set_cur(math.floor((e.frame.w - string.len(args.title)) / 2) + 1, 4)
e.w_write(args.title)
-- draw button
draw()
end

View File

@ -188,11 +188,9 @@ local function radio_2d_button(args)
end
end
-- handle focus
-- handle focus & enable
e.on_focused = e.redraw
e.on_unfocused = e.redraw
-- handle enable
e.on_enabled = e.redraw
e.on_disabled = e.redraw

View File

@ -132,11 +132,9 @@ local function radio_button(args)
end
end
-- handle focus
-- handle focus & enable
e.on_focused = e.redraw
e.on_unfocused = e.redraw
-- handle enable
e.on_enabled = e.redraw
e.on_disabled = e.redraw

View File

@ -48,7 +48,7 @@ local function number_field(args)
-- only handle if on an increment or decrement arrow
if e.enabled then
if core.events.was_clicked(event.type) then
e.req_focus()
e.take_focus()
if event.type == MOUSE_CLICK.UP then
ifield.move_cursor(event.current.x)

View File

@ -43,7 +43,7 @@ local function text_field(args)
-- only handle if on an increment or decrement arrow
if e.enabled then
if core.events.was_clicked(event.type) then
e.req_focus()
e.take_focus()
if event.type == MOUSE_CLICK.UP then
ifield.move_cursor(event.current.x)

View File

@ -23,7 +23,7 @@ local element = require("graphics.element")
---@param args power_indicator_args
---@return graphics_element element, element_id id
local function power(args)
element.assert(type(args.value) == "number", "value is a required number field")
element.assert(type(args.value) == "number", "value is a required field")
element.assert(util.is_int(args.width), "width is a required field")
args.height = 1

View File

@ -33,7 +33,7 @@ local function rad(args)
-- create new graphics element base object
local e = element.new(args)
e.value = types.new_zero_radiation_reading()
e.value = args.value or types.new_zero_radiation_reading()
local label_len = string.len(args.label)
local data_start = 1

View File

@ -278,12 +278,6 @@ local function listbox(args)
function e.redraw()
draw_arrows(0)
draw_bar()
-- redraw all children
for i = 1, #list do
local item = list[i] ---@type listbox_item
item.e.redraw()
end
end
-- initial draw