mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-11 08:48:23 +00:00
remove children property
This commit is contained in:
@@ -161,12 +161,11 @@ Widget to search within, defaults to layout root.
|
|||||||
--]]--
|
--]]--
|
||||||
function Layout:getWidgetAt (x, y, root)
|
function Layout:getWidgetAt (x, y, root)
|
||||||
local widget = root or self.root
|
local widget = root or self.root
|
||||||
local children = widget.children
|
local childCount = #widget
|
||||||
local childCount = #children
|
|
||||||
-- Loop through in reverse, because siblings defined later in the tree
|
-- Loop through in reverse, because siblings defined later in the tree
|
||||||
-- will overdraw earlier siblings.
|
-- will overdraw earlier siblings.
|
||||||
for i = childCount, 1, -1 do
|
for i = childCount, 1, -1 do
|
||||||
local child = children[i]
|
local child = widget[i]
|
||||||
local inner = self:getWidgetAt(x, y, child)
|
local inner = self:getWidgetAt(x, y, child)
|
||||||
if inner then return inner end
|
if inner then return inner end
|
||||||
end
|
end
|
||||||
@@ -202,7 +201,7 @@ function Layout:addDefaultHandlers ()
|
|||||||
local widget = self.focusedWidget
|
local widget = self.focusedWidget
|
||||||
if widget and event.key == 'space' or event.key == ' '
|
if widget and event.key == 'space' or event.key == ' '
|
||||||
or event.key == 'return' then
|
or event.key == 'return' then
|
||||||
self.input:handlePressStart(event.key, event.x, event.y,
|
self.input:handlePressStart(self, event.key, event.x, event.y,
|
||||||
widget, event.key)
|
widget, event.key)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -212,7 +211,7 @@ function Layout:addDefaultHandlers ()
|
|||||||
|
|
||||||
if acceleratedWidget then
|
if acceleratedWidget then
|
||||||
acceleratedWidget.hovered = true
|
acceleratedWidget.hovered = true
|
||||||
self.input:handlePressStart(event.key, event.x, event.y,
|
self.input:handlePressStart(self, event.key, event.x, event.y,
|
||||||
acceleratedWidget, event.key)
|
acceleratedWidget, event.key)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -223,7 +222,7 @@ function Layout:addDefaultHandlers ()
|
|||||||
local widget = self.focusedWidget
|
local widget = self.focusedWidget
|
||||||
if widget and event.key == 'space' or event.key == ' '
|
if widget and event.key == 'space' or event.key == ' '
|
||||||
or event.key == 'return' then
|
or event.key == 'return' then
|
||||||
self.input:handlePressEnd(event.key, event.x, event.y,
|
self.input:handlePressEnd(self, event.key, event.x, event.y,
|
||||||
widget, event.key)
|
widget, event.key)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -233,7 +232,7 @@ function Layout:addDefaultHandlers ()
|
|||||||
|
|
||||||
if acceleratedWidget then
|
if acceleratedWidget then
|
||||||
acceleratedWidget.hovered = false
|
acceleratedWidget.hovered = false
|
||||||
self.input:handlePressEnd(event.key, event.x, event.y,
|
self.input:handlePressEnd(self, event.key, event.x, event.y,
|
||||||
acceleratedWidget, event.key)
|
acceleratedWidget, event.key)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ function Renderer:renderIconAndText (widget)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Renderer:renderChildren (widget)
|
function Renderer:renderChildren (widget)
|
||||||
for i, child in ipairs(widget.children) do self:render(child) end
|
for i, child in ipairs(widget) do self:render(child) end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Renderer:render (widget)
|
function Renderer:render (widget)
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ A Widget instance.
|
|||||||
local function metaCall (Widget, layout, self)
|
local function metaCall (Widget, layout, self)
|
||||||
self = self or {}
|
self = self or {}
|
||||||
self.layout = layout
|
self.layout = layout
|
||||||
self.children = self.children or {}
|
|
||||||
self.position = { x = nil, y = nil }
|
self.position = { x = nil, y = nil }
|
||||||
self.dimensions = { width = nil, height = nil }
|
self.dimensions = { width = nil, height = nil }
|
||||||
self.shadowProperties = {}
|
self.shadowProperties = {}
|
||||||
@@ -119,8 +118,8 @@ local function metaCall (Widget, layout, self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for k, v in ipairs(self) do
|
for k, v in ipairs(self) do
|
||||||
self.children[k] = v.isWidget and v or metaCall(Widget, self.layout, v)
|
self[k] = v.isWidget and v or metaCall(Widget, self.layout, v)
|
||||||
self.children[k].parent = self
|
self[k].parent = self
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@@ -179,10 +178,10 @@ Get widget's previous sibling.
|
|||||||
The widget's previous sibling, if any.
|
The widget's previous sibling, if any.
|
||||||
--]]--
|
--]]--
|
||||||
function Widget:getPreviousSibling ()
|
function Widget:getPreviousSibling ()
|
||||||
if not self.parent then return end
|
local parent = self.parent
|
||||||
local siblings = self.parent.children
|
if not parent then return end
|
||||||
for i, widget in ipairs(siblings) do
|
for i, widget in ipairs(parent) do
|
||||||
if widget == self then return siblings[i - 1] end
|
if widget == self then return parent[i - 1] end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -193,10 +192,10 @@ Get widget's next sibling.
|
|||||||
The widget's next sibling, if any.
|
The widget's next sibling, if any.
|
||||||
--]]--
|
--]]--
|
||||||
function Widget:getNextSibling ()
|
function Widget:getNextSibling ()
|
||||||
if not self.parent then return end
|
local parent = self.parent
|
||||||
local siblings = self.parent.children
|
if not parent then return end
|
||||||
for i, widget in ipairs(siblings) do
|
for i, widget in ipairs(parent) do
|
||||||
if widget == self then return siblings[i + 1] end
|
if widget == self then return parent[i + 1] end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -236,8 +235,8 @@ Cycles back around to the layout root from the last widget in the tree.
|
|||||||
The next widget in the tree.
|
The next widget in the tree.
|
||||||
--]]--
|
--]]--
|
||||||
function Widget:getNextNeighbor ()
|
function Widget:getNextNeighbor ()
|
||||||
if #self.children > 0 then
|
if #self > 0 then
|
||||||
return self.children[1]
|
return self[1]
|
||||||
end
|
end
|
||||||
for ancestor in self:eachAncestor(true) do
|
for ancestor in self:eachAncestor(true) do
|
||||||
local nextWidget = ancestor:getNextSibling()
|
local nextWidget = ancestor:getNextSibling()
|
||||||
@@ -248,9 +247,8 @@ end
|
|||||||
|
|
||||||
-- get the last child of the last child of the last child of the...
|
-- get the last child of the last child of the last child of the...
|
||||||
local function getGreatestDescendant (widget)
|
local function getGreatestDescendant (widget)
|
||||||
while #widget.children > 0 do
|
while #widget > 0 do
|
||||||
local children = widget.children
|
widget = widget[#widget]
|
||||||
widget = children[#children]
|
|
||||||
end
|
end
|
||||||
return widget
|
return widget
|
||||||
end
|
end
|
||||||
@@ -295,7 +293,7 @@ function Widget:addChild (data)
|
|||||||
local layout = self.layout
|
local layout = self.layout
|
||||||
local child = Widget(layout, data or {})
|
local child = Widget(layout, data or {})
|
||||||
|
|
||||||
table.insert(self.children, child)
|
table.insert(self, child)
|
||||||
child.parent = self
|
child.parent = self
|
||||||
child.layout = self.layout
|
child.layout = self.layout
|
||||||
|
|
||||||
@@ -351,7 +349,7 @@ function Widget:calculateDimension (name)
|
|||||||
end
|
end
|
||||||
local claimed = 0
|
local claimed = 0
|
||||||
local unsized = 1
|
local unsized = 1
|
||||||
for i, widget in ipairs(self.parent.children) do
|
for i, widget in ipairs(self.parent) do
|
||||||
if widget ~= self then
|
if widget ~= self then
|
||||||
if widget[name] then
|
if widget[name] then
|
||||||
claimed = claimed + widget:calculateDimension(name)
|
claimed = claimed + widget:calculateDimension(name)
|
||||||
@@ -387,7 +385,7 @@ function Widget:calculatePosition (axis)
|
|||||||
p = p + (parent.margin or 0)
|
p = p + (parent.margin or 0)
|
||||||
p = p + (parent.padding or 0)
|
p = p + (parent.padding or 0)
|
||||||
local parentFlow = parent.flow or 'y'
|
local parentFlow = parent.flow or 'y'
|
||||||
for i, widget in ipairs(parent.children) do
|
for i, widget in ipairs(parent) do
|
||||||
if widget == self then
|
if widget == self then
|
||||||
self.position[axis] = p
|
self.position[axis] = p
|
||||||
return p
|
return p
|
||||||
@@ -448,7 +446,7 @@ function Widget:setDimension (name, size)
|
|||||||
end
|
end
|
||||||
local parentDimension = self.parent:calculateDimension(name)
|
local parentDimension = self.parent:calculateDimension(name)
|
||||||
local claimed = 0
|
local claimed = 0
|
||||||
for i, widget in ipairs(self.parent.children) do
|
for i, widget in ipairs(self.parent) do
|
||||||
if widget ~= self and widget[name] then
|
if widget ~= self and widget[name] then
|
||||||
claimed = claimed + widget[name]
|
claimed = claimed + widget[name]
|
||||||
end
|
end
|
||||||
@@ -588,9 +586,11 @@ function Widget:reshape ()
|
|||||||
Event.Reshape:emit(self, {
|
Event.Reshape:emit(self, {
|
||||||
target = self
|
target = self
|
||||||
})
|
})
|
||||||
for i, widget in ipairs(self.children) do
|
for i, widget in ipairs(self) do
|
||||||
|
if widget.reshape then
|
||||||
widget:reshape()
|
widget:reshape()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
self.isReshaping = nil
|
self.isReshaping = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ local Layout
|
|||||||
local show
|
local show
|
||||||
|
|
||||||
local function deactivateSiblings (target)
|
local function deactivateSiblings (target)
|
||||||
local sibling = target.parent and target.parent.children[1]
|
local sibling = target.parent and target.parent[1]
|
||||||
local wasSiblingOpen
|
local wasSiblingOpen
|
||||||
|
|
||||||
if not sibling then
|
if not sibling then
|
||||||
@@ -90,9 +90,9 @@ show = function (self)
|
|||||||
root.height = root:getHeight() + h
|
root.height = root:getHeight() + h
|
||||||
if child.type == 'menu.item' then
|
if child.type == 'menu.item' then
|
||||||
local pad = child.padding or 0
|
local pad = child.padding or 0
|
||||||
local tw = child.fontData:getAdvance(child.children[2].text)
|
local tw = child.fontData:getAdvance(child[2].text)
|
||||||
+ pad * 2 + h
|
+ pad * 2 + h
|
||||||
local kw = child.fontData:getAdvance(child.children[3].text)
|
local kw = child.fontData:getAdvance(child[3].text)
|
||||||
+ pad * 2
|
+ pad * 2
|
||||||
textWidth = math.max(textWidth, tw)
|
textWidth = math.max(textWidth, tw)
|
||||||
keyWidth = math.max(keyWidth, kw)
|
keyWidth = math.max(keyWidth, kw)
|
||||||
@@ -103,13 +103,13 @@ show = function (self)
|
|||||||
|
|
||||||
menuLayout:onReshape(function (event)
|
menuLayout:onReshape(function (event)
|
||||||
menuLayout:hide()
|
menuLayout:hide()
|
||||||
deactivateSiblings(self.rootMenu.children[1])
|
deactivateSiblings(self.rootMenu[1])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
menuLayout:onPressStart(function (event)
|
menuLayout:onPressStart(function (event)
|
||||||
if not event.hit then
|
if not event.hit then
|
||||||
menuLayout:hide()
|
menuLayout:hide()
|
||||||
deactivateSiblings(self.rootMenu.children[1])
|
deactivateSiblings(self.rootMenu[1])
|
||||||
end
|
end
|
||||||
activate(event)
|
activate(event)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user