Add :set_{width,height} to widgets (#291)
This adds new functions to all widgets that allow to force a specific width/height. These values override the result from :fit(). Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
c2be60fb54
commit
f4077def8e
|
@ -51,6 +51,28 @@ function base.widget:set_opacity(o)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Set the widget's width
|
||||||
|
-- @tparam number|nil s The width that the widget has. `nil` means to apply the
|
||||||
|
-- default mechanism of calling the `:fit` method. A number overrides the result
|
||||||
|
-- from `:fit`.
|
||||||
|
function base.widget:set_width(s)
|
||||||
|
if s ~= self._forced_width then
|
||||||
|
self._forced_width = s
|
||||||
|
self:emit_signal("widget::layout_changed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set the widget's height
|
||||||
|
-- @tparam number|nil s The height that the widget has. `nil` means to apply the
|
||||||
|
-- default mechanism of calling the `:fit` method. A number overrides the result
|
||||||
|
-- from `:fit`.
|
||||||
|
function base.widget:set_height(s)
|
||||||
|
if s ~= self._forced_height then
|
||||||
|
self._forced_height = s
|
||||||
|
self:emit_signal("widget::layout_changed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- {{{ Caches
|
-- {{{ Caches
|
||||||
|
@ -141,6 +163,10 @@ function base.fit_widget(parent, context, widget, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Apply forced size
|
||||||
|
w = widget._forced_width or w
|
||||||
|
h = widget._forced_height or h
|
||||||
|
|
||||||
-- Also sanitize the output.
|
-- Also sanitize the output.
|
||||||
w = math.max(0, math.min(w, width))
|
w = math.max(0, math.min(w, width))
|
||||||
h = math.max(0, math.min(h, height))
|
h = math.max(0, math.min(h, height))
|
||||||
|
@ -394,6 +420,10 @@ function base.make_widget(proxy, widget_name)
|
||||||
-- Widget is fully opaque
|
-- Widget is fully opaque
|
||||||
ret.opacity = 1
|
ret.opacity = 1
|
||||||
|
|
||||||
|
-- Size is not restricted/forced
|
||||||
|
ret._forced_width = nil
|
||||||
|
ret._forced_height = nil
|
||||||
|
|
||||||
-- Make buttons work
|
-- Make buttons work
|
||||||
ret:connect_signal("button::press", function(...)
|
ret:connect_signal("button::press", function(...)
|
||||||
return base.handle_button("press", ...)
|
return base.handle_button("press", ...)
|
||||||
|
|
Loading…
Reference in New Issue