#539 fixed child ID map not being correct under specific circumstances

This commit is contained in:
Mikayla Fischler 2024-12-13 17:16:25 -05:00
parent 33803a1ace
commit 9b443709f4
3 changed files with 6 additions and 12 deletions

View File

@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")
local core = {}
core.version = "2.4.6"
core.version = "2.4.7"
core.flasher = flasher
core.events = events

View File

@ -2,7 +2,6 @@
-- Generic Graphics Element
--
-- local log = require("scada-common.log")
local util = require("scada-common.util")
local core = require("graphics.core")
@ -476,10 +475,7 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
if args.parent ~= nil then
-- remove self from parent
-- log.debug("removing " .. self.id .. " from parent")
args.parent.__remove_child(self.id)
else
-- log.debug("no parent for " .. self.id .. " on delete attempt")
end
end
@ -502,9 +498,12 @@ function element.new(args, constraint, child_offset_x, child_offset_y)
self.next_id = self.next_id + 1
end
table.insert(protected.children, child)
-- see #539 on GitHub
-- using #protected.children after inserting may give the wrong index, since if it inserts in a hole that completes the list then
-- the length will jump up to the full length of the list, possibly making two map entries point to the same child
protected.child_id_map[id] = #protected.children + 1
protected.child_id_map[id] = #protected.children
table.insert(protected.children, child)
return id
end

View File

@ -1,6 +1,5 @@
-- Scroll-able List Box Display Graphics Element
-- local log = require("scada-common.log")
local tcd = require("scada-common.tcd")
local core = require("graphics.core")
@ -153,7 +152,6 @@ return function (args)
next_y = next_y + item.h + item_pad
item.e.reposition(1, item.y)
item.e.show()
-- log.debug("iterated " .. item.e.get_id())
end
content_height = next_y
@ -212,7 +210,6 @@ return function (args)
---@param child graphics_element child element
function e.on_added(id, child)
table.insert(list, { id = id, e = child, y = 0, h = child.get_height() })
-- log.debug("added child " .. id .. " into slot " .. #list)
update_positions()
end
@ -222,12 +219,10 @@ return function (args)
for idx, elem in ipairs(list) do
if elem.id == id then
table.remove(list, idx)
-- log.debug("removed child " .. id .. " from slot " .. idx)
update_positions()
return
end
end
-- log.debug("failed to remove child " .. id)
end
-- handle focus