wibox.layout.flex: fix the fit function

The fit function of the flex layout is different from the fixed.fit one.

Signed-off-by: Lukáš Hrázký <lukkash@email.cz>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Lukáš Hrázký 2013-01-05 16:12:48 +01:00 committed by Uli Schlachter
parent 9d333113dd
commit f6d9443c5d
1 changed files with 25 additions and 3 deletions

View File

@ -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)