Hi, 
I wrote the initial simple ticks implementation for awful.widget. To 
have a chance of inclusion in awful it needs your help. The multigraph 
by Andreas Kloeckner nobody touched to this day and I hope ticks don't 
end up the same.

When the progressbar widget was ported to Lua it was so much simpler 
then the C one. It would be good it remains like that, so I thought some 
ticks are better then no ticks at all... and this is what I wrote;

- Calling set_ticks(true) enables ticks for a progressbar
- They are drawn only over the filled part of the progressbar

The attached patch will draw ticks of 1px in gaps of 1px. You can see a 
picture with fill and gradient: http://sysphere.org/~anrxc/picture.png


For vertical progressbars in sizes from 10-30 the 1px tick in distance 
of 1px looks OK, distance of 2 is also OK (maybe even the best including 
for horizontal progressbars)... This right there covers 80% of all 
progressbar usage. But;

If someone draws a huge progressbar just because he can, or what ever 
else, awesome can not draw a 2px tick - code needs to be of a higher 
standard and I am not sure I can deliver it, so I'm asking for help.

Should the code automatically calculate the average tick and gap size 
based on the progressbar size? Because some ticks are better than no 
ticks, and simple (design) is better than complex. Some people I talked 
to say this is too complex (code wise), and that it would require 
constant maintenance.

Should then the progressbar implementation allow the control of the 
number of ticks and the size of the gaps (just like the old C one did)? 
This helps with code complexity, but complicates implementation.

Improve the code, add features, reimplement, do anything. Let's get 
ticks back into awesome, please. Thank you!

-- 
Adrian C. (anrxc) | anrxc..sysphere.org | PGP ID: D20A0618
PGP FP: 02A5 628A D8EE 2A93 996E  929F D5CB 31B7 D20A 0618

Attachment: signature.asc
Description: PGP signature

From d21b5e380a029a34237cebaebc475061a2115a07 Mon Sep 17 00:00:00 2001
From: Adrian C. (anrxc) <an...@sysphere.org>
Date: Sun, 28 Feb 2010 21:25:06 +0100
Subject: [PATCH] awful.widget: add progressbar ticks property

Initial implementation of progressbar ticks.

Signed-off-by: Adrian C. (anrxc) <an...@sysphere.org>
---
 lib/awful/widget/progressbar.lua.in |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/lib/awful/widget/progressbar.lua.in 
b/lib/awful/widget/progressbar.lua.in
index d32ca6d..8d3ff58 100644
--- a/lib/awful/widget/progressbar.lua.in
+++ b/lib/awful/widget/progressbar.lua.in
@@ -49,9 +49,15 @@ local data = setmetatable({}, { __mode = "k" })
 -- @param progressbar The progressbar.
 -- @param vertical A boolean value.
 
+--- Set the progressbar to draw ticks. Default is false.
+-- @name set_ticks
+-- @class function
+-- @param progressbar The progressbar.
+-- @param ticks A boolean value.
+
 local properties = { "width", "height", "border_color",
                      "gradient_colors", "color", "background_color",
-                     "vertical", "value" }
+                     "vertical", "ticks", "value" }
 
 local function update(pbar)
     local width = data[pbar].width or 100
@@ -95,6 +101,19 @@ local function update(pbar)
                            over_drawn_width,
                            rel_height,
                            true, data[pbar].background_color or "#000000aa")
+
+        -- Place smaller pieces over the gradient if ticks are enabled
+        if data[pbar].ticks then
+            local rel_border = border_width < 1 and 1 or border_width
+            for i = 1, math.floor((over_drawn_height - rel_height) / 2) do
+                local rel_offset = (rel_height - rel_border) + (i * 2)
+                img:draw_rectangle(border_width,
+                                   rel_offset,
+                                   over_drawn_width,
+                                   1,
+                                   true, data[pbar].background_color or 
"#000000aa")
+            end
+        end
     else
         local rel_x = math.floor((over_drawn_width * data[pbar].value) + 0.5)
         img:draw_rectangle(border_width + rel_x,
@@ -102,6 +121,18 @@ local function update(pbar)
                            over_drawn_width - rel_x,
                            over_drawn_height,
                            true, data[pbar].background_color or "#000000aa")
+
+        if data[pbar].ticks then
+            local rel_border = border_width < 1 and border_width or -1
+            for i = 1, math.floor((border_width + rel_x) / 2) do
+                local rel_offset = (rel_x - rel_border) - (i * 2)
+                img:draw_rectangle(rel_offset,
+                                   border_width,
+                                   1,
+                                   over_drawn_height,
+                                   true, data[pbar].background_color or 
"#000000aa")
+            end
+        end
     end
 
     -- Update the image
-- 
1.7.0

Reply via email to