wibox.widget: Add new `get_children(recursive)` method to all widgets

This commit is contained in:
Emmanuel Lepage Vallee 2016-01-16 01:13:07 -05:00
parent 7a7f9f2b64
commit 8da5c79bb8
8 changed files with 69 additions and 0 deletions

View File

@ -10,6 +10,7 @@ local table = table
local pairs = pairs
local type = type
local floor = math.floor
local util = require("awful.util")
local base = require("wibox.widget.base")
local align = {}
@ -164,6 +165,12 @@ function align:set_third(widget)
self:emit_signal("widget::layout_changed")
end
--- Get all children of this layout
-- @treturn table a list of all widgets
function align:get_children()
return util.from_sparse {self.first, self.second, self.third}
end
--- Fit the align layout into the given space. The align layout will
-- ask for the sum of the sizes of its sub-widgets in its direction
-- and the largest sized sub widget in the other direction.

View File

@ -44,6 +44,12 @@ function constraint:set_widget(widget)
self:emit_signal("widget::layout_changed")
end
--- Get the number of children element
-- @treturn table The children
function constraint:get_children()
return {self.widget}
end
--- Set the strategy to use for the constraining. Valid values are 'max',
-- 'min' or 'exact'. Throws an error on invalid values.
function constraint:set_strategy(val)

View File

@ -72,6 +72,12 @@ function margin:set_widget(widget)
self:emit_signal("widget::layout_changed")
end
--- Get the number of children element
-- @treturn table The children
function margin:get_children()
return {self.widget}
end
--- Set all the margins to val.
function margin:set_margins(val)
self.left = val

View File

@ -58,6 +58,12 @@ function mirror:set_widget(widget)
self:emit_signal("widget::layout_changed")
end
--- Get the number of children element
-- @treturn table The children
function mirror:get_children()
return {self.widget}
end
--- Reset this layout. The widget will be removed and the axes reset.
function mirror:reset()
self.horizontal = false

View File

@ -66,6 +66,12 @@ function rotate:set_widget(widget)
self:emit_signal("widget::layout_changed")
end
--- Get the number of children element
-- @treturn table The children
function rotate:get_children()
return {self.widget}
end
--- Reset this layout. The widget will be removed and the rotation reset.
function rotate:reset()
self.direction = nil

View File

@ -261,6 +261,12 @@ function scroll:set_widget(widget)
self:emit_signal("widget::redraw_needed")
end
--- Get the number of children element
-- @treturn table The children
function scroll:get_children()
return {self.widget}
end
--- Specify the expand mode that is used for extra space.
-- @tparam boolean expand If true, the widget is expanded to include the extra
-- space. If false, the extra space is simply left empty.

View File

@ -69,6 +69,12 @@ function background:set_widget(widget)
self:emit_signal("widget::layout_changed")
end
--- Get the number of children element
-- @treturn table The children
function background:get_children()
return {self.widget}
end
--- Set the background to use
function background:set_bg(bg)
if bg then

View File

@ -73,6 +73,32 @@ function base.widget:set_height(s)
end
end
--- Get all direct children widgets
-- This method should be re-implemented by the relevant widgets
-- @treturn table The children
function base.widget:get_children()
return {}
end
-- It could have been merged into `get_all_children`, but it's not necessary
local function digg_children(ret, tlw)
for k, w in ipairs(tlw:get_children()) do
table.insert(ret, w)
digg_children(ret, w)
end
end
--- Get all direct and indirect children widgets
-- This will scan all containers recursively to find widgets
-- Warning: This method it prone to stack overflow id the widget, or any of its
-- children, contain (directly or indirectly) itself.
-- @treturn table The children
function base.widget:get_all_children()
local ret = {}
digg_children(ret, self)
return ret
end
-- }}}
-- {{{ Caches