Hi,
attached are 2 patches.
First fixes an issue with graph always drawing 1 px lower than it
should have (so the vertical lines were drawn 1px shorter and the top
pixel was never filled). It also changes the rounding of progressbar
and graph values from math.floor(value) to math.floor(value + 0.5),
making it a regular round(). That makes them more accurate.
Second removes the requirement for minimal progressbar size 5px. I
don't see why it shouldn't be possible, if there is a reason, please
tell me. I left the limit for graph, because such a small graph is
pointless anyway, but 1 px progressbar is quite cool :).
cheers
lukash
>From 452085877f2b3185d1b31c2f724a0737bdb35760 Mon Sep 17 00:00:00 2001
From: Lukas Hrazky <[email protected]>
Date: Sun, 25 Oct 2009 12:59:25 +0100
Subject: [PATCH 1/2] progressbar/graph: fix rounding and graph drawing
Signed-off-by: Lukas Hrazky <[email protected]>
---
lib/awful/widget/graph.lua.in | 5 +++--
lib/awful/widget/progressbar.lua.in | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/awful/widget/graph.lua.in b/lib/awful/widget/graph.lua.in
index a65647d..1841a0c 100644
--- a/lib/awful/widget/graph.lua.in
+++ b/lib/awful/widget/graph.lua.in
@@ -112,9 +112,10 @@ local function update(graph)
if value >= 0 then
value = value / max_value
img:draw_line(data[graph].width - border_width - i - 1,
- border_width + ((data[graph].height - 2 * border_width) * (1 - value)),
+ border_width - 1 +
+ math.floor(((data[graph].height - 2 * border_width) * (1 - value)) + 0.5),
data[graph].width - border_width - i - 1,
- border_width,
+ border_width - 1,
data[graph].background_color or "#000000aa")
end
end
diff --git a/lib/awful/widget/progressbar.lua.in b/lib/awful/widget/progressbar.lua.in
index c12e7b9..761e786 100644
--- a/lib/awful/widget/progressbar.lua.in
+++ b/lib/awful/widget/progressbar.lua.in
@@ -98,7 +98,7 @@ local function update(pbar)
rel_height,
true, data[pbar].background_color or "#000000aa")
else
- local rel_x = math.floor(over_drawn_width * data[pbar].value)
+ local rel_x = math.floor((over_drawn_width * data[pbar].value) + 0.5)
img:draw_rectangle(border_width + rel_x,
border_width,
over_drawn_width - rel_x,
--
1.6.5
>From 1ce6dfb6a6994018d39ed0db454e684ad7f9e189 Mon Sep 17 00:00:00 2001
From: Lukas Hrazky <[email protected]>
Date: Sun, 25 Oct 2009 21:15:54 +0100
Subject: [PATCH 2/2] progressbar: remove minimum size limit
Signed-off-by: Lukas Hrazky <[email protected]>
---
lib/awful/widget/progressbar.lua.in | 16 ++++------------
1 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/lib/awful/widget/progressbar.lua.in b/lib/awful/widget/progressbar.lua.in
index 761e786..bd10bc0 100644
--- a/lib/awful/widget/progressbar.lua.in
+++ b/lib/awful/widget/progressbar.lua.in
@@ -57,8 +57,6 @@ local function update(pbar)
local width = data[pbar].width or 100
local height = data[pbar].height or 20
- if data[pbar].width < 5 or data[pbar].height < 2 then return end
-
-- Create new empty image
local img = capi.image.argb32(width, height, nil)
@@ -124,10 +122,8 @@ end
-- @param progressbar The progressbar.
-- @param height The height to set.
function set_height(progressbar, height)
- if height >= 5 then
- data[progressbar].height = height
- update(progressbar)
- end
+ data[progressbar].height = height
+ update(progressbar)
return progressbar
end
@@ -135,10 +131,8 @@ end
-- @param progressbar The progressbar.
-- @param width The width to set.
function set_width(progressbar, width)
- if width >= 5 then
- data[progressbar].width = width
- update(progressbar)
- end
+ data[progressbar].width = width
+ update(progressbar)
return progressbar
end
@@ -162,8 +156,6 @@ function new(args)
local width = args.width or 100
local height = args.height or 20
- if width < 5 or height < 5 then return end
-
args.type = "imagebox"
local pbar = {}
--
1.6.5