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
|
2016-08-21 08:57:32 +02:00
|
|
|
local function generic_widget(text, col)
|
2016-05-25 21:01:31 +02:00
|
|
|
return {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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
|
|
|
|
},
|
|
|
|
text and {
|
|
|
|
align = "center",
|
|
|
|
valign = "center",
|
|
|
|
text = text,
|
|
|
|
widget = wibox.widget.textbox
|
|
|
|
} or nil,
|
|
|
|
widget = wibox.layout.stack
|
|
|
|
},
|
|
|
|
margins = 5,
|
|
|
|
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
|
|
|
|
l:add(wibox.widget(generic_widget(names[j] or "N/A")))
|
|
|
|
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
|
|
|
|
awesome:emit_signal("refresh")
|
|
|
|
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
|