From fa6d996c41d3e47c6815e1facfe4326788f8706e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 25 Nov 2012 19:16:31 +0100 Subject: [PATCH] widgets: Add some constructor arguments This saves space when constructing widgets, because some common cases can now be done in a single line of code. Signed-off-by: Uli Schlachter --- lib/wibox/widget/background.lua.in | 4 +++- lib/wibox/widget/imagebox.lua.in | 12 +++++++++++- lib/wibox/widget/textbox.lua.in | 10 +++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/wibox/widget/background.lua.in b/lib/wibox/widget/background.lua.in index cb123e9a0..474ee9628 100644 --- a/lib/wibox/widget/background.lua.in +++ b/lib/wibox/widget/background.lua.in @@ -94,7 +94,7 @@ function background:set_bgimage(image) self._emit_updated() end -local function new() +local function new(widget) local ret = base.make_widget() for k, v in pairs(background) do @@ -107,6 +107,8 @@ local function new() ret:emit_signal("widget::updated") end + ret:set_widget(widget) + return ret end diff --git a/lib/wibox/widget/imagebox.lua.in b/lib/wibox/widget/imagebox.lua.in index af61396b6..b59192b07 100644 --- a/lib/wibox/widget/imagebox.lua.in +++ b/lib/wibox/widget/imagebox.lua.in @@ -108,7 +108,10 @@ function imagebox:set_resize(allowed) end -- Returns a new imagebox -local function new() +-- @param image the image to display, may be nil +-- @param resize_allowed If false, the image will be clipped, else it will be resized +-- to fit into the available space. +local function new(image, resize_allowed) local ret = base.make_widget() for k, v in pairs(imagebox) do @@ -117,6 +120,13 @@ local function new() end end + if image then + ret:set_image(image) + end + if resize_allowed ~= nil then + ret:set_resize(resize_allowed) + end + return ret end diff --git a/lib/wibox/widget/textbox.lua.in b/lib/wibox/widget/textbox.lua.in index 2d664e2b5..7578f3e09 100644 --- a/lib/wibox/widget/textbox.lua.in +++ b/lib/wibox/widget/textbox.lua.in @@ -115,7 +115,7 @@ function textbox:set_font(font) end -- Returns a new textbox -local function new() +local function new(text, ignore_markup) local ret = base.make_widget() for k, v in pairs(textbox) do @@ -133,6 +133,14 @@ local function new() ret:set_align("left") ret:set_font() + if text then + if ignore_markup then + ret:set_text(text) + else + ret:set_markup(text) + end + end + return ret end