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
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue