"order" parameter for LuaGuiElement#add
Posted: Wed Jul 14, 2021 11:12 am
Having just implemented this myself in Lua, I figured I'd ask if this could be made part of the engine-side code:
It would be nice if instead I could just provide an "order" parameter to GUI elements I create, such that when a new GUI element is created with an order, it slots itself in the correct place, rather than me having to iterate through the elements on the Lua side.
Code: Select all
local function findIndexForNewElement(parent, order)
local index = 1
for i=1,#parent.children do
if (parent.children[i].tags['order'] or "") < order then
index = index + 1
else
break
end
end
return index
end
local order = "a"
parent.add{
-- ...
tags = {order = order},
index = findIndexForNewElement(parent, order)
}