2016-07-09 19:03:49 +02:00
|
|
|
local file_path, image_path = ...
|
|
|
|
require("_common_template")(...)
|
2016-05-25 21:01:31 +02:00
|
|
|
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local color = require( "gears.color" )
|
|
|
|
local beautiful = require( "beautiful" )
|
2016-08-21 08:57:32 +02:00
|
|
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
2016-05-25 21:01:31 +02:00
|
|
|
|
|
|
|
-- Create a generic rectangle widget to show layout disposition
|
2017-08-07 22:49:48 +02:00
|
|
|
local function generic_widget(text, col, margins)
|
2016-10-09 07:32:31 +02:00
|
|
|
return wibox.widget {
|
2016-05-25 21:01:31 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
draw = function(_, _, cr, width, height)
|
2016-08-21 08:57:32 +02:00
|
|
|
cr:set_source(color(col or beautiful.bg_normal))
|
2016-05-25 21:01:31 +02:00
|
|
|
cr:set_line_width(3)
|
|
|
|
cr:rectangle(0, 0, width, height)
|
|
|
|
cr:fill_preserve()
|
|
|
|
cr:set_source(color(beautiful.border_color))
|
|
|
|
cr:stroke()
|
|
|
|
end,
|
|
|
|
widget = wibox.widget.base.make_widget
|
|
|
|
},
|
2016-10-09 07:32:31 +02:00
|
|
|
{
|
|
|
|
id = "text",
|
2022-09-04 09:33:09 +02:00
|
|
|
halign = "center",
|
2016-05-25 21:01:31 +02:00
|
|
|
valign = "center",
|
2016-10-09 07:32:31 +02:00
|
|
|
text = text or "foobar",
|
2016-05-25 21:01:31 +02:00
|
|
|
widget = wibox.widget.textbox
|
|
|
|
} or nil,
|
|
|
|
widget = wibox.layout.stack
|
|
|
|
},
|
2017-08-07 22:49:48 +02:00
|
|
|
margins = margins or 5,
|
2016-10-09 07:32:31 +02:00
|
|
|
set_text = function(self, text2)
|
|
|
|
self:get_children_by_id("text")[1]:set_text(text2)
|
|
|
|
end,
|
|
|
|
is_widget = true,
|
2016-05-25 21:01:31 +02:00
|
|
|
widget = wibox.container.margin,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-08-21 08:57:32 +02:00
|
|
|
local names = {
|
|
|
|
"first" ,
|
|
|
|
"second" ,
|
|
|
|
"third" ,
|
|
|
|
"fourth" ,
|
|
|
|
"fifth" ,
|
|
|
|
"sixth" ,
|
|
|
|
"seventh",
|
|
|
|
"eighth" ,
|
|
|
|
"ninth" ,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Generic template to create "before and after" for layout mutators
|
|
|
|
local function generic_before_after(layout, layout_args, count, method, method_args)
|
|
|
|
local ls = {}
|
|
|
|
|
|
|
|
-- Create the layouts
|
|
|
|
for i=1, 2 do
|
|
|
|
local args = {layout = layout}
|
|
|
|
|
|
|
|
-- In case the layout change the array (it is technically not forbidden)
|
|
|
|
for k,v in pairs(layout_args) do
|
|
|
|
args[k] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
local l = wibox.layout(args)
|
|
|
|
for j=1, count or 3 do
|
2016-10-09 07:32:31 +02:00
|
|
|
l:add(generic_widget(names[j] or "N/A"))
|
2016-08-21 08:57:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
ls[i] = l
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Mutate
|
|
|
|
if type(method) == "function" then
|
|
|
|
method(ls[2], unpack(method_args or {}))
|
|
|
|
else
|
|
|
|
ls[2][method](ls[2], unpack(method_args or {}))
|
|
|
|
end
|
|
|
|
|
|
|
|
return wibox.layout {
|
|
|
|
{
|
|
|
|
markup = "<b>Before:</b>",
|
|
|
|
widget = wibox.widget.textbox,
|
|
|
|
},
|
|
|
|
ls[1],
|
|
|
|
{
|
|
|
|
markup = "<b>After:</b>",
|
|
|
|
widget = wibox.widget.textbox,
|
|
|
|
},
|
|
|
|
ls[2],
|
|
|
|
layout = wibox.layout.fixed.vertical
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-05-25 21:01:31 +02:00
|
|
|
-- Let the test request a size and file format
|
2016-08-21 08:57:32 +02:00
|
|
|
local widget, w, h = loadfile(file_path)(generic_widget, generic_before_after)
|
2016-05-25 21:01:31 +02:00
|
|
|
|
|
|
|
-- Emulate the event loop for 10 iterations
|
|
|
|
for _ = 1, 10 do
|
2019-02-15 17:04:19 +01:00
|
|
|
require("gears.timer").run_delayed_calls_now()
|
2016-05-25 21:01:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Save to the output file
|
2017-05-30 10:33:52 +02:00
|
|
|
wibox.widget.draw_to_svg_file(widget, image_path..".svg", w or 200, h or 30)
|
2016-12-31 13:59:38 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|