wibox.layout.align: Correctly size second widget

In expand nodes "none" and "outside", the variable size_remains describes how
much space is available for the first/third widget. Everything else is used by
the second widget. Thus, fitting the second widget to anything involving
size_remains is wrong. Instead, this commit uses the correct value.

This also fixes a messed up argument order for horizontal align layouts.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2015-08-13 15:42:39 +02:00
parent 769d6acb64
commit 3fbd16d9a3
1 changed files with 6 additions and 3 deletions

View File

@ -31,6 +31,9 @@ function align:draw(context, cr, width, height)
local size_first = 0 local size_first = 0
-- start with all the space given by the parent, subtract as we go along -- start with all the space given by the parent, subtract as we go along
local size_remains = self.dir == "y" and height or width local size_remains = self.dir == "y" and height or width
-- This is only set & used if expand ~= "inside" and we have second width.
-- It contains the size allocated to the second widget.
local size_second
-- we will prioritize the middle widget unless the expand mode is "inside" -- we will prioritize the middle widget unless the expand mode is "inside"
-- if it is, we prioritize the first widget by not doing this block also, -- if it is, we prioritize the first widget by not doing this block also,
@ -38,7 +41,7 @@ function align:draw(context, cr, width, height)
-- instead -- instead
if self._expand ~= "inside" and self.second then if self._expand ~= "inside" and self.second then
local w, h = base.fit_widget(context, self.second, width, height) local w, h = base.fit_widget(context, self.second, width, height)
local size_second = self.dir == "y" and h or w size_second = self.dir == "y" and h or w
-- if all the space is taken, skip the rest, and draw just the middle -- if all the space is taken, skip the rest, and draw just the middle
-- widget -- widget
if size_second >= size_remains then if size_second >= size_remains then
@ -123,10 +126,10 @@ function align:draw(context, cr, width, height)
end end
else else
if self.dir == "y" then if self.dir == "y" then
_, h = base.fit_widget(context, self.second, width, size_remains) _, h = base.fit_widget(context, self.second, width, size_second)
y = floor( (height - h)/2 ) y = floor( (height - h)/2 )
else else
w, _ = base.fit_widget(context, self.second, width, size_remains) w, _ = base.fit_widget(context, self.second, size_second, height)
x = floor( (width -w)/2 ) x = floor( (width -w)/2 )
end end
end end