2021-08-21 12:45:49 +02:00
|
|
|
local ElementList = Object:extend()
|
|
|
|
|
|
|
|
function ElementList:initElements()
|
|
|
|
self.elements = {}
|
2021-08-24 19:41:25 +02:00
|
|
|
self.focusedElement = nil
|
2021-08-31 10:01:24 +02:00
|
|
|
self.lastFocused = nil
|
2021-08-22 12:39:44 +02:00
|
|
|
self.nbrElement = 0
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:addElement(name, element)
|
2021-08-22 12:39:44 +02:00
|
|
|
self.nbrElement = self.nbrElement + 1
|
2021-08-21 12:45:49 +02:00
|
|
|
self.elements[name] = element
|
2021-08-22 12:39:44 +02:00
|
|
|
return self.nbrElement
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:deleteElement(name)
|
|
|
|
self.elements[name] = nil
|
|
|
|
end
|
|
|
|
|
2021-12-31 15:39:50 +01:00
|
|
|
function ElementList:setFocus(name, widgetId, page)
|
2021-08-27 00:44:01 +02:00
|
|
|
assert(self:elementExists(name), "Element " .. name .. " doesn't exists")
|
2021-08-31 10:01:24 +02:00
|
|
|
self:storeLastFocus()
|
2021-08-27 00:44:01 +02:00
|
|
|
self.focusedElement = name
|
|
|
|
self.elements[name].isVisible = true
|
2021-12-31 15:39:50 +01:00
|
|
|
if (widgetId ~= nil) then
|
|
|
|
self.elements[name]:setSubFocus(widgetId, page)
|
|
|
|
end
|
2021-08-27 00:44:01 +02:00
|
|
|
end
|
|
|
|
|
2021-08-31 10:01:24 +02:00
|
|
|
function ElementList:removeFocus()
|
|
|
|
self:storeLastFocus()
|
|
|
|
self.focusedElement = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:storeLastFocus()
|
|
|
|
if (self.focusedElement ~= nil) then
|
|
|
|
self.lastFocused = self.focusedElement
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:setLastFocus()
|
|
|
|
if (self:elementExists(self.lastFocused)) then
|
|
|
|
self:setFocus(self.lastFocused)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-24 19:41:25 +02:00
|
|
|
function ElementList:elementExists(name)
|
|
|
|
return (self:getElement(name) ~= nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:haveFocus()
|
2021-08-31 18:30:28 +02:00
|
|
|
return self:elementIsVisible(self.focusedElement)
|
2021-08-24 19:41:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:getFocusedElement()
|
|
|
|
return self:getElement(self.focusedElement)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:getElement(name)
|
|
|
|
if (not utils.string.isEmpty(name)) then
|
|
|
|
return self.elements[name]
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2021-08-21 12:45:49 +02:00
|
|
|
function ElementList:getVisibleElement(topLayer)
|
|
|
|
local visibleList = {}
|
2021-08-22 13:02:52 +02:00
|
|
|
for _, element in pairs(self.elements) do
|
2021-08-21 12:45:49 +02:00
|
|
|
if (element ~= nil) then
|
|
|
|
if (element:getVisibility() and ((element.depth) < 0 == topLayer)) then
|
|
|
|
table.insert(visibleList, element)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-08-22 12:39:44 +02:00
|
|
|
|
|
|
|
table.sort(visibleList, function (a, b)
|
|
|
|
if (a.depth == b.depth) then
|
|
|
|
return (a.creationId < b.creationId)
|
|
|
|
else
|
|
|
|
return (a.depth > b.depth)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-08-21 12:45:49 +02:00
|
|
|
return visibleList
|
|
|
|
end
|
|
|
|
|
2021-08-31 18:30:28 +02:00
|
|
|
function ElementList:elementIsVisible(name)
|
|
|
|
if (self:elementExists(name)) then
|
|
|
|
return self.elements[name]:getVisibility()
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-08-21 12:45:49 +02:00
|
|
|
return ElementList
|