progressbar: Make `ticks` and `bar_shape` compatible with each other.
It looked horrible/buggy when combined. Now it looks like people would expect it to work. Another problem was the `bar_border_width` look when `ticks` was `true.
This commit is contained in:
parent
0afb719f82
commit
76704b33e7
|
@ -165,6 +165,10 @@ local progressbar = { mt = {} }
|
|||
--
|
||||
-- @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[opt=4] number ticks_size
|
||||
-- @propemits true false
|
||||
|
@ -428,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
|
||||
|
@ -444,6 +448,29 @@ 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)
|
||||
|
||||
if pbar._private.ticks and explicit_bar_shape then
|
||||
local tr_off = 0
|
||||
|
||||
-- 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"))
|
||||
|
||||
cr:fill()
|
||||
else
|
||||
bar_shape(cr, rel_x, over_drawn_height)
|
||||
|
||||
cr:set_source(color(pbar._private.color or beautiful.progressbar_fg or "#ff0000"))
|
||||
|
@ -456,8 +483,11 @@ function progressbar.draw(pbar, _, cr, width, height)
|
|||
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
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
--DOC_GEN_IMAGE --DOC_HIDE_START
|
||||
--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE
|
||||
local parent = ...
|
||||
local wibox = require("wibox")
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue