widget: Add an `:add_button()` method.
This is done now because a lot of code in `lib/` add buttons by manually extracting buttons from awful.button. Instead of adding ugly code to prevent using the legacy API, do this.
This commit is contained in:
parent
57f38f4824
commit
cf0385af80
|
@ -48,6 +48,10 @@
|
||||||
-- @param table
|
-- @param table
|
||||||
-- @see awful.button
|
-- @see awful.button
|
||||||
|
|
||||||
|
--- Add a new `awful.button` to this widget.
|
||||||
|
-- @tparam awful.button button The button to add.
|
||||||
|
-- @function add_button
|
||||||
|
|
||||||
--- Emit a signal and ensure all parent widgets in the hierarchies also
|
--- Emit a signal and ensure all parent widgets in the hierarchies also
|
||||||
-- forward the signal. This is useful to track signals when there is a dynamic
|
-- forward the signal. This is useful to track signals when there is a dynamic
|
||||||
-- set of containers and layouts wrapping the widget.
|
-- set of containers and layouts wrapping the widget.
|
||||||
|
|
|
@ -40,6 +40,29 @@ function base.widget:set_visible(b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Add a new `awful.button` to this widget.
|
||||||
|
-- @tparam awful.button button The button to add.
|
||||||
|
function base.widget:add_button(button)
|
||||||
|
if not button then return end
|
||||||
|
|
||||||
|
-- Simple case
|
||||||
|
if not self._private.buttons then
|
||||||
|
self:set_buttons({button})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- This could happen if something accidentally uses rawset
|
||||||
|
assert(self._private.buttons_formatted)
|
||||||
|
|
||||||
|
-- an `awful.button` is a tupple of `capi.button`
|
||||||
|
self._private.buttons_formatted = gtable.join(
|
||||||
|
self._private.buttons_formatted,
|
||||||
|
button
|
||||||
|
)
|
||||||
|
|
||||||
|
table.insert(self._private.buttons, button)
|
||||||
|
end
|
||||||
|
|
||||||
--- Is the widget visible?
|
--- Is the widget visible?
|
||||||
-- @treturn boolean
|
-- @treturn boolean
|
||||||
-- @method get_visible
|
-- @method get_visible
|
||||||
|
|
Loading…
Reference in New Issue