From f6d9443c5d942877a5f6e1da8f1436bf962e6d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= Date: Sat, 5 Jan 2013 16:12:48 +0100 Subject: [PATCH] wibox.layout.flex: fix the fit function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fit function of the flex layout is different from the fixed.fit one. Signed-off-by: Lukáš Hrázký Signed-off-by: Uli Schlachter --- lib/wibox/layout/flex.lua.in | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/wibox/layout/flex.lua.in b/lib/wibox/layout/flex.lua.in index a0a0cf1d..96363163 100644 --- a/lib/wibox/layout/flex.lua.in +++ b/lib/wibox/layout/flex.lua.in @@ -5,7 +5,6 @@ --------------------------------------------------------------------------- local base = require("wibox.layout.base") -local fixed = require("wibox.layout.fixed") local widget_base = require("wibox.widget.base") local table = table local pairs = pairs @@ -18,8 +17,6 @@ local function round(x) return floor(x + 0.5) end -flex.fit = fixed.fit - --- Draw a flex layout. Each widget gets an equal share of the available space. -- @param wibox The wibox that this widget is drawn to. -- @param cr The cairo context to use. @@ -64,6 +61,31 @@ function flex:add(widget) self._emit_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 + + for k, v in pairs(self.widgets) do + local w, h = v:fit(orig_width, orig_height) + local max + if self.dir == "y" then + max = w + else + max = h + end + if max > used_max then + used_max = max + end + end + + if self.dir == "y" then + return used_max, orig_height + end + return orig_width, used_max +end + function flex:reset() for k, v in pairs(self.widgets) do v:disconnect_signal("widget::updated", self._emit_updated)