wibox.widget: Add new `get_children(recursive)` method to all widgets
This commit is contained in:
parent
7a7f9f2b64
commit
8da5c79bb8
|
@ -10,6 +10,7 @@ local table = table
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local type = type
|
local type = type
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
|
local util = require("awful.util")
|
||||||
local base = require("wibox.widget.base")
|
local base = require("wibox.widget.base")
|
||||||
|
|
||||||
local align = {}
|
local align = {}
|
||||||
|
@ -164,6 +165,12 @@ function align:set_third(widget)
|
||||||
self:emit_signal("widget::layout_changed")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
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
|
--- 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
|
-- ask for the sum of the sizes of its sub-widgets in its direction
|
||||||
-- and the largest sized sub widget in the other direction.
|
-- and the largest sized sub widget in the other direction.
|
||||||
|
|
|
@ -44,6 +44,12 @@ function constraint:set_widget(widget)
|
||||||
self:emit_signal("widget::layout_changed")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
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',
|
--- Set the strategy to use for the constraining. Valid values are 'max',
|
||||||
-- 'min' or 'exact'. Throws an error on invalid values.
|
-- 'min' or 'exact'. Throws an error on invalid values.
|
||||||
function constraint:set_strategy(val)
|
function constraint:set_strategy(val)
|
||||||
|
|
|
@ -72,6 +72,12 @@ function margin:set_widget(widget)
|
||||||
self:emit_signal("widget::layout_changed")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
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.
|
--- Set all the margins to val.
|
||||||
function margin:set_margins(val)
|
function margin:set_margins(val)
|
||||||
self.left = val
|
self.left = val
|
||||||
|
|
|
@ -58,6 +58,12 @@ function mirror:set_widget(widget)
|
||||||
self:emit_signal("widget::layout_changed")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
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.
|
--- Reset this layout. The widget will be removed and the axes reset.
|
||||||
function mirror:reset()
|
function mirror:reset()
|
||||||
self.horizontal = false
|
self.horizontal = false
|
||||||
|
|
|
@ -66,6 +66,12 @@ function rotate:set_widget(widget)
|
||||||
self:emit_signal("widget::layout_changed")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
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.
|
--- Reset this layout. The widget will be removed and the rotation reset.
|
||||||
function rotate:reset()
|
function rotate:reset()
|
||||||
self.direction = nil
|
self.direction = nil
|
||||||
|
|
|
@ -261,6 +261,12 @@ function scroll:set_widget(widget)
|
||||||
self:emit_signal("widget::redraw_needed")
|
self:emit_signal("widget::redraw_needed")
|
||||||
end
|
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.
|
--- Specify the expand mode that is used for extra space.
|
||||||
-- @tparam boolean expand If true, the widget is expanded to include the extra
|
-- @tparam boolean expand If true, the widget is expanded to include the extra
|
||||||
-- space. If false, the extra space is simply left empty.
|
-- space. If false, the extra space is simply left empty.
|
||||||
|
|
|
@ -69,6 +69,12 @@ function background:set_widget(widget)
|
||||||
self:emit_signal("widget::layout_changed")
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get the number of children element
|
||||||
|
-- @treturn table The children
|
||||||
|
function background:get_children()
|
||||||
|
return {self.widget}
|
||||||
|
end
|
||||||
|
|
||||||
--- Set the background to use
|
--- Set the background to use
|
||||||
function background:set_bg(bg)
|
function background:set_bg(bg)
|
||||||
if bg then
|
if bg then
|
||||||
|
|
|
@ -73,6 +73,32 @@ function base.widget:set_height(s)
|
||||||
end
|
end
|
||||||
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
|
-- {{{ Caches
|
||||||
|
|
Loading…
Reference in New Issue