widget.base: Add ':index(w, r)' method

This function is optionally recursive. This allow to manipulate
abstract layouts without really having to care about the exact
hierarchy.
This commit is contained in:
Emmanuel Lepage Vallee 2016-01-18 02:35:28 -05:00
parent 8da5c79bb8
commit b2d121aa18
1 changed files with 24 additions and 0 deletions

View File

@ -99,6 +99,30 @@ function base.widget:get_all_children()
return ret return ret
end end
--- Get a widex index
-- @param widget The widget to look for
-- @param[opt] recursive Also check sub-widgets
-- @param[opt] ... Aditional widgets to add at the end of the "path"
-- @return The index
-- @return The parent layout
-- @return The path between "self" and "widget"
function base.widget:index(widget, recursive, ...)
local widgets = self:get_children()
for idx, w in ipairs(widgets) do
if w == widget then
return idx, self, {...}
elseif recursive then
local idx, l, path = w:index(widget, true, self, ...)
if idx and l then
return idx, l, path
end
end
end
return nil, self, {}
end
-- }}} -- }}}
-- {{{ Caches -- {{{ Caches