--DOC_GEN_IMAGE --DOC_HIDE_START local parent = ... local wibox = require("wibox") local color = require("gears.color") local cairo = require("lgi").cairo -- luacheck: push no max string line length local image_path = [[ ]] --luacheck: pop local l = wibox.layout { forced_width = 260, spacing = 5, layout = wibox.layout.fixed.vertical } local function sur_to_pat(img2) local pat = cairo.Pattern.create_for_surface(img2) pat:set_extend(cairo.Extend.REPEAT) return pat end -- Imported for elv13/blind/pattern.lua local function stripe_pat(col, angle, line_width, spacing) col = color(col) angle = angle or math.pi/4 line_width = line_width or 2 spacing = spacing or 2 local hy = line_width + 2*spacing -- Get the necessary width and height so the line repeat itself correctly local a, o = math.cos(angle)*hy, math.sin(angle)*hy local w, h = math.ceil(a + (line_width - 1)), math.ceil(o + (line_width - 1)) -- Create the pattern local img2 = cairo.SvgSurface.create(nil, w, h) local cr2 = cairo.Context(img2) cr2:set_antialias(cairo.ANTIALIAS_NONE) -- Avoid artefacts caused by anti-aliasing local offset = line_width -- Setup cr2:set_source(color(col)) cr2:set_line_width(line_width) -- The central line cr2:move_to(-offset, -offset) cr2:line_to(w+offset, h+offset) cr2:stroke() -- Top right cr2:move_to(-offset + w - spacing/2+line_width, -offset) cr2:line_to(2*w+offset - spacing/2+line_width, h+offset) cr2:stroke() -- Bottom left cr2:move_to(-offset + spacing/2-line_width, -offset + h) cr2:line_to(w+offset + spacing/2-line_width, 2*h+offset) cr2:stroke() return sur_to_pat(img2) end local stripe_pattern = stripe_pat("#ff0000") --DOC_HIDE_END local paddings = { 0, 5, 10, { left = 5, top = 5, bottom = 10, right = 10, } } --DOC_NEWLINE for _, padding in ipairs(paddings) do local w = wibox.widget { { { markup = "Central widget", valign = "center", align = "center", forced_height = 30, forced_width = 30, widget = wibox.widget.textbox }, bg = stripe_pattern, widget = wibox.container.background }, borders = 10, paddings = padding, border_image = image_path, widget = wibox.container.border } --DOC_HIDE_START if type(padding) == "table" then padding = "{left=5, top=5, bottom=10, right=10}" end l:add(wibox.widget { { markup = "paddings = "..padding.."", widget = wibox.widget.textbox, }, w, layout = wibox.layout.fixed.vertical, }) --DOC_HIDE_END end parent:add(l) --DOC_HIDE --DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80