Merge pull request #3559 from Elv13/border_container

Add a new border container
This commit is contained in:
Emmanuel Lepage Vallée 2023-12-31 15:36:02 -08:00 committed by GitHub
commit 1f7ac8f9c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 3565 additions and 45 deletions

View File

@ -23,6 +23,141 @@ local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility
local background = { mt = {} }
-- If a background is resized with the mouse, it might create a large
-- number of scaled texture. After the cache grows beyond this number, it
-- is purged.
local MAX_CACHE_SIZE = 10
local global_scaled_pattern_cache = setmetatable({}, {__mode = "k"})
local function clone_stops(input, output)
local err, count = input:get_color_stop_count()
if err ~= "SUCCESS" then return end
for idx = 0, count-1 do
local _, off, r, g, b, a = input:get_color_stop_rgba(idx)
output:add_color_stop_rgba(off, r, g, b, a)
end
end
local function stretch_lineal_gradient(input, width, height)
-- First, get the original values.
local err, x0, y0, x1, y1 = input:get_linear_points()
if err ~= "SUCCESS" then
return input
end
local new_x0, new_y0 = x1 == 0 and 0 or ((x0/x1)*width), y1 == 0 and 0 or ((y0/y1)*height)
local output = cairo.Pattern.create_linear(new_x0, new_y0, width, height)
clone_stops(input, output)
return output
end
local function stretch_radial_gradient(input, width, height)
local err, cx0, cy0, radius0, cx1, cy1, radius1 = input:get_radial_circles()
if err ~= "SUCCESS" then
return input
end
-- Create a box for the original gradient, starting at 0x0.
local x1 = math.max(cx0 + radius0, cx1 + radius1)
local y1 = math.max(cy0 + radius0, cy1 + radius1)
-- Now scale this box to `width`x`height`
local x_factor, y_factor = width/x1, height/y1
local rad_factor = math.sqrt(width^2 + height^2) / math.sqrt(x1^1+y1^2)
local output = cairo.Pattern.create_radial(
cx0*x_factor, cy0*y_factor, radius0*rad_factor, cx1*x_factor, cx1*y_factor, radius1*rad_factor
)
clone_stops(input, output)
return output
end
local function get_pattern_size(pat)
local t = pat.type
if t == "LINEAR" then
local _, _, _, x1, y1 = pat:get_linear_points()
return x1, y1
elseif t == "RADIAL" then
local _, _, _, cx1, cy1, _ = pat:get_radial_circles()
return cx1, cy1
end
end
local function stretch_common(self, width, height)
if (not self._private.background) and (not self._private.bgimage) then return end
if not (self._private.stretch_horizontally or self._private.stretch_vertically) then
return self._private.background, self._private.bgimage
end
local old = self._private.background
local size_w, size_h = get_pattern_size(old)
-- Note that technically, we could handle cairo.SurfacePattern and
-- cairo.RasterSourcePattern. However, this might create some surprising
-- results. For example switching to a different theme which uses tiled
-- pattern would change the "meaning" of this property.
if not size_w then return end
-- Don't try to resize zero-sized patterns. They are used for
-- generic liear gradient means "there is no gradient in this axis"
if self._private.stretch_vertically and size_h ~= 0 then
size_h = height
end
if self._private.stretch_horizontally and size_w ~= 0 then
size_w = width
end
local hash = size_w.."x"..size_h
if self._private.scale_cache[hash] then
return self._private.scale_cache[hash]
end
if global_scaled_pattern_cache[old] and global_scaled_pattern_cache[old][hash] then
-- Don't bother clearing the cache, if the pattern is already cached
-- elsewhere, it will remain in memory anyway.
self._private.scale_cache[hash] = global_scaled_pattern_cache[old][hash]
self._private.scale_cache_size = self._private.scale_cache_size + 1
end
local t, new = old.type
if t == "LINEAR" then
new = stretch_lineal_gradient(old, size_w, size_h)
elseif t == "RADIAL" then
new = stretch_radial_gradient(old, size_w, size_h)
end
global_scaled_pattern_cache[old] = global_scaled_pattern_cache[old] or setmetatable({}, {__mode = "v"})
global_scaled_pattern_cache[old][hash] = new
-- Prevent the memory leak.
if self._private.scale_cache_size > MAX_CACHE_SIZE then
self._private.scale_cache_size = 0
self._private.scale_cache = {}
end
self._private.scale_cache[hash] = new
self._private.scale_cache_size = self._private.scale_cache_size + 1
return new, self._private.bgimage
end
-- The Cairo SVG backend doesn't support surface as patterns correctly.
-- The result is both glitchy and blocky. It is also impossible to introspect.
-- Calling this function replace the normal code path is a "less correct", but
@ -39,9 +174,11 @@ function background._use_fallback_algorithm()
shape(cr, width, height)
if self._private.background then
local bg = stretch_common(self, width, height)
if bg then
cr:save() --Save to avoid messing with the original source
cr:set_source(self._private.background)
cr:set_source(bg)
cr:fill_preserve()
cr:restore()
end
@ -115,15 +252,18 @@ function background:before_draw_children(context, cr, width, height)
cr:push_group_with_content(cairo.Content.COLOR_ALPHA)
end
local bg, bgimage = stretch_common(self, width, height)
-- Draw the background
if self._private.background then
if bg then
cr:save()
cr:set_source(self._private.background)
cr:set_source(bg)
cr:rectangle(0, 0, width, height)
cr:fill()
cr:restore()
end
if self._private.bgimage then
if bgimage then
cr:save()
if type(self._private.bgimage) == "function" then
self._private.bgimage(context, cr, width, height,unpack(self._private.bgimage_args))
@ -253,6 +393,42 @@ function background:set_children(children)
self:set_widget(children[1])
end
--- Stretch the background gradient horizontally.
--
-- This only works for linear or radial gradients. It does nothing
-- for solid colors, `bgimage` or raster patterns.
--
--@DOC_wibox_container_background_stretch_horizontally_EXAMPLE@
--
-- @property stretch_horizontally
-- @tparam[opt=false] boolean stretch_horizontally
-- @propemits true false
-- @see stretch_vertically
-- @see bg
-- @see gears.color
--- Stretch the background gradient vertically.
--
-- This only works for linear or radial gradients. It does nothing
-- for solid colors, `bgimage` or raster patterns.
--
--@DOC_wibox_container_background_stretch_vertically_EXAMPLE@
--
-- @property stretch_vertically
-- @tparam[opt=false] boolean stretch_vertically
-- @propemits true false
-- @see stretch_horizontally
-- @see bg
-- @see gears.color
for _, orientation in ipairs {"horizontally", "vertically"} do
background["set_stretch_"..orientation] = function(self, value)
self._private["stretch_"..orientation] = value
self:emit_signal("widget::redraw_needed")
self:emit_signal("property::stretch_"..orientation, value)
end
end
--- The background color/pattern/gradient to use.
--
--@DOC_wibox_container_background_bg_EXAMPLE@
@ -352,7 +528,8 @@ end
--
-- If the shape is set, the border will also be shaped.
--
-- See `wibox.container.background.shape` for an usage example.
--@DOC_wibox_container_background_border_width_EXAMPLE@
--
-- @property border_width
-- @tparam[opt=0] number border_width
-- @propertyunit pixel
@ -400,6 +577,8 @@ end
--- Set the color for the border.
--
--@DOC_wibox_container_background_border_color_EXAMPLE@
--
-- See `wibox.container.background.shape` for an usage example.
-- @property border_color
-- @tparam color border_color
@ -450,10 +629,13 @@ end
--- How the border width affects the contained widget.
--
--@DOC_wibox_container_background_border_strategy_EXAMPLE@
--
-- @property border_strategy
-- @tparam[opt="none"] string border_strategy
-- @propertyvalue "none" Just apply the border, do not affect the content size (default).
-- @propertyvalue "inner" Squeeze the size of the content by the border width.
-- @propemits true false
function background:set_border_strategy(value)
self._private.border_strategy = value
@ -463,12 +645,24 @@ end
--- The background image to use.
--
-- This property is deprecated. The `wibox.container.border` provides a much
-- more fine-grained support for background images. It is now out of the
-- `wibox.container.background` scope. `wibox.layout.stack` can also be used
-- to overlay a widget on top of a `wibox.widget.imagebox`. This solution
-- exposes all availible imagebox properties. Finally, if you wish to use the
-- `function` callback support, implement the `before_draw_children` method
-- on any widget. This gives you the same level of control without all the
-- `bgimage` corner cases.
--
-- If `image` is a function, it will be called with `(context, cr, width, height)`
-- as arguments. Any other arguments passed to this method will be appended.
--
-- @property bgimage
-- @tparam[opt=nil] image|nil bgimage
-- @deprecatedproperty bgimage
-- @tparam string|surface|function bgimage A background image or a function.
-- @see gears.surface
-- @see wibox.container.border
-- @see wibox.widget.imagebox
-- @see wibox.layout.stack
function background:set_bgimage(image, ...)
self._private.bgimage = type(image) == "function" and image or surface.load(image)
@ -498,6 +692,8 @@ local function new(widget, bg, shape)
gtable.crush(ret, background, true)
ret._private.shape = shape
ret._private.scale_cache = {}
ret._private.scale_cache_size = 0
ret:set_widget(widget)
ret:set_bg(bg)

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ return setmetatable({
arcchart = require("wibox.container.arcchart");
place = require("wibox.container.place");
tile = require("wibox.container.tile");
border = require("wibox.container.border");
}, {__call = function(_, args) return base.make_widget_declarative(args) end})
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -31,12 +31,23 @@ local base = require("wibox.widget.base")
local surface = require("gears.surface")
local gtable = require("gears.table")
local gdebug = require("gears.debug")
local gfs = require("gears.filesystem")
local setmetatable = setmetatable
local type = type
local math = math
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
-- Placeholder table to represent an emty stylesheet.
-- It has to be defined here to avoid being GCed
local empty_stylesheet = {}
local policies_to_extents = {
["pad"] = cairo.Extend.PAD,
["repeat"] = cairo.Extend.REPEAT,
["reflect"] = cairo.Extend.REFLECT,
}
-- Safe load for optional Rsvg module
local Rsvg = nil
do
@ -49,18 +60,25 @@ end
local imagebox = { mt = {} }
local rsvg_handle_cache = setmetatable({}, { __mode = 'k' })
local stylesheet_cache = {}
---Load rsvg handle form image file
--Load rsvg handle form image file
-- @tparam string file Path to svg file.
-- @return Rsvg handle
-- @treturn table A table where cached data can be stored.
local function load_rsvg_handle(file)
function imagebox._load_rsvg_handle(file, style)
-- Make sure this is called in the right order.
assert((not style) or (style and stylesheet_cache[style]))
local style_ref = style and stylesheet_cache[style] or empty_stylesheet
if not Rsvg then return end
local cache = (rsvg_handle_cache[file] or {})["handle"]
local bucket = rsvg_handle_cache[file] or {}
local cache = (bucket[style_ref] or {})["handle"]
if cache then
return cache, rsvg_handle_cache[file]
return cache, bucket[style_ref]
end
local handle, err
@ -72,9 +90,10 @@ local function load_rsvg_handle(file)
end
if not err then
rsvg_handle_cache[file] = rsvg_handle_cache[file] or {}
rsvg_handle_cache[file]["handle"] = handle
return handle, rsvg_handle_cache[file]
rsvg_handle_cache[file] = rsvg_handle_cache[file] or setmetatable({}, {__mode = "k"})
rsvg_handle_cache[file][style_ref] = rsvg_handle_cache[file][style_ref] or {}
rsvg_handle_cache[file][style_ref]["handle"] = handle
return handle, rsvg_handle_cache[file][style_ref]
end
end
@ -111,7 +130,7 @@ end
---@treturn boolean True if image was successfully applied
local function load_and_apply(ib, file, image_loader, image_setter)
local image_applied
local object, cache = image_loader(file)
local object, cache = image_loader(file, ib._private.stylesheet_og)
if object then
image_applied = image_setter(ib, object, cache)
@ -119,6 +138,38 @@ local function load_and_apply(ib, file, image_loader, image_setter)
return image_applied
end
--- Support both CSS data and filepath for the stylsheet.
function imagebox._get_stylesheet(self, content_or_path)
if not content_or_path then return nil end
-- Always set the entry because the image cache uses it.
stylesheet_cache[content_or_path] = stylesheet_cache[content_or_path]
or setmetatable({}, {__mode = "v"})
if gfs.file_readable(content_or_path) then
local ret
local _, obj = next(stylesheet_cache[content_or_path])
if obj then
ret = obj._private.stylesheet
table.insert(stylesheet_cache[content_or_path], self)
else
local f = io.open(content_or_path, 'r')
if not f then return nil end
ret = f:read("*all")
f:close()
table.insert(stylesheet_cache[content_or_path], self)
end
return ret
else
return content_or_path
end
end
---Update the cached size depending on the stylesheet and dpi.
--
-- It's necessary because a single RSVG handle can be used by
@ -182,6 +233,11 @@ function imagebox:draw(ctx, cr, width, height)
local w, h = self._private.default.width, self._private.default.height
local policy = {
w = self._private.horizontal_fit_policy or "auto",
h = self._private.vertical_fit_policy or "auto"
}
if self._private.resize then
-- That's for the "fit" policy.
local aspects = {
@ -189,17 +245,12 @@ function imagebox:draw(ctx, cr, width, height)
h = height / h
}
local policy = {
w = self._private.horizontal_fit_policy or "auto",
h = self._private.vertical_fit_policy or "auto"
}
for _, aspect in ipairs {"w", "h"} do
if self._private.upscale == false and (w < width and h < height) then
aspects[aspect] = 1
elseif self._private.downscale == false and (w >= width and h >= height) then
aspects[aspect] = 1
elseif policy[aspect] == "none" then
elseif policy[aspect] == "none" or policies_to_extents[policy[aspect]] then
aspects[aspect] = 1
elseif policy[aspect] == "auto" then
aspects[aspect] = math.min(width / w, height / h)
@ -258,7 +309,18 @@ function imagebox:draw(ctx, cr, width, height)
if self._private.handle then
self._private.handle:render_cairo(cr)
else
cr:set_source_surface(self._private.image, 0, 0)
-- Yes, it is possible that the vertical or horizontal policies both
-- have extends, but Cairo doesn't support this. So be it.
local pol = policies_to_extents[policy.w]
pol = pol or policies_to_extents[policy.h]
if pol then
local pat = cairo.Pattern.create_for_surface(self._private.image)
pat:set_extend(pol)
cr:set_source(pat)
else
cr:set_source_surface(self._private.image, 0, 0)
end
local filter = self._private.scaling_quality
@ -300,6 +362,32 @@ end
-- @tparam[opt=nil] image|nil image
-- @propemits false false
--- Return the source image width.
--
-- For SVG images, this may be affected by the DPI and might not
-- reflect the size the images will be rendered at. For PNG or
-- JPG images, this will return the file resolution.
--
-- @property source_width
-- @tparam number source_width
-- @propertydefault This depends on the source image.
-- @negativeallowed false
-- @see image
-- @see source_height
--- Return the source image height.
--
-- For SVG images, this may be affected by the DPI and might not
-- reflect the size the images will be rendered at. For PNG or
-- JPG images, this will return the file resolution.
--
-- @property source_height
-- @tparam number source_height
-- @propertydefault This depends on the source image.
-- @negativeallowed false
-- @see image
-- @see source_width
--- Set the `imagebox` image.
--
-- The image can be a file, a cairo image surface, or an rsvg handle object
@ -326,7 +414,7 @@ function imagebox:set_image(image)
if type(image) == "string" then
-- try to load rsvg handle from file
setup_succeed = load_and_apply(self, image, load_rsvg_handle, set_handle)
setup_succeed = load_and_apply(self, image, imagebox._load_rsvg_handle, set_handle)
if not setup_succeed then
-- rsvg handle failed, try to load cairo surface with pixbuf
@ -355,6 +443,14 @@ function imagebox:set_image(image)
return true
end
for _, dim in ipairs { "width", "height" } do
imagebox["get_source_"..dim] = function(self)
if not self._private.default then return nil end
return self._private.default[dim]
end
end
--- Set a clip shape for this imagebox.
--
-- A clip shape defines an area and dimension to which the content should be
@ -426,8 +522,7 @@ end
-- If the image is an SVG (vector graphics), this property allows to set
-- a CSS stylesheet. It can be used to set colors and much more.
--
-- Note that this property is a string, not a path. If the stylesheet is
-- stored on disk, read the content first.
-- The value can be either CSS data or a file path.
--
--@DOC_wibox_widget_imagebox_stylesheet_EXAMPLE@
--
@ -466,18 +561,47 @@ end
-- @propemits true false
-- @see dpi
for _, prop in ipairs {"stylesheet", "dpi", "auto_dpi"} do
for _, prop in ipairs {"dpi", "auto_dpi"} do
imagebox["set_" .. prop] = function(self, value)
local old = self._private[prop]
-- It will be set in :fit and :draw. The handle is shared
-- by multiple imagebox, so it cannot be set just once.
self._private[prop] = value
self:emit_signal("widget::redraw_needed")
self:emit_signal("widget::layout_changed")
self:emit_signal("property::" .. prop)
self:emit_signal("property::" .. prop, value, old)
end
end
function imagebox:set_stylesheet(value)
if value == self._private.stylesheet_og then return end
local old = self._private.stylesheet_og
if old and stylesheet_cache[old] then
for k, v in ipairs(stylesheet_cache[old]) do
if self == v then
table.remove(stylesheet_cache[old], k)
break
end
end
end
local content = imagebox._get_stylesheet(self, value)
self._private.stylesheet = content
self._private.stylesheet_og = value
-- Refresh the pixmap.
self.image = self._private.original_image
self:emit_signal("widget::redraw_needed")
self:emit_signal("widget::layout_changed")
self:emit_signal("property::stylesheet", value)
end
function imagebox:set_resize(allowed)
self._private.resize = allowed
@ -510,6 +634,9 @@ end
--- Set the horizontal fit policy.
--
-- Note that `repeat`, `reflect` and `pad` cannot be mixed across
-- the vertical and horizontal axis.
--
-- Here is the result for a 22x32 image:
--
-- @DOC_wibox_widget_imagebox_horizontal_fit_policy_EXAMPLE@
@ -519,12 +646,20 @@ end
-- @propertyvalue "auto" Honor the `resize` variable and preserve the aspect ratio.
-- @propertyvalue "none" Do not resize at all.
-- @propertyvalue "fit" Resize to the widget width.
-- @propertyvalue "repeat" Repeat the image side by side.
-- @propertyvalue "reflect" Like `repeat`, but alternate the reflection.
-- @propertyvalue "pad" Take the last column of pixels and repeat them.
-- @propemits true false
-- @see vertical_fit_policy
-- @see resize
--- Set the vertical fit policy.
--
-- Valid values are:
--
-- Note that `repeat`, `reflect` and `pad` cannot be mixed across
-- the vertical and horizontal axis.
--
-- Here is the result for a 32x22 image:
--
-- @DOC_wibox_widget_imagebox_vertical_fit_policy_EXAMPLE@
@ -534,6 +669,10 @@ end
-- @propertyvalue "auto" Honor the `resize` variable and preserve the aspect ratio.
-- @propertyvalue "none" Do not resize at all.
-- @propertyvalue "fit" Resize to the widget height.
-- @propertyvalue "fit" Resize to the widget width.
-- @propertyvalue "repeat" Repeat the image side by side.
-- @propertyvalue "reflect" Like `repeat`, but alternate the reflection.
-- @propertyvalue "pad" Take the last column of pixels and repeat them.
-- @propemits true false
-- @see horizontal_fit_policy
-- @see resize

