diff --git a/tests/examples/wibox/container/border/border_images1.lua b/tests/examples/wibox/container/border/border_images1.lua new file mode 100644 index 000000000..69a3ecfba --- /dev/null +++ b/tests/examples/wibox/container/border/border_images1.lua @@ -0,0 +1,59 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") +local beautiful = require( "beautiful" ) +local gears = { color = require("gears.color")} + +local red_logo = beautiful._logo(nil, gears.color("#ff0000")) +local green_logo = beautiful._logo(nil, gears.color("#00ff00")) +local blue_logo = beautiful._logo(nil, gears.color("#0000ff")) +local yellow_logo = beautiful._logo(nil, gears.color("#ffff00")) +local orange_logo = beautiful._logo(nil, gears.color("#ffbb00")) +local purple_logo = beautiful._logo(nil, gears.color("#ff00ff")) +local cyan_logo = beautiful._logo(nil, gears.color("#00ffff")) +local black_logo = beautiful._logo(nil, gears.color("#000000")) + +--DOC_HIDE_END + +local w1 = wibox.widget { + { + text = "Single image", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + borders = 20, + sides_fit_policy = "repeat", + border_images = blue_logo, + widget = wibox.container.border +} + +--DOC_NEWLINE + +local w2 = wibox.widget { + { + text = "Multiple images", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + sides_fit_policy = "repeat", + border_images = { + top_left = red_logo, + top = green_logo, + top_right = blue_logo, + right = yellow_logo, + bottom_right = orange_logo, + bottom = purple_logo, + bottom_left = cyan_logo, + left = black_logo, + }, + widget = wibox.container.border +} + +--DOC_HIDE_START + +parent.spacing = 20 +parent:add(w1) +parent:add(w2) +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/border_merging1.lua b/tests/examples/wibox/container/border/border_merging1.lua new file mode 100644 index 000000000..e9b9f1c9b --- /dev/null +++ b/tests/examples/wibox/container/border/border_merging1.lua @@ -0,0 +1,73 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") +local beautiful = require( "beautiful" ) + +local function generic_widget(text, margins) + return wibox.widget { + { + { + { + id = "text", + align = "center", + valign = "center", + text = text, + widget = wibox.widget.textbox + }, + margins = 10, + widget = wibox.container.margin, + }, + border_width = 3, + border_color = beautiful.border_color, + bg = beautiful.bg_normal, + widget = wibox.container.background + }, + margins = margins or 5, + widget = wibox.container.margin, + } +end + +local l = wibox.layout { + spacing = 100, + forced_num_cols = 2, + forced_num_rows = 2, + homogeneous = true, + expand = true, + layout = wibox.layout.grid.vertical +} + +--DOC_HIDE_END + +for _, side in ipairs { "top", "bottom", "left", "right" } do + l:add(wibox.widget { + { + text = side .. " = true", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + border_merging = { + -- This is the equaivalent "left = true,". "side" is the loop + -- variable. + [side] = true + }, + border_widgets = { + top_left = generic_widget("top_left"), + top = generic_widget("top"), + top_right = generic_widget("top_right"), + right = generic_widget("right"), + bottom_right = generic_widget("bottom_right"), + bottom = generic_widget("bottom"), + bottom_left = generic_widget("bottom_left"), + left = generic_widget("left"), + }, + widget = wibox.container.border + }) +end + + +--DOC_HIDE_START + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/border_widgets1.lua b/tests/examples/wibox/container/border/border_widgets1.lua new file mode 100644 index 000000000..c2ce21734 --- /dev/null +++ b/tests/examples/wibox/container/border/border_widgets1.lua @@ -0,0 +1,55 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") +local beautiful = require( "beautiful" ) + +local function generic_widget(text, margins) + return wibox.widget { + { + { + { + id = "text", + align = "center", + valign = "center", + text = text, + widget = wibox.widget.textbox + }, + margins = 10, + widget = wibox.container.margin, + }, + border_width = 3, + border_color = beautiful.border_color, + bg = beautiful.bg_normal, + widget = wibox.container.background + }, + margins = margins or 5, + widget = wibox.container.margin, + } +end + +--DOC_HIDE_END + +local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + border_widgets = { + top_left = generic_widget("top_left"), + top = generic_widget("top"), + top_right = generic_widget("top_right"), + right = generic_widget("right"), + bottom_right = generic_widget("bottom_right"), + bottom = generic_widget("bottom"), + bottom_left = generic_widget("bottom_left"), + left = generic_widget("left"), + }, + widget = wibox.container.border +} + +--DOC_HIDE_START + +parent:add(w) +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/borders1.lua b/tests/examples/wibox/container/border/borders1.lua new file mode 100644 index 000000000..bd5d07cde --- /dev/null +++ b/tests/examples/wibox/container/border/borders1.lua @@ -0,0 +1,104 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") +local cairo = require("lgi").cairo + +-- luacheck: push no max string line length + +local svg_image_path = [[ + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +-- There is no path there, but that's just for the doc. +local handle = wibox.widget.imagebox._load_rsvg_handle(svg_image_path) +local png_image_path = cairo.ImageSurface(cairo.Format.ARGB32, 48, 48) +local cr = cairo.Context(png_image_path) +handle:render_cairo(cr) + +local l = wibox.layout { + forced_width = 440, + spacing = 5, + forced_num_cols = 2, + homogeneous = false, + expand = false, + layout = wibox.layout.grid.vertical +} + +l:add_widget_at(wibox.widget { + markup = "SVG image (34x34 pt):", + widget = wibox.widget.textbox, +},1,1) + +l:add_widget_at(wibox.widget { + markup = "PNG image (48x48 px):", + widget = wibox.widget.textbox, +},1,2) + +l:add_widget_at(wibox.widget { + image = svg_image_path, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 1, 1, 1) + +l:add_widget_at(wibox.widget { + image = png_image_path, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 2, 1, 1) + +--DOC_HIDE_END +for k, borders in ipairs {0, 10, 30, 64} do + --DOC_HIDE_START + local r = 1 + k*2 + + l:add_widget_at(wibox.widget { + markup = "borders = ".. borders .."", + widget = wibox.widget.textbox, + }, r, 1, 1, 2) + --DOC_HIDE_END + + for idx, image in ipairs {svg_image_path, png_image_path} do + local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + forced_height = 30, + forced_width = 30, + widget = wibox.widget.textbox + }, + fill = false, + borders = borders, + border_image = image, + forced_width = 200, --DOC_HIDE + forced_height = 100, + widget = wibox.container.border + } + l:add_widget_at(w, r+1, idx, 1, 1) + end +end +--DOC_HIDE_START + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/corners_fit_policy1.lua b/tests/examples/wibox/container/border/corners_fit_policy1.lua new file mode 100644 index 000000000..d97686596 --- /dev/null +++ b/tests/examples/wibox/container/border/corners_fit_policy1.lua @@ -0,0 +1,122 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +-- luacheck: push no max string line length + +local image_path1 = [[ + + + + + + + + + + + + + + + +]] + +local image_path2 = [[ + + + + + + + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +local l = wibox.layout { + forced_width = 440, + spacing = 5, + forced_num_cols = 2, + homogeneous = false, + expand = false, + layout = wibox.layout.grid.vertical +} + +l:add(wibox.widget { + markup = "Original image:", + widget = wibox.widget.textbox, +}) + +l:add_widget_at(wibox.widget { + image = image_path1, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 1, 1, 1) + +l:add_widget_at(wibox.widget { + image = image_path2, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 2, 1, 1) + +--DOC_HIDE_END +for k, mode in ipairs {"fit", "repeat", "reflect", "pad"} do + --DOC_HIDE_START + local r = 1 + k*2 + + l:add_widget_at(wibox.widget { + markup = "corners_fit_policy = \"".. mode .."\"", + widget = wibox.widget.textbox, + }, r, 1, 1, 2) + --DOC_HIDE_END + + + for idx, image in ipairs { image_path1, image_path2 } do + local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + fill = false, + borders = { + left = 10, + right = 50, + top = 10, + bottom = 50, + }, + border_image = image, + corners_fit_policy = mode, + forced_width = 200, --DOC_HIDE + widget = wibox.container.border + } + + l:add_widget_at(w, r+1, idx, 1, 1) --DOC_HIDE + end + --DOC_HIDE_END +end +--DOC_HIDE_START + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/custom_draw1.lua b/tests/examples/wibox/container/border/custom_draw1.lua new file mode 100644 index 000000000..9eac39e4a --- /dev/null +++ b/tests/examples/wibox/container/border/custom_draw1.lua @@ -0,0 +1,29 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE +local parent = ... +local wibox = require("wibox") + +--DOC_HIDE_END + + local w = wibox.widget { + { + text = "Center widget", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + after_draw_children = function(_, _, cr, width, height) + cr:set_source_rgba(1,0,0,1) + cr:set_dash({1,1},1) + cr:rectangle(1, 1, width-2, height-2) + cr:rectangle(5, 5, width-10, height-10) + cr:stroke() + end, + borders = 20, + honor_borders = false, + forced_width = 100, --DOC_HIDE + forced_height = 50, --DOC_HIDE + widget = wibox.container.border + } + +parent:add(w) --DOC_HIDE +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/dpi1.lua b/tests/examples/wibox/container/border/dpi1.lua new file mode 100644 index 000000000..81935e677 --- /dev/null +++ b/tests/examples/wibox/container/border/dpi1.lua @@ -0,0 +1,104 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") +local cairo = require("lgi").cairo + +-- luacheck: push no max string line length + +local svg_image_path = [[ + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +-- There is no path there, but that's just for the doc. +local handle = wibox.widget.imagebox._load_rsvg_handle(svg_image_path) +local png_image_path = cairo.ImageSurface(cairo.Format.ARGB32, 48, 48) +local cr = cairo.Context(png_image_path) +handle:render_cairo(cr) + +local l = wibox.layout { + forced_width = 440, + spacing = 5, + forced_num_cols = 2, + homogeneous = false, + expand = false, + layout = wibox.layout.grid.vertical +} + +l:add_widget_at(wibox.widget { + markup = "SVG image (34x34 pt):", + widget = wibox.widget.textbox, +},1,1) + +l:add_widget_at(wibox.widget { + markup = "PNG image (48x48 px):", + widget = wibox.widget.textbox, +},1,2) + +l:add_widget_at(wibox.widget { + image = svg_image_path, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 1, 1, 1) + +l:add_widget_at(wibox.widget { + image = png_image_path, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 2, 1, 1) + +--DOC_HIDE_END +for k, dpi in ipairs {72, 96, 220} do + --DOC_HIDE_START + local r = 1 + k*2 + + l:add_widget_at(wibox.widget { + markup = "border_image_dpi = ".. dpi .."", + widget = wibox.widget.textbox, + }, r, 1, 1, 2) + --DOC_HIDE_END + + for idx, image in ipairs {svg_image_path, png_image_path} do + local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + forced_height = 30, + forced_width = 30, + widget = wibox.widget.textbox + }, + fill = false, + border_image_dpi = dpi, + borders = 10, + border_image = image, + forced_width = 200, --DOC_HIDE + widget = wibox.container.border + } + l:add_widget_at(w, r+1, idx, 1, 1) + end +end +--DOC_HIDE_START + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/dual1.lua b/tests/examples/wibox/container/border/dual1.lua new file mode 100644 index 000000000..0a49b9b3b --- /dev/null +++ b/tests/examples/wibox/container/border/dual1.lua @@ -0,0 +1,90 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE +local parent = ... +local wibox = require("wibox") +local beautiful = require( "beautiful" ) + +-- luacheck: push no max line length + +local image_path = ''.. + ''.. + ' '.. + ' '.. + ' '.. + ' '.. + ' '.. + ' ' .. + ' '.. + ' '.. + ' '.. + '' + +--luacheck: pop + +local function generic_widget(text) + return wibox.widget { + { + { + { + id = "text", + align = "center", + valign = "center", + text = text, + widget = wibox.widget.textbox + }, + margins = 10, + widget = wibox.container.margin, + }, + border_width = 3, + border_color = "transparent", + bg = beautiful.bg_normal, + widget = wibox.container.background + }, + opacity = 0.5, + widget = wibox.container.margin, + } +end + +--DOC_HIDE_END + local w = wibox.widget { + -- This is the background border. + { + paddings = { + left = 5, + top = 3, + right = 10, + bottom = 10, + }, + borders = 20, + border_image = image_path, + honor_borders = false, + widget = wibox.container.border + }, + -- This border container is used top place widgets. + { + { + text = "Center widget", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + border_widgets = { + top_left = generic_widget(""), + top = generic_widget("top"), + top_right = generic_widget(""), + right = generic_widget("right"), + bottom_right = generic_widget(""), + bottom = generic_widget("bottom"), + bottom_left = generic_widget(""), + left = generic_widget("left"), + }, + widget = wibox.container.border + }, + forced_width = 200, --DOC_HIDE + forced_height = 200, --DOC_HIDE + layout = wibox.layout.stack + } + +--DOC_HIDE_START +parent:add(w) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/expand_corners1.lua b/tests/examples/wibox/container/border/expand_corners1.lua new file mode 100644 index 000000000..55ef69093 --- /dev/null +++ b/tests/examples/wibox/container/border/expand_corners1.lua @@ -0,0 +1,58 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") +local beautiful = require( "beautiful" ) + +parent.spacing = 50 + +local function generic_widget(text, margins) + return wibox.widget { + { + { + { + id = "text", + align = "center", + valign = "center", + text = text, + widget = wibox.widget.textbox + }, + margins = 10, + widget = wibox.container.margin, + }, + border_width = 3, + border_color = beautiful.border_color, + bg = beautiful.bg_normal, + widget = wibox.container.background + }, + margins = margins or 5, + widget = wibox.container.margin, + } +end + +--DOC_HIDE_END + +for _, expand in ipairs { false, true } do + local w = wibox.widget { + { + text = "expand_corners = " .. (expand and "true" or "false"), + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + border_widgets = { + top_left = generic_widget("top_left"), + top = generic_widget("top"), + top_right = generic_widget("top_right"), + right = generic_widget("right"), + bottom_right = generic_widget("bottom_right"), + bottom = generic_widget("bottom"), + bottom_left = generic_widget("bottom_left"), + left = generic_widget("left"), + }, + expand_corners = expand, + widget = wibox.container.border + } + parent:add(wibox.container.place(w)) --DOC_HIDE +end + +----DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/fill1.lua b/tests/examples/wibox/container/border/fill1.lua new file mode 100644 index 000000000..c13804184 --- /dev/null +++ b/tests/examples/wibox/container/border/fill1.lua @@ -0,0 +1,75 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +-- luacheck: push no max string line length + +local image_path = [[ + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +local l = wibox.layout { + forced_width = 240, + spacing = 5, + layout = wibox.layout.fixed.vertical +} + +l:add(wibox.widget { + markup = "Original image:", + widget = wibox.widget.textbox, +}) + +l:add(wibox.widget { + image = image_path, + forced_height = 48, + forced_width = 48, + widget = wibox.widget.imagebox, +}) + +for _, fill in ipairs {true, false} do + --DOC_HIDE_END + local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + forced_height = 30, + forced_width = 30, + widget = wibox.widget.textbox + }, + borders = 10, + border_image = image_path, + fill = fill, + widget = wibox.container.border + } + + --DOC_HIDE_START + l:add(wibox.widget { + { + markup = "`fill` = "..(fill and "true" or "false").."", + widget = wibox.widget.textbox, + }, + w, + layout = wibox.layout.fixed.vertical, + }) +end + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/filling_fit_policy1.lua b/tests/examples/wibox/container/border/filling_fit_policy1.lua new file mode 100644 index 000000000..a20da39f3 --- /dev/null +++ b/tests/examples/wibox/container/border/filling_fit_policy1.lua @@ -0,0 +1,117 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +-- luacheck: push no max line length +local image_path1 = [[ + + + + + + + + + + + + + + + +]] + +local image_path2 = [[ + + + + + + + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +local l = wibox.layout { + forced_width = 440, + spacing = 5, + forced_num_cols = 2, + homogeneous = false, + expand = false, + layout = wibox.layout.grid.vertical +} + +l:add(wibox.widget { + markup = "Original image:", + widget = wibox.widget.textbox, +}) + +l:add_widget_at(wibox.widget { + image = image_path1, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 1, 1, 1) + +l:add_widget_at(wibox.widget { + image = image_path2, + forced_height = 48, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, +}, 2, 2, 1, 1) + +--DOC_HIDE_END +for k, mode in ipairs {"fit", "repeat", "reflect", "pad"} do + --DOC_HIDE_START + local r = 1 + k*2 + + l:add_widget_at(wibox.widget { + markup = "filling_fit_policy = \"".. mode .."\"", + widget = wibox.widget.textbox, + }, r, 1, 1, 2) + --DOC_HIDE_END + + + for idx, image in ipairs { image_path1, image_path2 } do + local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + forced_height = 50, --DOC_HIDE + widget = wibox.widget.textbox + }, + fill = true, + borders = idx == 1 and 10 or 30, + border_image = image, + filling_fit_policy = mode, + forced_width = 200, --DOC_HIDE + widget = wibox.container.border + } + + l:add_widget_at(w, r+1, idx, 1, 1) --DOC_HIDE + end + --DOC_HIDE_END +end +--DOC_HIDE_START + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/honor_borders1.lua b/tests/examples/wibox/container/border/honor_borders1.lua new file mode 100644 index 000000000..24a959cee --- /dev/null +++ b/tests/examples/wibox/container/border/honor_borders1.lua @@ -0,0 +1,121 @@ +--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 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") + +local l = wibox.layout { + forced_width = 240, + spacing = 5, + layout = wibox.layout.fixed.vertical +} + +for _, honor in ipairs {true, false} do + --DOC_HIDE_END + 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, + border_image = image_path, + honor_borders = honor, + widget = wibox.container.border + } + + --DOC_HIDE_START + l:add(wibox.widget { + { + markup = "honor_borders = "..(honor and "true" or "false").."", + widget = wibox.widget.textbox, + }, + w, + layout = wibox.layout.fixed.vertical, + }) +end + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/ontop1.lua b/tests/examples/wibox/container/border/ontop1.lua new file mode 100644 index 000000000..0b5cf4ce1 --- /dev/null +++ b/tests/examples/wibox/container/border/ontop1.lua @@ -0,0 +1,132 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") +local color = require("gears.color") +local beautiful = require( "beautiful" ) +local cairo = require("lgi").cairo + +-- luacheck: push no max string line length +local image_path = [[ + + + + + + + + + + + + + + + + + + + + +]] +--luacheck: pop + +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(beautiful.bg_normal) + +local l = wibox.layout { + forced_width = 240, + spacing = 5, + layout = wibox.layout.fixed.vertical +} + +for _, ontop in ipairs {true, false} do + --DOC_HIDE_END + 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 + }, + paddings = { + left = 5, + top = 3, + right = 10, + bottom = 10, + }, + borders = 20, + border_image = image_path, + ontop = ontop, + honor_borders = false, + widget = wibox.container.border + } + + --DOC_HIDE_START + l:add(wibox.widget { + { + markup = "ontop = "..(ontop and "true" or "false").."", + widget = wibox.widget.textbox, + }, + w, + layout = wibox.layout.fixed.vertical, + }) +end + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/paddings1.lua b/tests/examples/wibox/container/border/paddings1.lua new file mode 100644 index 000000000..477707e70 --- /dev/null +++ b/tests/examples/wibox/container/border/paddings1.lua @@ -0,0 +1,142 @@ +--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 diff --git a/tests/examples/wibox/container/border/sides_fit_policy1.lua b/tests/examples/wibox/container/border/sides_fit_policy1.lua new file mode 100644 index 000000000..51b976c84 --- /dev/null +++ b/tests/examples/wibox/container/border/sides_fit_policy1.lua @@ -0,0 +1,157 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +-- luacheck: push no max string line length + +local image_path1 = [[ + + + + + + + + + + + + + + + +]] + +local image_path2 = [[ + + + + + + + + + + + + + + + + + + + + + +]] + +local image_path3 = [[ + + + + + + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +local l = wibox.layout { + forced_width = 640, + spacing = 5, + forced_num_cols = 2, + homogeneous = false, + expand = false, + layout = wibox.layout.grid.vertical +} + +l:add(wibox.widget { + markup = "Original image:", + widget = wibox.widget.textbox, +}) + +for idx, original in ipairs {image_path1, image_path2, image_path3 } do + l:add_widget_at(wibox.widget { + image = original, + forced_height = 64, + forced_width = 200, + halign = "center", + widget = wibox.widget.imagebox, + }, 2, idx, 1, 1) +end + +--DOC_HIDE_END + +local images = { + { + path = image_path1, + borders = 10, + }, + { + path = image_path2, + borders = 30, + }, + { + path = image_path3, + borders = { + top = 20, + left = 20, + bottom = 20, + right = 20, + }, + }, +} + +--DOC_NEWLINE + +for k, mode in ipairs {"fit", "repeat", "reflect", "pad"} do + --DOC_HIDE_START + local r = 1 + k*2 + + l:add_widget_at(wibox.widget { + markup = "sides_fit_policy = \"".. mode .."\"", + widget = wibox.widget.textbox, + }, r, 1, 1, 2) + --DOC_HIDE_END + + + for idx, image in ipairs(images) do + local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + fill = false, + borders = image.borders, + border_image = image.path, + sides_fit_policy = mode, + forced_width = 200, --DOC_HIDE + widget = wibox.container.border + } + + l:add_widget_at(w, r+1, idx, 1, 1) --DOC_HIDE + end + --DOC_HIDE_END +end +--DOC_HIDE_START + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/slice1.lua b/tests/examples/wibox/container/border/slice1.lua new file mode 100644 index 000000000..4ddbf6b97 --- /dev/null +++ b/tests/examples/wibox/container/border/slice1.lua @@ -0,0 +1,76 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +-- luacheck: push no max string line length + +local image_path = [[ + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +local l = wibox.layout { + forced_width = 240, + spacing = 5, + layout = wibox.layout.fixed.vertical +} + +l:add(wibox.widget { + markup = "Original image:", + widget = wibox.widget.textbox, +}) + +l:add(wibox.widget { + image = image_path, + forced_height = 48, + forced_width = 48, + widget = wibox.widget.imagebox, +}) + +for _, i in ipairs {true, false} do + --DOC_HIDE_END + local w = wibox.widget { + { + text = "Central widget", + valign = "center", + align = "center", + forced_height = 30, + forced_width = 30, + widget = wibox.widget.textbox + }, + fill = true, + borders = 10, + border_image = image_path, + slice = i, + widget = wibox.container.border + } + + --DOC_HIDE_START + l:add(wibox.widget { + { + markup = "`slice` = "..(i and "true" or "false").."", + widget = wibox.widget.textbox, + }, + w, + layout = wibox.layout.fixed.vertical, + }) +end + +parent:add(l) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/border/stylesheet1.lua b/tests/examples/wibox/container/border/stylesheet1.lua new file mode 100644 index 000000000..c1e792a00 --- /dev/null +++ b/tests/examples/wibox/container/border/stylesheet1.lua @@ -0,0 +1,51 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +--luacheck: push no max line length + +--DOC_HIDE_END + +local image_path = ''.. + ''.. + ' '.. + ' '.. + ' '.. + ' '.. + ' '.. + ' ' .. + ' '.. + ' '.. + ' '.. + '' + +--DOC_NEWLINE + +local style = "".. + "#first {stop-color: magenta;}" .. + "#second {stop-color: cyan;}" .. + "#third {stop-color: yellow;}" + +--DOC_NEWLINE + +local w = wibox.widget { + { + text = "Center widget", + valign = "center", + align = "center", + widget = wibox.widget.textbox + }, + borders = 50, + border_image_stylesheet = style, + border_image = image_path, + honor_borders = false, + forced_width = 100, --DOC_HIDE + forced_height = 100, --DOC_HIDE + widget = wibox.container.border +} + +--DOC_HIDE_START + +--luacheck: pop + +parent:add(w) diff --git a/tests/examples/wibox/container/border/titlebar1.lua b/tests/examples/wibox/container/border/titlebar1.lua new file mode 100644 index 000000000..c50e7bc90 --- /dev/null +++ b/tests/examples/wibox/container/border/titlebar1.lua @@ -0,0 +1,172 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE +local parent = ... +local wibox = require("wibox") +local gears = { shape = require("gears.shape")} +local beautiful = require( "beautiful" ) + +-- luacheck: push no max line length +local bg = [[ + + + + + + + + + + + + + + + + + + +]] + +local btn = [[ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]] + +--luacheck: pop + +local function generic_widget(text, margins) + return wibox.widget { + { + { + { + id = "text", + align = "center", + valign = "center", + text = text, + widget = wibox.widget.textbox + }, + margins = 10, + widget = wibox.container.margin, + }, + border_width = 3, + border_color = beautiful.border_color, + bg = beautiful.bg_normal, + widget = wibox.container.background + }, + margins = margins or 5, + widget = wibox.container.margin, + } +end + +--DOC_HIDE_END + + local w = wibox.widget { + { + { + text = "Content", + align = "center", + valign = "center", + widget = wibox.widget.textbox + }, + border_widgets = { + top = { + { + { + { + stylesheet = "#bg1 {stop-color:#ca2b2b;} #bg2 {stop-color:#f8b9b9;}", + image = btn, + widget = wibox.widget.imagebox + }, + { + stylesheet = "#bg1 {stop-color:#ec9527;} #bg2 {stop-color:#ffff9c;}", + image = btn, + widget = wibox.widget.imagebox + }, + { + stylesheet = "#bg1 {stop-color:#75b525;} #bg2 {stop-color:#e0fda9;}", + image = btn, + widget = wibox.widget.imagebox + }, + spacing = 3, + layout = wibox.layout.fixed.horizontal + }, + { + align = "center", + text = "Shameless macOS ripoff", + widget = wibox.widget.textbox + }, + layout = wibox.layout.align.horizontal + }, + paddings = 6, + borders = 14, + border_image = bg, + honor_borders = false, + fill = true, + forced_height = 28, --DOC_HIDE + widget = wibox.container.border + }, + right = generic_widget(""), + bottom_right = generic_widget(""), + bottom = generic_widget(""), + bottom_left = generic_widget(""), + left = generic_widget(""), + }, + borders = { + top = 28, + left = 22, + right = 22, + bottom = 22, + }, + border_merging = { + top = true + }, + forced_width = 300, --DOC_HIDE + forced_height = 100, --DOC_HIDE + widget = wibox.container.border + }, + bg = "#d9d9d9", + shape = gears.shape.rounded_rect, + widget = wibox.container.background + } + +--DOC_HIDE_START +parent:add(w) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/container/defaults/border.lua b/tests/examples/wibox/container/defaults/border.lua new file mode 100644 index 000000000..40c337612 --- /dev/null +++ b/tests/examples/wibox/container/defaults/border.lua @@ -0,0 +1,47 @@ +--DOC_HIDE_ALL +--DOC_GEN_IMAGE +local wibox = require("wibox") + +-- luacheck: push no max string line length +local data = [[ + + + + + + + + + + + + + + + +]] +--luacheck: pop + +return { + text = "Before", + align = "center", + valign = "center", + widget = wibox.widget.textbox, +}, +{ + { + { + text = "After", + align = "center", + valign = "center", + widget = wibox.widget.textbox, + }, + border_image = data, + slice = true, + fill = true, + borders = 10, + widget = wibox.container.border + }, + margins = 5, + layout = wibox.container.margin +}