From 1881ceb9d3de9b52967cef2a024cd0737d80568d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= Date: Sun, 20 Jan 2013 15:00:28 +0100 Subject: [PATCH] wibox.layout.flex: add set_max_widget_size() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function can be used to set the maximum size the widget in the flex layout should take. Signed-off-by: Lukáš Hrázký Signed-off-by: Uli Schlachter --- lib/wibox/layout/flex.lua.in | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/wibox/layout/flex.lua.in b/lib/wibox/layout/flex.lua.in index 96363163..9fe2a457 100644 --- a/lib/wibox/layout/flex.lua.in +++ b/lib/wibox/layout/flex.lua.in @@ -34,6 +34,10 @@ function flex:draw(wibox, cr, width, height) space_per_item = width / num end + if self._max_widget_size then + space_per_item = math.min(space_per_item, self._max_widget_size) + end + for k, v in pairs(self.widgets) do local x, y, w, h if self.dir == "y" then @@ -61,11 +65,25 @@ function flex:add(widget) self._emit_updated() end +--- Set the maximum size the widgets in this layout will take (that is, +-- maximum width for horizontal and maximum height for vertical). +-- @param val The maximum size of the widget. +function flex:set_max_widget_size(val) + self._max_widget_size = val + self:emit_signal("widget::updated") +end + --- Fit the flex layout into the given space. -- @param orig_width The available width. -- @param orig_height The available height. function flex:fit(orig_width, orig_height) local used_max = 0 + local used_in_dir = self.dir == "y" and orig_height or orig_width + + if self._max_widget_size then + used_in_dir = math.min(used_in_dir, + #self.widgets * self._max_widget_size) + end for k, v in pairs(self.widgets) do local w, h = v:fit(orig_width, orig_height) @@ -81,9 +99,9 @@ function flex:fit(orig_width, orig_height) end if self.dir == "y" then - return used_max, orig_height + return used_max, used_in_dir end - return orig_width, used_max + return used_in_dir, used_max end function flex:reset() @@ -91,6 +109,7 @@ function flex:reset() v:disconnect_signal("widget::updated", self._emit_updated) end self.widgets = {} + self._max_widget_size = nil self:emit_signal("widget::updated") end