View File

@ -3,15 +3,24 @@ local Pango = lgi.Pango
local cairo = lgi.cairo
-- A simple Awesome logo
local function logo()
local function logo(fg, bg)
local img = cairo.ImageSurface.create(cairo.Format.ARGB32, 22, 22)
local cr = cairo.Context(img)
-- Awesome default #555555
cr:set_source_rgb(0.21568627451, 0.21568627451, 0.21568627451)
if bg then
cr:set_source(bg)
else
cr:set_source_rgb(0.21568627451, 0.21568627451, 0.21568627451)
end
cr:paint()
cr:set_source_rgb(1,1,1)
if fg then
cr:set_source(fg)
else
cr:set_source_rgb(1,1,1)
end
cr:rectangle(0, 7, 15, 1)
cr:fill()
@ -48,7 +57,8 @@ local module = {
-- Fake resources handling
xresources = require("beautiful.xresources"),
awesome_icon = logo()
awesome_icon = logo(),
_logo = logo,
}
module.graph_bg = module.bg_normal

View File

@ -0,0 +1,52 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local parent = ...
local wibox = require("wibox")
local gears = { shape = require("gears.shape"), color = require("gears.color") }
local beautiful = require("beautiful")
parent.spacing = 5
--DOC_HIDE_END
local colors = {
beautiful.bg_normal,
"#00ff00",
gears.color {
type = "linear",
from = { 0 , 20 },
to = { 20, 0 },
stops = {
{ 0, "#0000ff" },
{ 1, "#ff0000" }
},
},
}
--DOC_NEWLINE
for _, color in ipairs(colors) do
local w = wibox.widget {
{
{
text = " Content ",
valign = "center",
align = "center",
widget = wibox.widget.textbox
},
margins = 10,
widget = wibox.container.margin
},
border_color = color,
border_width = 3,
stretch_vertically = true,
stretch_horizontally = true,
shape = gears.shape.rounded_rect,
widget = wibox.container.background
}
parent:add(w) --DOC_HIDE
end
--DOC_HIDE_START
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,54 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local parent = ...
local wibox = require("wibox")
local gears = { shape = require("gears.shape") }
local beautiful = require("beautiful")
local l = wibox.layout {
forced_width = 640,
spacing = 5,
forced_num_cols = 2,
homogeneous = false,
expand = false,
layout = wibox.layout.grid.vertical
}
--DOC_HIDE_END
for k, strategy in ipairs { "none", "inner" } do
--DOC_HIDE_START
local r = k*2
l:add_widget_at(wibox.widget {
markup = "<b>border_strategy = \"".. strategy .."\"</b>",
widget = wibox.widget.textbox,
}, r, 1, 1, 2)
--DOC_HIDE_END
for idx, width in ipairs {0, 1, 3, 10 } do
local w = wibox.widget {
{
{
text = "border_width = "..width,
valign = "center",
align = "center",
widget = wibox.widget.textbox
},
border_color = beautiful.bg_normal,
border_width = width,
border_strategy = strategy,
shape = gears.shape.rounded_rect,
widget = wibox.container.background
},
widget = wibox.container.place
}
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

