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 <psychon@znc.in> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
8b36cb7ce4
commit
f93c91cd1b
|
@ -164,6 +164,7 @@ local function add_value(graph, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
update(graph)
|
update(graph)
|
||||||
|
return graph
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,6 +176,7 @@ local function set_height(graph, height)
|
||||||
data[graph].height = height
|
data[graph].height = height
|
||||||
update(graph)
|
update(graph)
|
||||||
end
|
end
|
||||||
|
return graph
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the graph width.
|
--- Set the graph width.
|
||||||
|
@ -185,6 +187,7 @@ local function set_width(graph, width)
|
||||||
data[graph].width = width
|
data[graph].width = width
|
||||||
update(graph)
|
update(graph)
|
||||||
end
|
end
|
||||||
|
return graph
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Build properties function
|
-- Build properties function
|
||||||
|
@ -193,6 +196,7 @@ for _, prop in ipairs(properties) do
|
||||||
_M["set_" .. prop] = function(graph, value)
|
_M["set_" .. prop] = function(graph, value)
|
||||||
data[graph][prop] = value
|
data[graph][prop] = value
|
||||||
update(graph)
|
update(graph)
|
||||||
|
return graph
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -116,6 +116,7 @@ end
|
||||||
local function set_value(pbar, value)
|
local function set_value(pbar, value)
|
||||||
local value = value or 0
|
local value = value or 0
|
||||||
data[pbar].value = math.min(1, math.max(0, value))
|
data[pbar].value = math.min(1, math.max(0, value))
|
||||||
|
return pbar
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the progressbar height.
|
--- Set the progressbar height.
|
||||||
|
@ -126,6 +127,7 @@ local function set_height(progressbar, height)
|
||||||
data[progressbar].height = height
|
data[progressbar].height = height
|
||||||
update(progressbar)
|
update(progressbar)
|
||||||
end
|
end
|
||||||
|
return progressbar
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the progressbar width.
|
--- Set the progressbar width.
|
||||||
|
@ -136,6 +138,7 @@ local function set_width(progressbar, width)
|
||||||
data[progressbar].width = width
|
data[progressbar].width = width
|
||||||
update(progressbar)
|
update(progressbar)
|
||||||
end
|
end
|
||||||
|
return progressbar
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Build properties function
|
-- Build properties function
|
||||||
|
@ -144,6 +147,7 @@ for _, prop in ipairs(properties) do
|
||||||
_M["set_" .. prop] = function(pbar, value)
|
_M["set_" .. prop] = function(pbar, value)
|
||||||
data[pbar][prop] = value
|
data[pbar][prop] = value
|
||||||
update(pbar)
|
update(pbar)
|
||||||
|
return pbar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue