diff --git a/lib/wibox/widget/template.lua b/lib/wibox/widget/template.lua index b67b351bd..81d943fdc 100644 --- a/lib/wibox/widget/template.lua +++ b/lib/wibox/widget/template.lua @@ -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(...) diff --git a/tests/examples/sequences/widget/tmpl/bind_property.lua b/tests/examples/sequences/widget/tmpl/bind_property.lua index b8f1289e2..cec436bdc 100644 --- a/tests/examples/sequences/widget/tmpl/bind_property.lua +++ b/tests/examples/sequences/widget/tmpl/bind_property.lua @@ -13,29 +13,27 @@ client.focus = client.gen_fake{ --DOC_HIDE_END local my_template_widget = wibox.widget.template { - template = { + { { - { - set_icon = function(self, icon) - self.image = gears.surface(icon) - end, - id = "icon_role", - widget = wibox.widget.imagebox - }, - { - id = "title_role", - widget = wibox.widget.textbox - }, - widget = wibox.layout.fixed.horizontal, + set_icon = function(self, icon) + self.image = gears.surface(icon) + end, + id = "icon_role", + widget = wibox.widget.imagebox }, - widget = wibox.container.background, - id = "background_role", - set_urgent = function(self, status) - self.bg = status and "#ff0000" or nil - end, - forced_width = 200, --DOC_HIDE - forced_height = 24, --DOC_HIDE - } + { + id = "title_role", + widget = wibox.widget.textbox + }, + widget = wibox.layout.fixed.horizontal, + }, + widget = wibox.container.background, + id = "background_role", + set_urgent = function(self, status) + self.bg = status and "#ff0000" or nil + end, + forced_width = 200, --DOC_HIDE + forced_height = 24, --DOC_HIDE } --DOC_NEWLINE diff --git a/tests/examples/wibox/widget/template/basic_textbox.lua b/tests/examples/wibox/widget/template/basic_textbox.lua index a9c2b574c..0be653662 100644 --- a/tests/examples/wibox/widget/template/basic_textbox.lua +++ b/tests/examples/wibox/widget/template/basic_textbox.lua @@ -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 diff --git a/tests/examples/wibox/widget/template/clone1.lua b/tests/examples/wibox/widget/template/clone1.lua index 330c6b606..4a8690031 100644 --- a/tests/examples/wibox/widget/template/clone1.lua +++ b/tests/examples/wibox/widget/template/clone1.lua @@ -23,37 +23,35 @@ client.focus = client.gen_fake{ --DOC_NEWLINE local default_template = wibox.widget.template { - template = { + { { { - { - forced_height = 16, - forced_width = 16, - shape = gears.shape.circle, - widget = wibox.widget.separator - }, - margins = 3, - widget = wibox.container.margin + forced_height = 16, + forced_width = 16, + shape = gears.shape.circle, + widget = wibox.widget.separator }, - { - set_color = function(self, color) - self.text = color - end, - text = "N/A", - widget = wibox.widget.textbox - }, - spacing = 5, - widget = wibox.layout.fixed.horizontal, + margins = 3, + widget = wibox.container.margin }, - set_color = function(self, color) - self.border_color = gears.color.to_rgba_string(color):sub(1,7).."44" - self.fg = color - end, - border_width = 1, - shape = gears.shape.octogon, - widget = wibox.container.background, - forced_width = 100, --DOC_HIDE - } + { + set_color = function(self, color) + self.text = color + end, + text = "N/A", + widget = wibox.widget.textbox + }, + spacing = 5, + widget = wibox.layout.fixed.horizontal, + }, + set_color = function(self, color) + self.border_color = gears.color.to_rgba_string(color):sub(1,7).."44" + self.fg = color + end, + border_width = 1, + shape = gears.shape.octogon, + widget = wibox.container.background, + forced_width = 100, --DOC_HIDE } --DOC_NEWLINE diff --git a/tests/examples/wibox/widget/template/concrete_implementation_module.lua b/tests/examples/wibox/widget/template/concrete_implementation_module.lua index 97deb39ec..8c4f0e6d2 100644 --- a/tests/examples/wibox/widget/template/concrete_implementation_module.lua +++ b/tests/examples/wibox/widget/template/concrete_implementation_module.lua @@ -10,8 +10,8 @@ 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, - text = "N/A", + widget = wibox.widget.textbox, + text = "N/A", update_callback = function(widget_template, args) local text = args and args.text or "???" widget_template.widget.text = text diff --git a/tests/examples/wibox/widget/template/concrete_implementation_user.lua b/tests/examples/wibox/widget/template/concrete_implementation_user.lua index 5fdc682fe..b6b3182dc 100644 --- a/tests/examples/wibox/widget/template/concrete_implementation_user.lua +++ b/tests/examples/wibox/widget/template/concrete_implementation_user.lua @@ -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" diff --git a/tests/examples/wibox/widget/template/set_property_existing.lua b/tests/examples/wibox/widget/template/set_property_existing.lua index b915310ea..08771623c 100644 --- a/tests/examples/wibox/widget/template/set_property_existing.lua +++ b/tests/examples/wibox/widget/template/set_property_existing.lua @@ -15,23 +15,21 @@ client.focus = client.gen_fake{ --DOC_HIDE_END local my_template_widget = wibox.widget.template { - template = { + { { - { - id = "icon_role", - widget = wibox.widget.imagebox - }, - { - id = "title_role", - widget = wibox.widget.textbox - }, - widget = wibox.layout.fixed.horizontal, + id = "icon_role", + widget = wibox.widget.imagebox }, - id = "background_role", - widget = wibox.container.background, - forced_width = 200, --DOC_HIDE - forced_height = 24, --DOC_HIDE - } + { + id = "title_role", + widget = wibox.widget.textbox + }, + widget = wibox.layout.fixed.horizontal, + }, + id = "background_role", + widget = wibox.container.background, + forced_width = 200, --DOC_HIDE + forced_height = 24, --DOC_HIDE } --DOC_NEWLINE