From f93c91cd1b88c59507a0d89b00a73902666987bd Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 8 Aug 2009 15:47:00 +0200 Subject: [PATCH] lib.awful.widget: Return obj in set_* methods This change enables stuff like the following: awful.widget.graph({}):set_color("red"):set_width(40):add_value(0.5) Additionally, one can use the above directly in th widgets table. This most likely doesn't break any existing configs and it adds a quite nice syntax which can be used for in-place configuration of new widgets. Signed-off-by: Uli Schlachter Signed-off-by: Julien Danjou --- lib/awful/widget/graph.lua.in | 4 ++++ lib/awful/widget/progressbar.lua.in | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/awful/widget/graph.lua.in b/lib/awful/widget/graph.lua.in index 4802a0dd5..7ef756b93 100644 --- a/lib/awful/widget/graph.lua.in +++ b/lib/awful/widget/graph.lua.in @@ -164,6 +164,7 @@ local function add_value(graph, value) end update(graph) + return graph end @@ -175,6 +176,7 @@ local function set_height(graph, height) data[graph].height = height update(graph) end + return graph end --- Set the graph width. @@ -185,6 +187,7 @@ local function set_width(graph, width) data[graph].width = width update(graph) end + return graph end -- Build properties function @@ -193,6 +196,7 @@ for _, prop in ipairs(properties) do _M["set_" .. prop] = function(graph, value) data[graph][prop] = value update(graph) + return graph end end end diff --git a/lib/awful/widget/progressbar.lua.in b/lib/awful/widget/progressbar.lua.in index 652a94955..75111e418 100644 --- a/lib/awful/widget/progressbar.lua.in +++ b/lib/awful/widget/progressbar.lua.in @@ -116,6 +116,7 @@ end local function set_value(pbar, value) local value = value or 0 data[pbar].value = math.min(1, math.max(0, value)) + return pbar end --- Set the progressbar height. @@ -126,6 +127,7 @@ local function set_height(progressbar, height) data[progressbar].height = height update(progressbar) end + return progressbar end --- Set the progressbar width. @@ -136,6 +138,7 @@ local function set_width(progressbar, width) data[progressbar].width = width update(progressbar) end + return progressbar end -- Build properties function @@ -144,6 +147,7 @@ for _, prop in ipairs(properties) do _M["set_" .. prop] = function(pbar, value) data[pbar][prop] = value update(pbar) + return pbar end end end