doc: Add more `wibox.container.background` examples.

This commit is contained in:
Emmanuel Lepage Vallee 2022-02-05 15:18:04 -08:00
parent 5ee926d5f1
commit 1291a346f3
6 changed files with 319 additions and 4 deletions

View File

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