View File

@ -0,0 +1,34 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local parent = ...
local wibox = require("wibox")
local gears = { shape = require("gears.shape") }
local beautiful = require("beautiful")
parent.spacing = 5
--DOC_HIDE_END
for _, width in ipairs {0, 1, 3, 10 } do
local w = wibox.widget {
{
{
text = " Content ",
valign = "center",
align = "center",
widget = wibox.widget.textbox
},
margins = 10,
widget = wibox.container.margin
},
border_color = beautiful.bg_normal,
border_width = width,
shape = gears.shape.rounded_rect,
widget = wibox.container.background
}
parent:add(w) --DOC_HIDE
end
--DOC_HIDE_START
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,82 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local parent = ...
local wibox = require("wibox")
local gears = { shape = require("gears.shape"), color = require("gears.color") }
local l = wibox.layout {
forced_width = 640,
spacing = 5,
forced_num_cols = 2,
homogeneous = false,
expand = false,
layout = wibox.layout.grid.vertical
}
--DOC_HIDE_END
local gradients = {
gears.color {
type = "linear",
from = { 0 , 0 },
to = { 100, 0 },
stops = {
{ 0 , "#0000ff" },
{ 0.8, "#0000ff" },
{ 1 , "#ff0000" }
}
},
gears.color {
type = "radial",
from = { 30, 98, 20 },
to = { 30, 98, 120 },
stops = {
{ 0 , "#ff0000" },
{ 0.5, "#00ff00" },
{ 1 , "#0000ff" },
}
}
}
--DOC_NEWLINE
for k, stretch in ipairs { false, true } do
--DOC_HIDE_START
local r = (k-1)*5 + 1
l:add_widget_at(wibox.widget {
markup = "<b>stretch_horizontally = \"".. (stretch and "true" or "false") .."\"</b>",
widget = wibox.widget.textbox,
}, r, 1, 1, 2)
--DOC_HIDE_END
for __, grad in ipairs(gradients) do
for idx, width in ipairs { 50, 100, 150, 200 } do
local w = wibox.widget {
{
{
text = " Width: " .. width .. " ",
valign = "center",
align = "center",
widget = wibox.widget.textbox
},
bg = grad,
stretch_horizontally = stretch,
forced_width = width,
fg = "#ffffff",
shape = gears.shape.rounded_rect,
widget = wibox.container.background
},
forced_width = 200,
widget = wibox.container.place
}
l:add_widget_at(w, (k-1)*5 + idx + 1, __, 1, 1) --DOC_HIDE
end
end
--DOC_HIDE_END
end
--DOC_HIDE_START
parent:add(l)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,83 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local parent = ...
local wibox = require("wibox")
local gears = { shape = require("gears.shape"), color = require("gears.color") }
local l = wibox.layout {
forced_width = 640,
spacing = 5,
forced_num_cols = 2,
homogeneous = false,
expand = false,
layout = wibox.layout.grid.vertical
}
--DOC_HIDE_END
local gradients = {
gears.color {
type = "linear",
from = { 0, 0 },
to = { 0, 100 },
stops = {
{ 0 , "#0000ff" },
{ 0.8, "#0000ff" },
{ 1 , "#ff0000" }
}
},
gears.color {
type = "radial",
from = { 30, 98, 20 },
to = { 30, 98, 120 },
stops = {
{ 0 , "#ff0000" },
{ 0.5, "#00ff00" },
{ 1 , "#0000ff" },
}
}
}
--DOC_NEWLINE
for k, stretch in ipairs { false, true } do
--DOC_HIDE_START
local r = (k-1) * 3 + 1
l:add_widget_at(wibox.widget {
markup = "<b>stretch_vertically = \"".. (stretch and "true" or "false") .."\"</b>",
widget = wibox.widget.textbox,
}, r, 1, 1, 2)
--DOC_HIDE_END
for _, gradient in ipairs(gradients) do
for idx, height in ipairs { 10, 50, 100, 150 } do
local w = wibox.widget {
{
{
text = " Height: " .. height .. " ",
valign = "center",
align = "center",
widget = wibox.widget.textbox
},
bg = gradient,
stretch_vertically = stretch,
forced_height = height,
fg = "#ffffff",
shape = gears.shape.rounded_rect,
widget = wibox.container.background
},
forced_height = 150,
widget = wibox.container.place
}
l:add_widget_at(w, r + _, idx, 1, 1) --DOC_HIDE
end
end
--DOC_HIDE_END
end
--DOC_HIDE_START
parent:add(l)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -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

