-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc(w.w.template) 3rd party lib usage example
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/examples/wibox/widget/template/concrete_implementation_module.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--DOC_NO_USAGE | ||
|
||
--DOC_HIDE_START | ||
local parent = ... | ||
|
||
local gears = require("gears") | ||
local wibox = require("wibox") | ||
|
||
local concrete_widget_template_builder | ||
--DOC_HIDE_END | ||
|
||
-- Build the default widget used as a fallback if user doesn't provide a template | ||
local default_widget = { | ||
template = wibox.widget.textclock, | ||
update_callback = function(widget_template, args) | ||
local text = args.text or "???" | ||
widget_template.widget.text = text | ||
end, | ||
} | ||
|
||
--DOC_NEWLINE | ||
function concrete_widget_template_builder(args) | ||
-- Build an instance of the template widget with either, the | ||
-- user provided parameters or the default | ||
local ret = wibox.widget.template( | ||
args.widget_template and args.widget_template or | ||
default_widget | ||
) | ||
|
||
--DOC_NEWLINE | ||
-- Patch the methods and fields the widget instance should have | ||
|
||
--DOC_NEWLINE | ||
-- e.g. Apply the received buttons, visible, forced_width and so on | ||
gears.table.crush(ret, args) | ||
|
||
--DOC_NEWLINE | ||
-- Optionally, call update once with parameters to prepare the widget | ||
ret:update { | ||
text = "default text", | ||
} | ||
|
||
--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 | ||
|
36 changes: 36 additions & 0 deletions
36
tests/examples/wibox/widget/template/concrete_implementation_user.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--DOC_NO_USAGE | ||
|
||
--DOC_HIDE_START | ||
local parent = ... | ||
|
||
local wibox = require("wibox") | ||
|
||
local function concrete_widget_template_builder() end | ||
--DOC_HIDE_END | ||
|
||
-- Instanciate the widget with the default template | ||
local default_widget = concrete_widget_template_builder() | ||
|
||
--DOC_NEWLINE | ||
-- Instanciate the widget with a custom template | ||
local custom_widget = concrete_widget_template_builder { | ||
widget_template = { | ||
template = wibox.widget.imagebox, | ||
update_callback = function (template, args) | ||
if args.text == "default text" then | ||
template.widget.image = "/path/to/image.png" | ||
else | ||
template.widget.image = "/path/to/another-image.png" | ||
end | ||
end | ||
|
||
} | ||
} | ||
|
||
--DOC_HIDE_START | ||
|
||
parent:add(default_widget) | ||
parent:add(custom_widget) | ||
|
||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 | ||
|