From e38651bafb540e29c5c10d6efaea5b9c73f7edf0 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:49 +0100 Subject: [PATCH] wibox.layout.align: don't take up all space in the other axis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a fit function to the align layout that makes sure that the layout will not take up all the available space in the other axis than it's direction. Eg. for horizontal align layout, it will only take up the maximum of its widgets' heights in the vertical axis. Signed-off-by: Lukáš Hrázký Signed-off-by: Uli Schlachter --- lib/wibox/layout/align.lua.in | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/wibox/layout/align.lua.in b/lib/wibox/layout/align.lua.in index efc8c27d..d4a95176 100644 --- a/lib/wibox/layout/align.lua.in +++ b/lib/wibox/layout/align.lua.in @@ -95,6 +95,30 @@ function align:set_third(widget) self.third = widget end +--- Fit the align layout into the given space. The align layout will +-- take all available space in its direction and the maximum size of +-- it's all three inner widgets in the other axis. +-- @param orig_width The available width. +-- @param orig_height The available height. +function align:fit(orig_width, orig_height) + local used_max = 0 + + for k, v in pairs{self.first, self.second, self.third} do + local w, h = v:fit(orig_width, orig_height) + + local max = self.dir == "y" and w or h + + 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 align:reset() for k, v in pairs({ "first", "second", "third" }) do self[v] = nil @@ -104,7 +128,6 @@ end local function get_layout(dir) local ret = widget_base.make_widget() - ret.fit = function(box, ...) return ... end ret.dir = dir ret._emit_updated = function() ret:emit_signal("widget::updated")