View File

@ -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 "side = 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

View File

@ -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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="fill:url(#b);stroke-width:.55040765;stroke-miterlimit:4;;" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-vector-effect:none;fill:url(#c);fill-fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dashoffset:0;stroke-color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
--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 = "<b>SVG image (34x34 pt):</b>",
widget = wibox.widget.textbox,
},1,1)
l:add_widget_at(wibox.widget {
markup = "<b>PNG image (48x48 px):</b>",
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 = "<b>borders = ".. borders .."</b>",
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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="fill:url(#b);stroke-width:.55040765;stroke-miterlimit:4;;" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-vector-effect:none;fill:url(#c);fill-fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dashoffset:0;stroke-color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
local image_path2 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="90" height="90" viewBox="0 0 23.812 23.813">
<defs>
<linearGradient id="a">
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="0" />
<stop style="stop-color:#4cc155;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="19.837" y1="28.684" x2="21.503" y2="30.629" gradientUnits="userSpaceOnUse" gradientTransform="matrix(3.00654 0 0 3.01583 -33.75 -72.882)" />
</defs>
<g transform="translate(-16.82 -12.342)">
<ellipse style="fill:#ff7f2a;stroke-width:4.39130402;stroke-miterlimit:4;" cx="20.797" cy="16.332" rx="3.977" ry="3.99" />
<ellipse cy="16.332" cx="28.681" style="fill:url(#b);stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#f0c;stroke-width:4.39130402;stroke-miterlimit:4;" cx="36.655" cy="16.332" rx="3.977" ry="3.99" />
<ellipse cy="24.29" cx="20.797" style="fill:#6f0;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#cf0;stroke-width:4.39130402;stroke-miterlimit:4;" cx="28.681" cy="24.29" rx="3.977" ry="3.99" />
<ellipse cy="24.29" cx="36.655" style="fill:#0ff;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#f0f;stroke-width:4.39130402;stroke-miterlimit:4;" cx="20.797" cy="32.165" rx="3.977" ry="3.99" />
<ellipse cy="32.165" cx="28.681" style="fill:#c8ab37;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#ff2a2a;stroke-width:4.39130402;stroke-miterlimit:4;" cx="36.655" cy="32.165" rx="3.977" ry="3.99" />
</g>
</svg>
]]
--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 = "<b>Original image:</b>",
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 = "<b>corners_fit_policy = \"".. mode .."\"</b>",
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

View File

@ -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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="fill:url(#b);stroke-width:.55040765;stroke-miterlimit:4;;" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-vector-effect:none;fill:url(#c);fill-fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dashoffset:0;stroke-color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
--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 = "<b>SVG image (34x34 pt):</b>",
widget = wibox.widget.textbox,
},1,1)
l:add_widget_at(wibox.widget {
markup = "<b>PNG image (48x48 px):</b>",
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 = "<b>border_image_dpi = ".. dpi .."</b>",
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

View File

@ -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 = '<?xml version="1.0"?>'..
'<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="30" height="30" viewBox="0 0 7.937 7.937">'..
' <defs>'..
' <linearGradient id="a">'..
' <stop style="stop-opacity:1;stop-color:magenta;" offset="0" id="first"/>'..
' <stop offset=".5" style="stop-opacity:1;stop-color:cyan;" id="second"/>'..
' <stop style="stop-opacity:1;stop-color:yellow;" offset="1" id="third"/>'..
' </linearGradient>' ..
' <linearGradient xlink:href="#a" id="b" gradientUnits="userSpaceOnUse" x1="28.726" y1="64.923" x2="182.185" y2="201.75" gradientTransform="matrix(.04726 0 0 .053 83.075 141.528)"/>'..
' </defs>'..
' <path d="M84.732 144.627c-.372 0-.642.329-.642.679v6.58c0 .35.27.678.642.678h6.653c.372 0 .642-.328.642-.679v-6.579c0-.35-.27-.68-.642-.68zm.043.685h6.567v6.568h-6.567z" style="fill:url(#b);" transform="translate(-84.09 -144.627)"/>'..
'</svg>'
--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

View File

@ -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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="opacity:1;fill:url(#b);fill-opacity:1;stroke:none;stroke-width:.55040765;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:url(#c);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
--luacheck: pop
local l = wibox.layout {
forced_width = 240,
spacing = 5,
layout = wibox.layout.fixed.vertical
}
l:add(wibox.widget {
markup = "<b>Original image:</b>",
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 = "<b>`fill` = "..(fill and "true" or "false").."</b>",
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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="fill:url(#b);stroke-width:.55040765;stroke-miterlimit:4;;" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-vector-effect:none;fill:url(#c);fill-fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dashoffset:0;stroke-color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
local image_path2 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="90" height="90" viewBox="0 0 23.812 23.813">
<defs>
<linearGradient id="a">
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="0" />
<stop style="stop-color:#4cc155;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="19.837" y1="28.684" x2="21.503" y2="30.629" gradientUnits="userSpaceOnUse" gradientTransform="matrix(3.00654 0 0 3.01583 -33.75 -72.882)" />
</defs>
<g transform="translate(-16.82 -12.342)">
<ellipse style="fill:#ff7f2a;stroke-width:4.39130402;stroke-miterlimit:4;" cx="20.797" cy="16.332" rx="3.977" ry="3.99" />
<ellipse cy="16.332" cx="28.681" style="fill:url(#b);stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#f0c;stroke-width:4.39130402;stroke-miterlimit:4;" cx="36.655" cy="16.332" rx="3.977" ry="3.99" />
<ellipse cy="24.29" cx="20.797" style="fill:#6f0;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#cf0;stroke-width:4.39130402;stroke-miterlimit:4;" cx="28.681" cy="24.29" rx="3.977" ry="3.99" />
<ellipse cy="24.29" cx="36.655" style="fill:#0ff;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#f0f;stroke-width:4.39130402;stroke-miterlimit:4;" cx="20.797" cy="32.165" rx="3.977" ry="3.99" />
<ellipse cy="32.165" cx="28.681" style="fill:#c8ab37;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#ff2a2a;stroke-width:4.39130402;stroke-miterlimit:4;" cx="36.655" cy="32.165" rx="3.977" ry="3.99" />
</g>
</svg>
]]
--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 = "<b>Original image:</b>",
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 = "<b>filling_fit_policy = \"".. mode .."\"</b>",
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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="opacity:0.25;fill:url(#b);fill-opacity:1;stroke:none;stroke-width:.55040765;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:0.25;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:url(#c);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
--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 = "<b>Central widget</b>",
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 = "<b>honor_borders = "..(honor and "true" or "false").."</b>",
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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="67.006" height="65.26">
<defs>
<filter height="1.408" y="-.204" width="1.408" x="-.204" id="a" style="color-interpolation-filters:sRGB">
<feGaussianBlur stdDeviation="2.079" />
</filter>
<filter height="1.158" y="-.079" width="1.158" x="-.079" id="b" style="color-interpolation-filters:sRGB">
<feGaussianBlur stdDeviation=".919" />
</filter>
<clipPath id="c" clipPathUnits="userSpaceOnUse">
<rect style="opacity:1;fill:#FF0000;fill-opacity:1;" width="12.7" height="12.7" x="56.318" y="122.526" rx="2.266" ry="2.266" />
</clipPath>
</defs>
<g transform="matrix(3.77953 0 0 3.77953 -205.339 -465.345)">
<path style="opacity:1;fill:#000;fill-opacity:1;filter:url(#a)" d="M341.607 504.254v40.498H326.25v-.09h-28.72a8.542 8.542 0 0 0 8.154 5.942h30.873a8.545 8.545 0 0 0 8.562-8.565v-30.873a8.527 8.527 0 0 0-3.512-6.912z" transform="matrix(.26458 0 0 .26458 -21.823 -7.793)" />
<rect ry="2.266" rx="2.266" y="122.526" x="56.318" height="12.7" width="12.7" style="opacity:1;fill:none;fill-opacity:1;filter:url(#b)" clip-path="url(#c)" transform="translate(-.267 1.837)" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:#FF7700;fill-opacity:1;fill-rule:nonzero;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M58.384 123.88a2.617 2.617 0 0 0-2.616 2.615v8.17a2.617 2.617 0 0 0 2.616 2.615h8.168a2.619 2.619 0 0 0 2.617-2.615v-8.17a2.619 2.619 0 0 0-2.617-2.615zm0 .7h8.168c1.067 0 1.916.847 1.916 1.915v8.17a1.904 1.904 0 0 1-1.917 1.916h-8.167a1.904 1.904 0 0 1-1.916-1.916v-8.17c0-1.068.848-1.914 1.916-1.914z" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:#FF0000;fill-opacity:1;fill-rule:nonzero;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M58.383 123.73a2.766 2.766 0 0 0-2.764 2.764v8.17a2.768 2.768 0 0 0 2.764 2.766h8.168a2.771 2.771 0 0 0 2.767-2.766v-8.17a2.77 2.77 0 0 0-2.767-2.764zm0 .3h8.168a2.468 2.468 0 0 1 2.469 2.464v8.17a2.47 2.47 0 0 1-2.47 2.467h-8.167a2.466 2.466 0 0 1-2.465-2.467v-8.17a2.464 2.464 0 0 1 2.465-2.465zm0 .402a2.054 2.054 0 0 0-2.065 2.062v8.17c0 1.147.918 2.066 2.065 2.066h8.168a2.06 2.06 0 0 0 2.066-2.066v-8.17c0-1.147-.92-2.062-2.066-2.062zm0 .298h8.168a1.75 1.75 0 0 1 1.767 1.764v8.17c0 .988-.78 1.768-1.767 1.768h-8.168c-.988 0-1.766-.78-1.766-1.768v-8.17c0-.988.778-1.764 1.766-1.764z" />
</g>
</svg>
]]
--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 = "<b>Central widget</b>",
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 = "<b>ontop = "..(ontop and "true" or "false").."</b>",
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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="opacity:1;fill:url(#b);fill-opacity:1;stroke:none;stroke-width:.55040765;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:url(#c);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
--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 = "<b>Central widget</b>",
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 = "<b>paddings = "..padding.."</b>",
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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="fill:url(#b);stroke-width:.55040765;stroke-miterlimit:4;;" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-vector-effect:none;fill:url(#c);fill-fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dashoffset:0;stroke-color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
local image_path2 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="90" height="90" viewBox="0 0 23.812 23.813">
<defs>
<linearGradient id="a">
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="0" />
<stop style="stop-color:#4cc155;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="19.837" y1="28.684" x2="21.503" y2="30.629" gradientUnits="userSpaceOnUse" gradientTransform="matrix(3.00654 0 0 3.01583 -33.75 -72.882)" />
</defs>
<g transform="translate(-16.82 -12.342)">
<ellipse style="fill:#ff7f2a;stroke-width:4.39130402;stroke-miterlimit:4;" cx="20.797" cy="16.332" rx="3.977" ry="3.99" />
<ellipse cy="16.332" cx="28.681" style="fill:url(#b);stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#f0c;stroke-width:4.39130402;stroke-miterlimit:4;" cx="36.655" cy="16.332" rx="3.977" ry="3.99" />
<ellipse cy="24.29" cx="20.797" style="fill:#6f0;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#cf0;stroke-width:4.39130402;stroke-miterlimit:4;" cx="28.681" cy="24.29" rx="3.977" ry="3.99" />
<ellipse cy="24.29" cx="36.655" style="fill:#0ff;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#f0f;stroke-width:4.39130402;stroke-miterlimit:4;" cx="20.797" cy="32.165" rx="3.977" ry="3.99" />
<ellipse cy="32.165" cx="28.681" style="fill:#c8ab37;stroke-width:4.39130402;stroke-miterlimit:4;" rx="3.977" ry="3.99" />
<ellipse style="fill:#ff2a2a;stroke-width:4.39130402;stroke-miterlimit:4;" cx="36.655" cy="32.165" rx="3.977" ry="3.99" />
</g>
</svg>
]]
local image_path3 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="67.006" height="65.26">
<defs>
<filter height="1.408" y="-.204" width="1.408" x="-.204" id="a" style="color-interpolation-filters:sRGB">
<feGaussianBlur stdDeviation="2.079" />
</filter>
<filter height="1.158" y="-.079" width="1.158" x="-.079" id="b" style="color-interpolation-filters:sRGB">
<feGaussianBlur stdDeviation=".919" />
</filter>
<clipPath id="c" clipPathUnits="userSpaceOnUse">
<rect style="opacity:1;fill:#4cc155;fill-opacity:1;" width="12.7" height="12.7" x="56.318" y="122.526" rx="2.266" ry="2.266" />
</clipPath>
</defs>
<g transform="matrix(3.77953 0 0 3.77953 -205.339 -465.345)">
<path style="opacity:1;fill:#000;fill-opacity:1;filter:url(#a)" d="M341.607 504.254v40.498H326.25v-.09h-28.72a8.542 8.542 0 0 0 8.154 5.942h30.873a8.545 8.545 0 0 0 8.562-8.565v-30.873a8.527 8.527 0 0 0-3.512-6.912z" transform="matrix(.26458 0 0 .26458 -21.823 -7.793)" />
<rect ry="2.266" rx="2.266" y="122.526" x="56.318" height="12.7" width="12.7" style="opacity:1;fill:none;fill-opacity:1;filter:url(#b)" clip-path="url(#c)" transform="translate(-.267 1.837)" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:#ef00d9;fill-opacity:1;fill-rule:nonzero;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M58.384 123.88a2.617 2.617 0 0 0-2.616 2.615v8.17a2.617 2.617 0 0 0 2.616 2.615h8.168a2.619 2.619 0 0 0 2.617-2.615v-8.17a2.619 2.619 0 0 0-2.617-2.615zm0 .7h8.168c1.067 0 1.916.847 1.916 1.915v8.17a1.904 1.904 0 0 1-1.917 1.916h-8.167a1.904 1.904 0 0 1-1.916-1.916v-8.17c0-1.068.848-1.914 1.916-1.914z" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:#0c00ef;fill-opacity:1;fill-rule:nonzero;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M58.383 123.73a2.766 2.766 0 0 0-2.764 2.764v8.17a2.768 2.768 0 0 0 2.764 2.766h8.168a2.771 2.771 0 0 0 2.767-2.766v-8.17a2.77 2.77 0 0 0-2.767-2.764zm0 .3h8.168a2.468 2.468 0 0 1 2.469 2.464v8.17a2.47 2.47 0 0 1-2.47 2.467h-8.167a2.466 2.466 0 0 1-2.465-2.467v-8.17a2.464 2.464 0 0 1 2.465-2.465zm0 .402a2.054 2.054 0 0 0-2.065 2.062v8.17c0 1.147.918 2.066 2.065 2.066h8.168a2.06 2.06 0 0 0 2.066-2.066v-8.17c0-1.147-.92-2.062-2.066-2.062zm0 .298h8.168a1.75 1.75 0 0 1 1.767 1.764v8.17c0 .988-.78 1.768-1.767 1.768h-8.168c-.988 0-1.766-.78-1.766-1.768v-8.17c0-.988.778-1.764 1.766-1.764z" />
</g>
</svg>
]]
--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 = "<b>Original image:</b>",
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 = "<b>sides_fit_policy = \"".. mode .."\"</b>",
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

