diff --git a/docs/images/progressbar.svg b/docs/images/progressbar.svg new file mode 100644 index 00000000..ade0797e --- /dev/null +++ b/docs/images/progressbar.svg @@ -0,0 +1,323 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + margins.left + paddings.right + margins.bottom + paddings.left + color + background_color + + border_color + bar_border_width + paddings.top + margins.right + border_width + margins.top + + diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 29314cae..05261466 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -1,6 +1,11 @@ --------------------------------------------------------------------------- --- A progressbar widget. -- +-- ![Components](../images/progressbar.svg) +-- +-- Common usage examples +-- ===================== +-- -- To add text on top of the progressbar, a `wibox.layout.stack` can be used: -- --@DOC_wibox_widget_progressbar_text_EXAMPLE@ @@ -13,6 +18,15 @@ -- a `wibox.container.constraint` widget or the `forced_width`/`forced_height` -- properties have to be used. -- +-- To have a gradient between 2 colors when the bar reaches a threshold, use +-- the `gears.color` gradients: +-- +--@DOC_wibox_widget_progressbar_grad1_EXAMPLE@ +-- +-- The same goes for multiple solid colors: +-- +--@DOC_wibox_widget_progressbar_grad2_EXAMPLE@ +-- --@DOC_wibox_widget_defaults_progressbar_EXAMPLE@ -- -- @author Julien Danjou <julien@danjou.info> @@ -37,14 +51,18 @@ local progressbar = { mt = {} } -- -- If the value is nil, no border will be drawn. -- +-- @DOC_wibox_widget_progressbar_border_color_EXAMPLE@ +-- -- @property border_color --- @tparam color color The border color to set. +-- @tparam gears.color color The border color to set. -- @propemits true false -- @propbeautiful -- @see gears.color --- The progressbar border width. -- +-- @DOC_wibox_widget_progressbar_border_width_EXAMPLE@ +-- -- @property border_width -- @tparam number border_width -- @propemits true false @@ -54,14 +72,18 @@ local progressbar = { mt = {} } -- -- If the value is nil, no border will be drawn. -- +-- @DOC_wibox_widget_progressbar_bar_border_color_EXAMPLE@ +-- -- @property bar_border_color --- @tparam color color The border color to set. +-- @tparam gears.color color The border color to set. -- @propemits true false -- @propbeautiful -- @see gears.color --- The progressbar inner border width. -- +-- @DOC_wibox_widget_progressbar_bar_border_width_EXAMPLE@ +-- -- @property bar_border_width -- @tparam number bar_border_width -- @propbeautiful @@ -69,16 +91,20 @@ local progressbar = { mt = {} } --- The progressbar foreground color. -- +-- @DOC_wibox_widget_progressbar_color_EXAMPLE@ +-- -- @property color --- @tparam color color The progressbar color. +-- @tparam gears.color color The progressbar color. -- @propemits true false -- @usebeautiful beautiful.progressbar_fg -- @see gears.color --- The progressbar background color. -- +-- @DOC_wibox_widget_progressbar_background_color_EXAMPLE@ +-- -- @property background_color --- @tparam color color The progressbar background color. +-- @tparam gears.color color The progressbar background color. -- @propemits true false -- @usebeautiful beautiful.progressbar_bg -- @see gears.color @@ -119,29 +145,45 @@ local progressbar = { mt = {} } -- @tparam[opt=true] boolean clip -- @propemits true false ---- The progressbar to draw ticks. Default is false. +--- The progressbar to draw ticks. +-- +-- @DOC_wibox_widget_progressbar_ticks_EXAMPLE@ -- -- @property ticks --- @tparam boolean ticks +-- @tparam[opt=false] boolean ticks -- @propemits true false --- The progressbar ticks gap. -- +-- @DOC_wibox_widget_progressbar_ticks_gap_EXAMPLE@ +-- -- @property ticks_gap --- @tparam number ticks_gap +-- @tparam[opt=1] number ticks_gap -- @propemits true false --- The progressbar ticks size. -- +-- @DOC_wibox_widget_progressbar_ticks_size_EXAMPLE@ +-- +-- It is also possible to mix this feature with the `bar_shape` property: +-- +-- @DOC_wibox_widget_progressbar_ticks_size2_EXAMPLE@ +-- -- @property ticks_size --- @tparam number ticks_size +-- @tparam[opt=4] number ticks_size -- @propemits true false --- The maximum value the progressbar should handle. -- +-- By default, the value is 1. So the content of `value` is +-- a percentage. +-- +-- @DOC_wibox_widget_progressbar_max_value_EXAMPLE@ +-- -- @property max_value --- @tparam number max_value +-- @tparam[opt=1] number max_value -- @propemits true false +-- @see value --- The progressbar background color. -- @@ -187,10 +229,18 @@ local progressbar = { mt = {} } --- The progressbar margins. -- +-- The margins are around the progressbar. If you want to add space between the +-- bar and the border, use `paddings`. +-- +-- @DOC_wibox_widget_progressbar_margins2_EXAMPLE@ +-- -- Note that if the `clip` is disabled, this allows the background to be smaller -- than the bar. -- --- See the `clip` example. +-- It is also possible to specify a single number instead of a border for each +-- direction; +-- +-- @DOC_wibox_widget_progressbar_margins1_EXAMPLE@ -- -- @property margins -- @tparam[opt=0] (table|number|nil) margins A table for each side or a number @@ -201,13 +251,21 @@ local progressbar = { mt = {} } -- @propemits false false -- @propbeautiful -- @see clip +-- @see padding +-- @see wibox.container.margin --- The progressbar padding. -- +-- This is the space between the inner bar and the progressbar outer border. +-- -- Note that if the `clip` is disabled, this allows the bar to be taller -- than the background. -- --- See the `clip` example. +-- @DOC_wibox_widget_progressbar_paddings2_EXAMPLE@ +-- +-- The paddings can also be a single numeric value: +-- +-- @DOC_wibox_widget_progressbar_paddings1_EXAMPLE@ -- -- @property paddings -- @tparam[opt=0] (table|number|nil) padding A table for each side or a number @@ -218,6 +276,7 @@ local progressbar = { mt = {} } -- @propemits false false -- @propbeautiful -- @see clip +-- @see margins --- The progressbar margins. -- @@ -373,8 +432,8 @@ function progressbar.draw(pbar, _, cr, width, height) -- Draw the progressbar shape - local bar_shape = pbar._private.bar_shape or - beautiful.progressbar_bar_shape or shape.rectangle + local explicit_bar_shape = pbar._private.bar_shape or beautiful.progressbar_bar_shape + local bar_shape = explicit_bar_shape or shape.rectangle local bar_border_width = pbar._private.bar_border_width or beautiful.progressbar_bar_border_width or pbar._private.border_width or @@ -389,20 +448,46 @@ function progressbar.draw(pbar, _, cr, width, height) over_drawn_height = over_drawn_height - bar_border_width cr:translate(bar_border_width/2, bar_border_width/2) - bar_shape(cr, rel_x, over_drawn_height) + if pbar._private.ticks and explicit_bar_shape then + local tr_off = 0 - cr:set_source(color(pbar._private.color or beautiful.progressbar_fg or "#ff0000")) + -- Make all the shape and fill later in case the `color` is a gradient. + for _=0, width / (ticks_size+ticks_gap)-border_width do + bar_shape(cr, ticks_size - (bar_border_width/2), over_drawn_height) + cr:translate(ticks_size+ticks_gap, 0) + tr_off = tr_off + ticks_size+ticks_gap + end + + -- Re-align the (potential) color gradients to 0,0. + cr:translate(-tr_off, 0) + + if bar_border_width > 0 then + cr:set_source(color(bar_border_color)) + cr:set_line_width(bar_border_width) + cr:stroke_preserve() + end + + cr:set_source(color(pbar._private.color or beautiful.progressbar_fg or "#ff0000")) - if bar_border_width > 0 then - cr:fill_preserve() - cr:set_source(color(bar_border_color)) - cr:set_line_width(bar_border_width) - cr:stroke() - else cr:fill() + else + bar_shape(cr, rel_x, over_drawn_height) + + cr:set_source(color(pbar._private.color or beautiful.progressbar_fg or "#ff0000")) + + if bar_border_width > 0 then + cr:fill_preserve() + cr:set_source(color(bar_border_color)) + cr:set_line_width(bar_border_width) + cr:stroke() + else + cr:fill() + end end - if pbar._private.ticks then + -- Legacy "ticks" bars. It looks horrible, but to avoid breaking the + -- behavior, so be it. + if pbar._private.ticks and not explicit_bar_shape then for i=0, width / (ticks_size+ticks_gap)-border_width do local rel_offset = over_drawn_width / 1 - (ticks_size+ticks_gap) * i @@ -424,9 +509,15 @@ end --- Set the progressbar value. -- +-- By default, unless `max_value` is set, it is number between +-- zero and one. +-- +-- @DOC_wibox_widget_progressbar_value_EXAMPLE@ +-- -- @property value --- @tparam number value The progress bar value between 0 and 1. +-- @tparam number value The progress bar value. -- @propemits true false +-- @see max_value function progressbar:set_value(value) value = value or 0 diff --git a/tests/examples/wibox/widget/progressbar/background_color.lua b/tests/examples/wibox/widget/progressbar/background_color.lua new file mode 100644 index 00000000..a859a902 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/background_color.lua @@ -0,0 +1,35 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, color in ipairs { {nil}, {"#ff0000"}, {"#00ff00"}, {"#0000ff44"} } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + background_color = color[1], + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = color[1] and '"'..color[1]..'"' or "nil", + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/bar_border_color.lua b/tests/examples/wibox/widget/progressbar/bar_border_color.lua new file mode 100644 index 00000000..8cd5d183 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/bar_border_color.lua @@ -0,0 +1,36 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, color in ipairs { {nil}, {"#ff0000"}, {"#00ff00"}, {"#0000ff44"} } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + bar_border_width = 2, + bar_border_color = color[1], + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = color[1] and '"'..color[1]..'"' or "nil", + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/bar_border_width.lua b/tests/examples/wibox/widget/progressbar/bar_border_width.lua new file mode 100644 index 00000000..4cd31ff7 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/bar_border_width.lua @@ -0,0 +1,36 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, width in ipairs { 0, 2, 4, 6 } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + bar_border_width = width, + bar_border_color = "#ff0000", + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = width, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/border_color.lua b/tests/examples/wibox/widget/progressbar/border_color.lua new file mode 100644 index 00000000..8d9b22a0 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/border_color.lua @@ -0,0 +1,36 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, color in ipairs { {nil}, {"#ff0000"}, {"#00ff00"}, {"#0000ff44"} } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + border_width = 2, + border_color = color[1], + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = color[1] and '"'..color[1]..'"' or "nil", + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/border_width.lua b/tests/examples/wibox/widget/progressbar/border_width.lua new file mode 100644 index 00000000..a31ae14e --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/border_width.lua @@ -0,0 +1,36 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, width in ipairs { 0, 2, 4, 6 } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + border_width = width, + border_color = "#ff0000", + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = width, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/color.lua b/tests/examples/wibox/widget/progressbar/color.lua new file mode 100644 index 00000000..624f5b1b --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/color.lua @@ -0,0 +1,35 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, color in ipairs { {nil}, {"#ff0000"}, {"#00ff00"}, {"#0000ff44"} } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + color = color[1], + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = color[1] and '"'..color[1]..'"' or "nil", + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/grad1.lua b/tests/examples/wibox/widget/progressbar/grad1.lua new file mode 100644 index 00000000..06e29917 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/grad1.lua @@ -0,0 +1,30 @@ +--DOC_GEN_IMAGE --DOC_HIDE --DOC_NO_USAGE +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require("beautiful") --DOC_HIDE + +parent:add( --DOC_HIDE + + wibox.widget { + color = { + type = "linear", + from = { 0 , 0 }, + to = { 100, 0 }, + stops = { + { 0 , "#0000ff" }, + { 0.8, "#0000ff" }, + { 1 , "#ff0000" } + } + }, + max_value = 1, + value = 1, + forced_height = 20, + forced_width = 100, + paddings = 1, + border_width = 1, + border_color = beautiful.border_color, + widget = wibox.widget.progressbar, + } + +) --DOC_HIDE +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/grad2.lua b/tests/examples/wibox/widget/progressbar/grad2.lua new file mode 100644 index 00000000..8f59e2b5 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/grad2.lua @@ -0,0 +1,40 @@ +--DOC_GEN_IMAGE --DOC_HIDE --DOC_NO_USAGE +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require("beautiful") --DOC_HIDE + +local l = wibox.layout.fixed.vertical() --DOC_HIDE +l.spacing = 5 --DOC_HIDE + + for _, value in ipairs { 0.3, 0.5, 0.7, 1 } do + l:add( --DOC_HIDE + wibox.widget { + color = { + type = "linear", + from = { 0 , 0 }, + to = { 100, 0 }, + stops = { + { 0 , "#00ff00" }, + { 0.5, "#00ff00" }, + { 0.5, "#ffff00" }, + { 0.7, "#ffff00" }, + { 0.7, "#ffaa00" }, + { 0.8, "#ffaa00" }, + { 0.8, "#ff0000" }, + { 1 , "#ff0000" } + } + }, + max_value = 1, + value = value, + forced_height = 20, + forced_width = 100, + paddings = 1, + border_width = 1, + border_color = beautiful.border_color, + widget = wibox.widget.progressbar, + } + ) --DOC_HIDE + end + +parent:add(l) --DOC_HIDE +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/margins1.lua b/tests/examples/wibox/widget/progressbar/margins1.lua new file mode 100644 index 00000000..e6b91146 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/margins1.lua @@ -0,0 +1,35 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, margin in ipairs { 0, 2, 4, 6 } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + margins = margin, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = margin, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/margins2.lua b/tests/examples/wibox/widget/progressbar/margins2.lua new file mode 100644 index 00000000..7605608a --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/margins2.lua @@ -0,0 +1,28 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE +local parent = ... +local wibox = require("wibox") + +--DOC_HIDE_END +local bg = --DOC_HIDE + wibox.widget { + { + margins = { + top = 4, + bottom = 2, + right = 10, + left = 5 + }, + value = 0.33, + border_width = 2, + border_color = "#00ff00", + background = "#0000ff", + widget = wibox.widget.progressbar, + }, + forced_height = 30, --DOC_HIDE + forced_width = 75, --DOC_hIDE + bg = "#ff0000", + widget = wibox.container.background + } + +parent:add(bg) --DOC_HIDE +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/max_value.lua b/tests/examples/wibox/widget/progressbar/max_value.lua new file mode 100644 index 00000000..09777e46 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/max_value.lua @@ -0,0 +1,35 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, value in ipairs { 0, 10, 42, 999 } do + + local pb = --DOC_HIDE + wibox.widget { + value = value, + max_value = 42, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = value.."/42", + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/paddings1.lua b/tests/examples/wibox/widget/progressbar/paddings1.lua new file mode 100644 index 00000000..1395598e --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/paddings1.lua @@ -0,0 +1,35 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, padding in ipairs { 0, 2, 4, 6 } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + paddings = padding, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = padding, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/paddings2.lua b/tests/examples/wibox/widget/progressbar/paddings2.lua new file mode 100644 index 00000000..06a22c0e --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/paddings2.lua @@ -0,0 +1,26 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE +local parent = ... +local wibox = require("wibox") + +--DOC_HIDE_END +local bg = --DOC_HIDE + wibox.widget { + paddings = { + top = 4, + bottom = 2, + right = 10, + left = 5 + }, + value = 1, + border_width = 2, + border_color = "#00ff00", + bar_border_wisth = 2, + bar_border_color = "#ffff00", + bor_color = "#ff00ff", + background = "#0000ff", + forced_width = 75, --DOC_HIDE + forced_height = 30, --DOC_HIDE + widget = wibox.widget.progressbar, + } +parent:add(bg) --DOC_HIDE +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/text.lua b/tests/examples/wibox/widget/progressbar/text.lua index c1f6ca91..92b5c7a6 100644 --- a/tests/examples/wibox/widget/progressbar/text.lua +++ b/tests/examples/wibox/widget/progressbar/text.lua @@ -18,6 +18,8 @@ parent:add( --DOC_HIDE }, { text = "50%", + valign = "center", + align = "center", widget = wibox.widget.textbox, }, layout = wibox.layout.stack diff --git a/tests/examples/wibox/widget/progressbar/ticks.lua b/tests/examples/wibox/widget/progressbar/ticks.lua new file mode 100644 index 00000000..2f86c40b --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/ticks.lua @@ -0,0 +1,36 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, has_ticks in ipairs { true, false } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + border_width = 2, + ticks = has_ticks, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = tostring(has_ticks), + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/ticks_gap.lua b/tests/examples/wibox/widget/progressbar/ticks_gap.lua new file mode 100644 index 00000000..5af4d5d5 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/ticks_gap.lua @@ -0,0 +1,37 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, gap in ipairs { 0, 2, 4, 6 } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + border_width = 2, + ticks = true, + ticks_gap = gap, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = gap, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/ticks_size.lua b/tests/examples/wibox/widget/progressbar/ticks_size.lua new file mode 100644 index 00000000..a290f9bb --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/ticks_size.lua @@ -0,0 +1,37 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END + for _, size in ipairs { 0, 2, 4, 6 } do + + local pb = --DOC_HIDE + wibox.widget { + value = 0.33, + border_width = 2, + ticks = true, + ticks_size = size, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = size, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END + end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/ticks_size2.lua b/tests/examples/wibox/widget/progressbar/ticks_size2.lua new file mode 100644 index 00000000..a2c7ca99 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/ticks_size2.lua @@ -0,0 +1,130 @@ +--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") + +local l1 = wibox.layout.fixed.horizontal() +local l2 = wibox.layout.fixed.horizontal() +local l3 = wibox.layout.fixed.horizontal() +l1.spacing = 5 +l2.spacing = 5 +l3.spacing = 5 + +--DOC_HIDE_END + for _, size in ipairs { 0, 2, 4, 6 } do + + -- Plane shapes. + local pb = --DOC_HIDE + wibox.widget { + value = 1, + border_width = 2, + ticks = true, + ticks_size = size, + ticks_gap = 3, + paddings = 2, + bar_shape = gears.shape.rounded_bar, + widget = wibox.widget.progressbar, + } + + --DOC_NEWLINE + + -- With a border for each shape. + local pb3 = --DOC_HIDE + wibox.widget { + value = 1, + border_width = 2, + ticks = true, + ticks_size = size, + ticks_gap = 3, + paddings = 2, + bar_shape = gears.shape.rounded_bar, + bor_border_width = 2, + bar_border_color = beautiful.border_color, + widget = wibox.widget.progressbar, + } + + --DOC_NEWLINE + + -- With a gradient. + local pb2 = --DOC_HIDE + wibox.widget { + color = { + type = "linear", + from = { 0 , 0 }, + to = { 65, 0 }, + stops = { + { 0 , "#0000ff" }, + { 0.75, "#0000ff" }, + { 1 , "#ff0000" } + } + }, + paddings = 2, + value = 1, + border_width = 2, + ticks = true, + ticks_size = size, + ticks_gap = 3, + bar_shape = gears.shape.rounded_bar, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l1:add(wibox.widget { + pb, + { + text = size, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + l2:add(wibox.widget { + pb3, + { + text = size, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + + l3:add(wibox.widget { + pb2, + { + { + { + { + text = size, + align = "center", + widget = wibox.widget.textbox, + }, + margins = 4, + widget = wibox.container.margin, + }, + bg = "#ffffff", + shape = gears.shape.circle, + widget = wibox.container.background, + }, + align = "center", + valign = "center", + widget = wibox.container.place, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + + --DOC_HIDE_END + end + +parent:add(l1) --DOC_HIDE +parent:add(l2) --DOC_HIDE +parent:add(l3) --DOC_HIDE +parent.spacing = 10 --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/wibox/widget/progressbar/value.lua b/tests/examples/wibox/widget/progressbar/value.lua new file mode 100644 index 00000000..aa9b3c15 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/value.lua @@ -0,0 +1,34 @@ +--DOC_GEN_IMAGE --DOC_HIDE_START +local parent = ... +local wibox = require("wibox") + +local l = wibox.layout.fixed.horizontal() +l.spacing = 5 + +--DOC_HIDE_END +for _, value in ipairs { 0, 0.2, 0.5, 1 } do + + local pb = --DOC_HIDE + wibox.widget { + value = value, + widget = wibox.widget.progressbar, + } + + --DOC_HIDE_START + l:add(wibox.widget { + pb, + { + text = value, + align = "center", + widget = wibox.widget.textbox, + }, + forced_height = 30, + forced_width = 75, + layout = wibox.layout.stack + }) + --DOC_HIDE_END +end + +parent:add(l) --DOC_HIDE + +--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80