Skip to content

Commit

Permalink
#539 fixed child ID map not being correct under specific circumstances
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaylaFischler committed Dec 13, 2024
1 parent 33803a1 commit 9b44370
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion graphics/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions graphics/element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-- Generic Graphics Element
--

-- local log = require("scada-common.log")
local util = require("scada-common.util")

local core = require("graphics.core")
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions graphics/elements/ListBox.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 9b44370

Please sign in to comment.