View File

@ -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 = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="opacity:1;fill:url(#b);fill-opacity:1;stroke:none;stroke-width:.55040765;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:url(#c);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
--luacheck: pop
local l = wibox.layout {
forced_width = 240,
spacing = 5,
layout = wibox.layout.fixed.vertical
}
l:add(wibox.widget {
markup = "<b>Original image:</b>",
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 = "<b>`slice` = "..(i and "true" or "false").."</b>",
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

View File

@ -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 = '<?xml version="1.0"?>'..
'<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="30" height="30" viewBox="0 0 7.937 7.937">'..
' <defs>'..
' <linearGradient id="a">'..
' <stop style="stop-opacity:1" offset="0" id="first"/>'..
' <stop offset=".5" style="stop-opacity:1" id="second"/>'..
' <stop style="stop-opacity:1" offset="1" id="third"/>'..
' </linearGradient>' ..
' <linearGradient xlink:href="#a" id="b" gradientUnits="userSpaceOnUse" x1="28.726" y1="64.923" x2="182.185" y2="201.75" gradientTransform="matrix(.04726 0 0 .053 83.075 141.528)"/>'..
' </defs>'..
' <path d="M84.732 144.627c-.372 0-.642.329-.642.679v6.58c0 .35.27.678.642.678h6.653c.372 0 .642-.328.642-.679v-6.579c0-.35-.27-.68-.642-.68zm.043.685h6.567v6.568h-6.567z" style="fill:url(#b);" transform="translate(-84.09 -144.627)"/>'..
'</svg>'
--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)

View File

@ -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 = [[
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="105.827" height="23.532" viewBox="0 0 28 6.226">
<defs>
<linearGradient gradientTransform="matrix(.22077 0 0 .2208 -204.378 31.642)" xlink:href="#a" id="d" x1="-264.083" y1="45.26" x2="-264.083" y2="17.29" gradientUnits="userSpaceOnUse"/>
<linearGradient id="a">
<stop style="stop-color:#777;stop-opacity:1" offset="0"/>
<stop style="stop-color:#dadada;stop-opacity:1" offset="1"/>
</linearGradient>
<linearGradient gradientTransform="matrix(.22077 0 0 .2208 -204.378 31.642)" xlink:href="#b" id="c" x1="-254.596" y1="18.068" x2="-254.596" y2="44.26" gradientUnits="userSpaceOnUse" spreadMethod="pad"/>
<linearGradient id="b">
<stop style="stop-color:#ececec;stop-opacity:1" offset="0"/>
<stop offset=".963" style="stop-color:#cbcbcb;stop-opacity:1"/>
<stop style="stop-color:#8d8d8d;stop-opacity:1" offset="1"/>
</linearGradient>
</defs>
<path d="M-250.12 35.462h23.877c1.111 0 2.006.894 2.006 2.006v3.999h-27.89v-3.999c0-1.112.895-2.006 2.006-2.006z" style="opacity:1;fill:url(#c);fill-opacity:1;stroke:none;stroke-width:.06623417;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" transform="translate(252.127 -35.351)"/>
<path style="opacity:1;fill:none;fill-opacity:1;stroke:url(#d);stroke-width:.22078058;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M-249.988 35.462h23.745c1.111 0 2.006.894 2.006 2.006v3.999h-27.757v-3.999c0-1.112.895-2.006 2.006-2.006z" transform="translate(252.127 -35.351)"/>
</svg>
]]
local btn = [[
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="45.773" height="45.773" viewBox="0 0 12.111 12.111">
<defs>
<linearGradient id="a">
<stop style="stop-opacity:1" offset="0" id="bg2"/>
<stop style="stop-opacity:.88627452" offset="1" id="bg1"/>
</linearGradient>
<linearGradient xlink:href="#b" id="g" gradientUnits="userSpaceOnUse" x1="-453.433" y1="105.448" x2="-453.433" y2="95.432"/>
<linearGradient id="b">
<stop style="stop-color:#d8eaff;stop-opacity:1" offset="0"/>
<stop style="stop-color:#d8eaff;stop-opacity:0" offset="1"/>
</linearGradient>
<linearGradient id="c">
<stop offset="0" style="stop-color:#ececec;stop-opacity:1"/>
<stop offset="1" style="stop-color:#8d8d8d;stop-opacity:1"/>
</linearGradient>
<linearGradient xlink:href="#d" id="i" x1="-453.111" y1="95.539" x2="-453.111" y2="105.508" gradientUnits="userSpaceOnUse"/>
<linearGradient id="d">
<stop style="stop-color:#000;stop-opacity:1" offset="0"/>
<stop style="stop-color:#000;stop-opacity:0" offset="1"/>
</linearGradient>
<linearGradient id="e">
<stop style="stop-color:#101010;stop-opacity:.02531646" offset="0"/>
<stop offset=".788" style="stop-color:#000;stop-opacity:0"/>
<stop style="stop-color:#272727;stop-opacity:.68776369" offset=".875"/>
<stop style="stop-color:#ededed;stop-opacity:.40784314" offset="1"/>
</linearGradient>
<radialGradient xlink:href="#a" id="f" gradientUnits="userSpaceOnUse" cx="-453.052" cy="104.365" fx="-453.052" fy="104.365" r="5.292"/>
<radialGradient xlink:href="#e" id="j" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1.14291 -.0086 .00853 1.13429 51.276 -28.422)" cx="-442.185" cy="110.611" fx="-442.185" fy="110.611" r="5.292"/>
<clipPath clipPathUnits="userSpaceOnUse" id="h">
<circle r="5.292" cy="100.83" cx="-453.193" style="opacity:1;fill:url(#radialGradient1250);fill-opacity:1;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
</clipPath>
</defs>
<g transform="translate(459.213 -94.787)">
<circle r="5.292" cy="100.83" cx="-453.193" style="opacity:1;fill:url(#f);fill-opacity:1;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
<path d="M-448.374 98.657c.13 3.044-9.622 2.906-9.661.094-.017-.466 1.585-3.179 4.842-3.212 2.922 0 4.668 2.334 4.819 3.118z" style="opacity:1;fill:url(#g);fill-opacity:1;stroke:url(#linearGradient1378);stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0"/>
<circle clip-path="url(#h)" style="opacity:1;fill:none;fill-opacity:1;stroke:url(#i);stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter1216)" cx="-453.193" cy="100.83" r="5.292"/>
<circle style="opacity:1;fill:none;fill-opacity:1;stroke:url(#j);stroke-width:1.92490542;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" cx="-453.158" cy="100.842" r="5.093"/>
</g>
</svg>
]]
--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

