Skip to content

Commit

Permalink
doc: Add more wibox.container.background examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elv13 committed Dec 31, 2023
1 parent 5ee926d commit 1291a34
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/examples/shims/beautiful.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions tests/examples/wibox/container/background/border_color.lua
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions tests/examples/wibox/container/background/border_strategy.lua
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions tests/examples/wibox/container/background/border_width.lua
Original file line number Diff line number Diff line change
@@ -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
82 changes: 82 additions & 0 deletions tests/examples/wibox/container/background/stretch_horizontally.lua
Original file line number Diff line number Diff line change
@@ -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
83 changes: 83 additions & 0 deletions tests/examples/wibox/container/background/stretch_vertically.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1291a34

Please sign in to comment.