2022-10-16 10:30:57 +02:00
|
|
|
--DOC_NO_USAGE --DOC_GEN_IMAGE
|
2021-11-12 16:05:22 +01:00
|
|
|
|
|
|
|
--DOC_HIDE_START
|
|
|
|
local parent = ...
|
|
|
|
|
|
|
|
local gears = require("gears")
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
|
|
|
--DOC_HIDE_END
|
|
|
|
|
|
|
|
-- Build the default widget used as a fallback if user doesn't provide a template
|
|
|
|
local default_widget = {
|
2022-10-23 05:32:12 +02:00
|
|
|
widget = wibox.widget.textbox,
|
|
|
|
text = "N/A",
|
2021-11-12 16:05:22 +01:00
|
|
|
update_callback = function(widget_template, args)
|
|
|
|
local text = args and args.text or "???"
|
|
|
|
widget_template.widget.text = text
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
--DOC_NEWLINE
|
2022-10-16 10:30:57 +02:00
|
|
|
local function concrete_widget_template_builder(args)
|
2021-11-12 16:05:22 +01:00
|
|
|
args = args or {}
|
|
|
|
|
|
|
|
--DOC_NEWLINE
|
|
|
|
-- Build an instance of the template widget with either, the
|
|
|
|
-- user provided parameters or the default
|
2022-10-23 06:00:13 +02:00
|
|
|
local ret = wibox.template(args.widget_template or default_widget)
|
2021-11-12 16:05:22 +01:00
|
|
|
|
|
|
|
--DOC_NEWLINE
|
2022-10-16 10:30:57 +02:00
|
|
|
-- Patch the methods and fields the widget instance should have
|
2021-11-12 16:05:22 +01:00
|
|
|
|
|
|
|
--DOC_NEWLINE
|
2022-10-16 10:30:57 +02:00
|
|
|
-- e.g. Apply the received buttons, visible, forced_width and so on
|
|
|
|
gears.table.crush(ret, args)
|
2021-11-12 16:05:22 +01:00
|
|
|
|
|
|
|
--DOC_NEWLINE
|
|
|
|
-- Optionally, call update once with parameters to prepare the widget
|
2022-10-16 10:30:57 +02:00
|
|
|
ret:update {
|
|
|
|
text = "default text",
|
|
|
|
}
|
2021-11-12 16:05:22 +01:00
|
|
|
|
|
|
|
--DOC_NEWLINE
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--DOC_HIDE_START
|
|
|
|
|
|
|
|
local w = concrete_widget_template_builder()
|
|
|
|
parent:add(w)
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
|
|
|
|