wibox.template: Remove the `args` in favor of passing the template directly.

It didn't do much and I wanted to make the syntax a drop-in replacement
of `wibox.widget {}`.
This commit is contained in:
Emmanuel Lepage Vallee 2022-10-22 20:32:12 -07:00
parent 67b2b26683
commit 3765efaccc
7 changed files with 71 additions and 85 deletions

View File

@ -362,34 +362,28 @@ end
-- @method clone
-- @treturn wibox.widget.template The copy.
function template:clone()
return template {
template = self._private.widget_template
}
return template(self._private.widget_template)
end
--- Create a new `wibox.widget.template` instance.
-- @tparam[opt] table args
-- @tparam[opt] table|widget args.template The widget template to use.
-- @tparam[opt] function args.update_callback The callback function to update
-- @tparam[opt] table tmpl
-- @tparam[opt] function tmpl.update_callback The callback function to update
-- the widget.
-- @tparam[opt] boolean args.update_now Update the widget after its
-- @tparam[opt] boolean tmpl.update_now Update the widget after its
-- construction. This will call the `:update()` method with no parameter.
-- @treturn wibox.widget.template The new instance.
-- @constructorfct wibox.widget.template
function template.new(args)
args = args or {}
function template.new(tmpl)
tmpl = tmpl or {}
local ret = wbase.make_widget(nil, nil, { enable_properties = true })
gtable.crush(ret, template, true)
ret._private.connections = {}
ret:set_template(args.template)
ret:set_update_callback(args.update_callback)
ret:set_update_now(args.update_now)
-- Apply the received buttons, visible, forced_width and so on
gtable.crush(ret, args)
ret:set_template(tmpl)
ret:set_update_callback(tmpl.update_callback)
ret:set_update_now(tmpl.update_now)
rawset(ret, "_is_template", true)
@ -412,9 +406,7 @@ function template.make_from_value(value)
if rawget(value, "_is_template") then return value:clone() end
return template.new {
template = value
}
return template.new(value)
end
function template.mt:__call(...)

View File

@ -13,7 +13,6 @@ client.focus = client.gen_fake{
--DOC_HIDE_END
local my_template_widget = wibox.widget.template {
template = {
{
{
set_icon = function(self, icon)
@ -36,7 +35,6 @@ client.focus = client.gen_fake{
forced_width = 200, --DOC_HIDE
forced_height = 24, --DOC_HIDE
}
}
--DOC_NEWLINE
--DOC_HIDE_START

View File

@ -6,7 +6,7 @@ local wibox = require("wibox")
--DOC_HIDE_END
local my_template_widget = wibox.widget.template {
template = wibox.widget.textbox,
widget = wibox.widget.textbox,
update_callback = function(template_widget, args)
local text = args.text or "???"
template_widget.widget.text = text

View File

@ -23,7 +23,6 @@ client.focus = client.gen_fake{
--DOC_NEWLINE
local default_template = wibox.widget.template {
template = {
{
{
{
@ -54,7 +53,6 @@ client.focus = client.gen_fake{
widget = wibox.container.background,
forced_width = 100, --DOC_HIDE
}
}
--DOC_NEWLINE
--- Set the widget template.

View File

@ -10,7 +10,7 @@ local wibox = require("wibox")
-- Build the default widget used as a fallback if user doesn't provide a template
local default_widget = {
template = wibox.widget.textbox,
widget = wibox.widget.textbox,
text = "N/A",
update_callback = function(widget_template, args)
local text = args and args.text or "???"

View File

@ -17,7 +17,7 @@ end
-- Instanciate the widget with a custom template
local custom_widget = concrete_widget_template_builder {
widget_template = {
template = wibox.widget.imagebox,
widget = wibox.widget.imagebox,
update_callback = function (template, args)
if args and args.text == "default text" then
template.widget.image = "/path/to/image.png"

View File

@ -15,7 +15,6 @@ client.focus = client.gen_fake{
--DOC_HIDE_END
local my_template_widget = wibox.widget.template {
template = {
{
{
id = "icon_role",
@ -32,7 +31,6 @@ client.focus = client.gen_fake{
forced_width = 200, --DOC_HIDE
forced_height = 24, --DOC_HIDE
}
}
--DOC_NEWLINE
-- Later in the code