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 <psychon@znc.in>
This commit is contained in:
parent
2badbed440
commit
fa6d996c41
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue