From c355ce7d96b58bb49a53c6883678ef9a421bcbf7 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 26 Apr 2021 00:17:07 -0700 Subject: [PATCH] tests: Test the imagebox --- .../wibox/widget/imagebox/clip_shape.lua | 62 ++++++++++++++ .../examples/wibox/widget/imagebox/halign.lua | 58 +++++++++++++ .../widget/imagebox/horizontal_fit_policy.lua | 81 +++++++++++++++++++ .../widget/imagebox/max_scaling_factor.lua | 53 ++++++++++++ .../examples/wibox/widget/imagebox/resize.lua | 19 +++-- .../wibox/widget/imagebox/scaling_quality.lua | 77 ++++++++++++++++++ .../examples/wibox/widget/imagebox/valign.lua | 58 +++++++++++++ .../widget/imagebox/vertical_fit_policy.lua | 81 +++++++++++++++++++ 8 files changed, 483 insertions(+), 6 deletions(-) create mode 100644 tests/examples/wibox/widget/imagebox/clip_shape.lua create mode 100644 tests/examples/wibox/widget/imagebox/halign.lua create mode 100644 tests/examples/wibox/widget/imagebox/horizontal_fit_policy.lua create mode 100644 tests/examples/wibox/widget/imagebox/max_scaling_factor.lua create mode 100644 tests/examples/wibox/widget/imagebox/scaling_quality.lua create mode 100644 tests/examples/wibox/widget/imagebox/valign.lua create mode 100644 tests/examples/wibox/widget/imagebox/vertical_fit_policy.lua diff --git a/tests/examples/wibox/widget/imagebox/clip_shape.lua b/tests/examples/wibox/widget/imagebox/clip_shape.lua new file mode 100644 index 00000000..2070d4f9 --- /dev/null +++ b/tests/examples/wibox/widget/imagebox/clip_shape.lua @@ -0,0 +1,62 @@ +--DOC_GEN_IMAGE --DOC_HIDE +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local gears = {shape=require("gears.shape")} --DOC_HIDE + +local l = wibox.layout { --DOC_HIDE + forced_width = 380, --DOC_HIDE + spacing = 5, --DOC_HIDE + layout = wibox.layout.flex.vertical --DOC_HIDE +} --DOC_HIDE + +local names = {"circle", "squircle", "rounded_rect"} --DOC_HIDE + +for _, resize in ipairs {true, false} do + local row = wibox.layout { --DOC_HIDE + spacing = 5, --DOC_HIDE + layout = wibox.layout.fixed.horizontal --DOC_HIDE + } --DOC_HIDE + + row:add(wibox.widget { --DOC_HIDE + markup = "resize = "..(resize and "true" or "false").."", --DOC_HIDE + forced_width = 80, --DOC_HIDE + widget = wibox.widget.textbox --DOC_HIDE + }) --DOC_HIDE + + for idx, shape in ipairs {gears.shape.circle, gears.shape.squircle, gears.shape.rounded_rect} do + local w = wibox.widget { + { + { + image = beautiful.awesome_icon, + forced_height = 32, + forced_width = 32, + clip_shape = shape, + resize = resize, + widget = wibox.widget.imagebox + }, + widget = wibox.container.place + }, + forced_height = 64, --DOC_HIDE + forced_width = 64, --DOC_HIDE + widget = wibox.container.background + } + + + row:add(wibox.widget {--DOC_HIDE + {--DOC_HIDE + markup = "`shape` = "..names[idx].."",--DOC_HIDE + widget = wibox.widget.textbox,--DOC_HIDE + },--DOC_HIDE + w,--DOC_HIDE + layout = wibox.layout.fixed.vertical,--DOC_HIDE + }) --DOC_HIDE + end + + l:add(row) --DOC_HIDE +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/widget/imagebox/halign.lua b/tests/examples/wibox/widget/imagebox/halign.lua new file mode 100644 index 00000000..0983a97f --- /dev/null +++ b/tests/examples/wibox/widget/imagebox/halign.lua @@ -0,0 +1,58 @@ +--DOC_GEN_IMAGE --DOC_HIDE +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE + +local l = wibox.layout { --DOC_HIDE + forced_width = 360, --DOC_HIDE + spacing = 5, --DOC_HIDE + layout = wibox.layout.flex.vertical --DOC_HIDE +} --DOC_HIDE + +for _, resize in ipairs {true, false} do + local row = wibox.layout { --DOC_HIDE + spacing = 5, --DOC_HIDE + layout = wibox.layout.fixed.horizontal --DOC_HIDE + } --DOC_HIDE + + row:add(wibox.widget { --DOC_HIDE + markup = "resize = "..(resize and "true" or "false").."", --DOC_HIDE + forced_width = 80, --DOC_HIDE + widget = wibox.widget.textbox --DOC_HIDE + }) --DOC_HIDE + + for _, halign in ipairs {"left", "center", "right"} do + local w = wibox.widget { + { + { + image = beautiful.awesome_icon, + forced_height = 32, + forced_width = 32, + halign = halign, + resize = resize, + widget = wibox.widget.imagebox + }, + bg = beautiful.bg_normal, + forced_height = 32, --DOC_HIDE + forced_width = 80, --DOC_HIDE + widget = wibox.container.background + }, + widget = wibox.container.place + } + + row:add(wibox.widget {--DOC_HIDE + {--DOC_HIDE + markup = "`valign` = "..halign.."",--DOC_HIDE + widget = wibox.widget.textbox,--DOC_HIDE + },--DOC_HIDE + w,--DOC_HIDE + layout = wibox.layout.fixed.vertical,--DOC_HIDE + }) --DOC_HIDE + end + + l:add(row) --DOC_HIDE +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/widget/imagebox/horizontal_fit_policy.lua b/tests/examples/wibox/widget/imagebox/horizontal_fit_policy.lua new file mode 100644 index 00000000..6bfcbc32 --- /dev/null +++ b/tests/examples/wibox/widget/imagebox/horizontal_fit_policy.lua @@ -0,0 +1,81 @@ +--DOC_HIDE_ALL +--DOC_GEN_IMAGE +local parent = ... +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) +local lgi = require("lgi") +local cairo = lgi.cairo + +-- A simple Awesome logo +local function demo() + local img = cairo.ImageSurface.create(cairo.Format.ARGB32, 22, 32) + local cr = cairo.Context(img) + + -- Awesome default #555555 + cr:set_source_rgb(0,0,1) + cr:paint() + + cr:set_source_rgb(1,0,0) + + cr:rectangle(0, 15, 22, 2) + cr:rectangle(10, 0, 2, 32) + cr:fill() + + cr:set_source_rgb(0,1,0) + + cr:arc(11, 16, 8, 0, 2*math.pi) + cr:fill() + + return img +end + + +local function cell_centered_widget(widget) + return wibox.widget { + widget, + valign = 'center', + halign = 'center', + content_fill_vertical = false, + content_fill_horizontal = false, + widget = wibox.container.place + } +end + +local function build_ib(size, policy) + return cell_centered_widget(wibox.widget { + { + horizontal_fit_policy = policy, + forced_height = size, + forced_width = size, + image = demo(), + widget = wibox.widget.imagebox + }, + forced_width = size + 2, + forced_height = size + 2, + color = beautiful.border_color, + margins = 1, + widget = wibox.container.margin + }) +end + + +local l = wibox.widget { + homogeneous = false, + spacing = 5, + layout = wibox.layout.grid, +} +parent:add(l) + +l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "auto"'), 1, 1) +l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "none"'), 2, 1) +l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "fit"'), 3, 1) +l:add_widget_at(wibox.widget.textbox('imagebox size'), 4, 1) + +for i,size in ipairs({16, 32, 64}) do + l:add_widget_at(build_ib(size, "auto"), 1, i + 1) + l:add_widget_at(build_ib(size, "none"), 2, i + 1) + l:add_widget_at(build_ib(size, "fit" ), 3, i + 1) + l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 4, i + 1) +end + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/imagebox/max_scaling_factor.lua b/tests/examples/wibox/widget/imagebox/max_scaling_factor.lua new file mode 100644 index 00000000..db0b0abe --- /dev/null +++ b/tests/examples/wibox/widget/imagebox/max_scaling_factor.lua @@ -0,0 +1,53 @@ +--DOC_HIDE_ALL +--DOC_GEN_IMAGE +local parent = ... +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) + +local function cell_centered_widget(widget) + return wibox.widget { + widget, + valign = 'center', + halign = 'center', + content_fill_vertical = false, + content_fill_horizontal = false, + widget = wibox.container.place + } +end + +local function build_ib(size, factor) + return cell_centered_widget(wibox.widget { + { + forced_height = size, + forced_width = size, + max_scaling_factor = factor, + image = beautiful.awesome_icon, + widget = wibox.widget.imagebox + }, + forced_width = size + 2, + forced_height = size + 2, + color = beautiful.border_color, + margins = 1, + widget = wibox.container.margin + }) +end + + +local l = wibox.widget { + homogeneous = false, + spacing = 5, + layout = wibox.layout.grid, +} +parent:add(l) + +l:add_widget_at(cell_centered_widget(wibox.widget.textbox('max_scaling_factor = nil')), 1, 1) +l:add_widget_at(cell_centered_widget(wibox.widget.textbox('max_scaling_factor = 2')), 2, 1) +l:add_widget_at(cell_centered_widget(wibox.widget.textbox('imagebox size')), 3, 1) + +for i,size in ipairs({16, 32, 64}) do + l:add_widget_at(build_ib(size, nil), 1, i + 1) + l:add_widget_at(build_ib(size, 2), 2, i + 1) + l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 3, i + 1) +end + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/imagebox/resize.lua b/tests/examples/wibox/widget/imagebox/resize.lua index 2b4124ef..c4030191 100644 --- a/tests/examples/wibox/widget/imagebox/resize.lua +++ b/tests/examples/wibox/widget/imagebox/resize.lua @@ -16,12 +16,19 @@ local function cell_centered_widget(widget) end local function build_ib(size, resize) - return cell_centered_widget({ - resize = resize, - forced_width = size, - forced_height = size, - image = beautiful.awesome_icon, - widget = wibox.widget.imagebox + return cell_centered_widget(wibox.widget { + { + resize = resize, + forced_height = size, + forced_width = size, + image = beautiful.awesome_icon, + widget = wibox.widget.imagebox + }, + forced_width = size + 2, + forced_height = size + 2, + color = beautiful.border_color, + margins = 1, + widget = wibox.container.margin }) end diff --git a/tests/examples/wibox/widget/imagebox/scaling_quality.lua b/tests/examples/wibox/widget/imagebox/scaling_quality.lua new file mode 100644 index 00000000..be588ced --- /dev/null +++ b/tests/examples/wibox/widget/imagebox/scaling_quality.lua @@ -0,0 +1,77 @@ +--DOC_GEN_IMAGE --DOC_HIDE +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local lgi = require("lgi")--DOC_HIDE +local cairo = lgi.cairo --DOC_HIDE + +--DOC_HIDE A simple Awesome logo +local function demo()--DOC_HIDE + local img = cairo.ImageSurface.create(cairo.Format.ARGB32, 32, 22)--DOC_HIDE + local cr = cairo.Context(img)--DOC_HIDE + cr:set_antialias(cairo.Antialias.NONE) --DOC_HIDE + + -- Awesome default #555555--DOC_HIDE + cr:set_source_rgb(0,0,1)--DOC_HIDE + cr:paint() --DOC_HIDE + + cr:set_source_rgb(1,0,0)--DOC_HIDE + + cr:rectangle(0, 10, 32, 2)--DOC_HIDE + cr:rectangle(15, 0, 2, 22)--DOC_HIDE + cr:fill()--DOC_HIDE + + cr:set_source_rgb(0,1,0)--DOC_HIDE + + cr:arc(16, 11, 8, 0, 2*math.pi)--DOC_HIDE + cr:fill()--DOC_HIDE + + return img--DOC_HIDE +end--DOC_HIDE + +local img = demo () --DOC_HIDE + +local l = wibox.layout { --DOC_HIDE + -- forced_width = 720, --DOC_HIDE + spacing = 5, --DOC_HIDE + layout = wibox.layout.flex.vertical --DOC_HIDE +} --DOC_HIDE + + for _, quality in ipairs {"fast", "good", "best", "nearest", "bilinear"} do + local w = wibox.widget { + { + { + image = img, + forced_height = 64, + forced_width = 96, + scaling_quality = quality, + widget = wibox.widget.imagebox + }, + widget = wibox.container.place + }, + -- forced_height = 96, --DOC_HIDE + -- forced_width = 96, --DOC_HIDE + widget = wibox.container.background + } + + --DOC_HIDE SVG doesn't support those mode, so rasterize everything. + local raster = wibox.widget.draw_to_image_surface(w, 96, 64) --DOC_HIDE + + l:add(wibox.widget {--DOC_HIDE + {--DOC_HIDE + markup = "`scaling_quality` = "..quality.."",--DOC_HIDE + widget = wibox.widget.textbox,--DOC_HIDE + },--DOC_HIDE + { --DOC_HIDE + image = raster, --DOC_HIDE + forced_height = 64, --DOC_HIDE + forced_width = 96, --DOC_HIDE + widget = wibox.widget.imagebox --DOC_HIDE + },--DOC_HIDE + layout = wibox.layout.fixed.vertical,--DOC_HIDE + }) --DOC_HIDE + 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/widget/imagebox/valign.lua b/tests/examples/wibox/widget/imagebox/valign.lua new file mode 100644 index 00000000..28779ef5 --- /dev/null +++ b/tests/examples/wibox/widget/imagebox/valign.lua @@ -0,0 +1,58 @@ +--DOC_GEN_IMAGE --DOC_HIDE +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE + +local l = wibox.layout { --DOC_HIDE + forced_width = 340, --DOC_HIDE + spacing = 5, --DOC_HIDE + layout = wibox.layout.flex.vertical --DOC_HIDE +} --DOC_HIDE + +for _, resize in ipairs {true, false} do + local row = wibox.layout { --DOC_HIDE + spacing = 5, --DOC_HIDE + layout = wibox.layout.fixed.horizontal --DOC_HIDE + } --DOC_HIDE + + row:add(wibox.widget { --DOC_HIDE + markup = "resize = "..(resize and "true" or "false").."", --DOC_HIDE + forced_width = 80, --DOC_HIDE + widget = wibox.widget.textbox --DOC_HIDE + }) --DOC_HIDE + + for _, valign in ipairs {"top", "center", "bottom"} do + local w = wibox.widget { + { + { + image = beautiful.awesome_icon, + forced_height = 32, + forced_width = 32, + valign = valign, + resize = resize, + widget = wibox.widget.imagebox + }, + bg = beautiful.bg_normal, + forced_height = 80, --DOC_HIDE + forced_width = 32, --DOC_HIDE + widget = wibox.container.background + }, + widget = wibox.container.place + } + + row:add(wibox.widget {--DOC_HIDE + {--DOC_HIDE + markup = "`valign` = "..valign.."",--DOC_HIDE + widget = wibox.widget.textbox,--DOC_HIDE + },--DOC_HIDE + w,--DOC_HIDE + layout = wibox.layout.fixed.vertical,--DOC_HIDE + }) --DOC_HIDE + end + + l:add(row) --DOC_HIDE +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/widget/imagebox/vertical_fit_policy.lua b/tests/examples/wibox/widget/imagebox/vertical_fit_policy.lua new file mode 100644 index 00000000..24744f96 --- /dev/null +++ b/tests/examples/wibox/widget/imagebox/vertical_fit_policy.lua @@ -0,0 +1,81 @@ +--DOC_HIDE_ALL +--DOC_GEN_IMAGE +local parent = ... +local wibox = require( "wibox" ) +local beautiful = require( "beautiful" ) +local lgi = require("lgi") +local cairo = lgi.cairo + +-- A simple Awesome logo +local function demo() + local img = cairo.ImageSurface.create(cairo.Format.ARGB32, 32, 22) + local cr = cairo.Context(img) + + -- Awesome default #555555 + cr:set_source_rgb(0,0,1) + cr:paint() + + cr:set_source_rgb(1,0,0) + + cr:rectangle(0, 10, 32, 2) + cr:rectangle(15, 0, 2, 22) + cr:fill() + + cr:set_source_rgb(0,1,0) + + cr:arc(16, 11, 8, 0, 2*math.pi) + cr:fill() + + return img +end + + +local function cell_centered_widget(widget) + return wibox.widget { + widget, + valign = 'center', + halign = 'center', + content_fill_vertical = false, + content_fill_horizontal = false, + widget = wibox.container.place + } +end + +local function build_ib(size, policy) + return cell_centered_widget(wibox.widget { + { + vertical_fit_policy = policy, + forced_height = size, + forced_width = size, + image = demo(), + widget = wibox.widget.imagebox + }, + forced_width = size + 2, + forced_height = size + 2, + color = beautiful.border_color, + margins = 1, + widget = wibox.container.margin + }) +end + + +local l = wibox.widget { + homogeneous = false, + spacing = 5, + layout = wibox.layout.grid, +} +parent:add(l) + +l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "auto"'), 1, 1) +l:add_widget_at(wibox.widget.textbox('versical_fit_policy = "none"'), 2, 1) +l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "fit"'), 3, 1) +l:add_widget_at(wibox.widget.textbox('imagebox size'), 4, 1) + +for i,size in ipairs({16, 32, 64}) do + l:add_widget_at(build_ib(size, "auto"), 1, i + 1) + l:add_widget_at(build_ib(size, "none"), 2, i + 1) + l:add_widget_at(build_ib(size, "fit" ), 3, i + 1) + l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 4, i + 1) +end + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80