wibox.widget: Add `set_children` method

Provide a generic method to set the widget content
This commit is contained in:
Emmanuel Lepage Vallee 2016-02-04 01:11:10 -05:00
parent 3ef5003ace
commit e36f23171b
10 changed files with 83 additions and 0 deletions

View File

@ -171,6 +171,17 @@ function align:get_children()
return util.from_sparse {self.first, self.second, self.third}
end
--- Replace the layout children
-- This layout only accept three children, all others will be ignored
-- @tparam table children A table composed of valid widgets
function align:set_children(children)
if not children then return self:reset() end
self.first = children[1]
self.second = children[2]
self.third = children[3]
self:emit_signal("widget::layout_changed")
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.
@ -243,6 +254,9 @@ local function get_layout(dir, first, second, third)
ret:set_second(second)
ret:set_third(third)
-- An align layout allow set_children to have empty entries
ret.allow_empty_widget = true
return ret
end

View File

@ -50,6 +50,14 @@ function constraint:get_children()
return {self.widget}
end
--- Replace the layout children
-- This layout only accept one children, all others will be ignored
-- @tparam table children A table composed of valid widgets
function constraint:set_children(children)
self.widget = children and children[1]
self:emit_signal("widget::layout_changed")
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

@ -110,6 +110,14 @@ function fixed:get_children()
return self.widgets
end
--- Replace the layout children
-- @tparam table children A table composed of valid widgets
function fixed:set_children(children)
if not children then return self:reset() end
self.widgets = children
self:emit_signal("widget::layout_changed")
end
--- Replace the first instance of `widget` in the layout with `widget2`
-- @param widget The widget to replace
-- @param widget2 The widget to replace `widget` with

View File

@ -31,6 +31,11 @@ local flex = {}
-- @name get_children
-- @class function
--- Replace the layout children
-- @tparam table children A table composed of valid widgets
-- @name set_children
-- @class function
--- Add some widgets to the given fixed layout
-- @param layout The layout you are modifying.
-- @tparam widget ... Widgets that should be added (must at least be one)

View File

@ -78,6 +78,14 @@ function margin:get_children()
return {self.widget}
end
--- Replace the layout children
-- This layout only accept one children, all others will be ignored
-- @tparam table children A table composed of valid widgets
function margin:set_children(children)
self.widget = children and children[1]
self:emit_signal("widget::layout_changed")
end
--- Set all the margins to val.
function margin:set_margins(val)
self.left = val

View File

@ -64,6 +64,14 @@ function mirror:get_children()
return {self.widget}
end
--- Replace the layout children
-- This layout only accept one children, all others will be ignored
-- @tparam table children A table composed of valid widgets
function mirror:set_children(children)
self.widget = children and children[1]
self:emit_signal("widget::layout_changed")
end
--- Reset this layout. The widget will be removed and the axes reset.
function mirror:reset()
self.horizontal = false

View File

@ -72,6 +72,14 @@ function rotate:get_children()
return {self.widget}
end
--- Replace the layout children
-- This layout only accept one children, all others will be ignored
-- @tparam table children A table composed of valid widgets
function rotate:set_children(children)
self.widget = children and children[1]
self:emit_signal("widget::layout_changed")
end
--- Reset this layout. The widget will be removed and the rotation reset.
function rotate:reset()
self.direction = nil

View File

@ -267,6 +267,14 @@ function scroll:get_children()
return {self.widget}
end
--- Replace the layout children
-- This layout only accept one children, all others will be ignored
-- @tparam table children A table composed of valid widgets
function scroll:set_children(children)
self.widget = children and children[1]
self:emit_signal("widget::layout_changed")
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

@ -101,6 +101,14 @@ function background:get_children()
return {self.widget}
end
--- Replace the layout children
-- This layout only accept one children, all others will be ignored
-- @tparam table children A table composed of valid widgets
function background:set_children(children)
self.widget = children and children[1]
self:emit_signal("widget::layout_changed")
end
--- Set the background to use
function background:set_bg(bg)
if bg then

View File

@ -80,6 +80,14 @@ function base.widget:get_children()
return {}
end
--- Replace the layout children
-- The default implementation does nothing, this must be re-implemented by
-- all layout and container widgets.
-- @tparam table children A table composed of valid widgets
function base.widget:set_children(children)
-- Nothing on purpose
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