View File

@ -0,0 +1,47 @@
--DOC_HIDE_ALL
--DOC_GEN_IMAGE
local wibox = require("wibox")
-- luacheck: push no max string line length
local data = [[
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 12.7 12.7">
<defs>
<linearGradient id="a">
<stop style="stop-color:#ff2121;stop-opacity:1" offset="0" />
<stop style="stop-color:#2c21ff;stop-opacity:1" offset="1" />
</linearGradient>
<linearGradient xlink:href="#a" id="b" x1="37.798" y1="89.869" x2="148.167" y2="200.238" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" />
<linearGradient xlink:href="#a" id="c" gradientUnits="userSpaceOnUse" gradientTransform="translate(31.412 180.42) scale(.11008)" x1="148.167" y1="200.238" x2="37.798" y2="89.869" />
</defs>
<g transform="translate(-35.298 -190.038)">
<rect style="opacity:1;fill:url(#b);fill-opacity:1;stroke:none;stroke-width:.55040765;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" width="12.15" height="12.15" x="35.573" y="190.313" rx="2.371" ry="2.371" />
<path style="color:#000;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000;solid-opacity:1;vector-effect:none;fill:url(#c);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:.55040765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;enable-background:accumulate" d="M37.943 190.037a2.647 2.647 0 0 0-2.646 2.647v7.408a2.647 2.647 0 0 0 2.646 2.646h7.409a2.647 2.647 0 0 0 2.646-2.646v-7.408a2.647 2.647 0 0 0-2.646-2.647zm0 .55h7.409c1.165 0 2.095.931 2.095 2.097v7.408c0 1.165-.93 2.095-2.095 2.095h-7.409a2.085 2.085 0 0 1-2.095-2.095v-7.408c0-1.166.93-2.096 2.095-2.096z" />
</g>
</svg>
]]
--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
}

View File

@ -24,7 +24,14 @@ local function demo()
cr:set_source_rgb(0,1,0)
cr:arc(11, 16, 8, 0, 2*math.pi)
cr:fill()
cr:fill_preserve()
cr:clip()
cr:move_to(0 ,0 )
cr:line_to(22,32)
cr:set_source_rgb(1,1,0)
cr:stroke()
return img
end
@ -69,13 +76,19 @@ 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('horizontal_fit_policy = "repeat"'), 4, 1)
l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "reflect"'), 5, 1)
l:add_widget_at(wibox.widget.textbox('horizontal_fit_policy = "pad"'), 6, 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)
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(build_ib(size, "repeat" ), 4, i + 1)
l:add_widget_at(build_ib(size, "reflect" ), 5, i + 1)
l:add_widget_at(build_ib(size, "pad" ), 6, i + 1)
l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 7, i + 1)
end
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -24,7 +24,14 @@ local function demo()
cr:set_source_rgb(0,1,0)
cr:arc(16, 11, 8, 0, 2*math.pi)
cr:fill()
cr:fill_preserve()
cr:clip()
cr:move_to(0 ,0 )
cr:line_to(32,22)
cr:set_source_rgb(1,1,0)
cr:stroke()
return img
end
@ -66,16 +73,22 @@ local l = wibox.widget {
}
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('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('vertical_fit_policy = "repeat"' ), 4, 1)
l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "reflect"'), 5, 1)
l:add_widget_at(wibox.widget.textbox('vertical_fit_policy = "pad"' ), 6, 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)
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(build_ib(size, "repeat" ), 4, i + 1)
l:add_widget_at(build_ib(size, "reflect" ), 5, i + 1)
l:add_widget_at(build_ib(size, "pad" ), 6, i + 1)
l:add_widget_at(cell_centered_widget(wibox.widget.textbox(size..'x'..size)), 7, i + 1)
end
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80