Fix Align Layout Fit Behavior
This changes the align layout fit function so that align:fit will not return more space than is actually needed by its sub-widgets. Changes to align:draw were also required so that any widget assigned to the middle slot will expand to fill the remaining space. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
c855b1babb
commit
ceaeaedb5b
|
@ -57,14 +57,10 @@ function align:draw(wibox, cr, width, height)
|
||||||
local x, y, w, h
|
local x, y, w, h
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
w, h = width, size_limit - size_first - size_third
|
w, h = width, size_limit - size_first - size_third
|
||||||
local real_w, real_h = base.fit_widget(self.second, w, h)
|
x, y = 0, size_first
|
||||||
x, y = 0, size_first + h / 2 - real_h / 2
|
|
||||||
h = real_h
|
|
||||||
else
|
else
|
||||||
w, h = size_limit - size_first - size_third, height
|
w, h = size_limit - size_first - size_third, height
|
||||||
local real_w, real_h = base.fit_widget(self.second, w, h)
|
x, y = size_first, 0
|
||||||
x, y = size_first + w / 2 - real_w / 2, 0
|
|
||||||
w = real_w
|
|
||||||
end
|
end
|
||||||
base.draw_widget(wibox, cr, self.second, x, y, w, h)
|
base.draw_widget(wibox, cr, self.second, x, y, w, h)
|
||||||
end
|
end
|
||||||
|
@ -100,27 +96,29 @@ function align:set_third(widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit the align layout into the given space. The align layout will
|
--- Fit the align layout into the given space. The align layout will
|
||||||
-- take all available space in its direction and the maximum size of
|
-- ask for the sum of the sizes of its sub-widgets in its direction
|
||||||
-- it's all three inner widgets in the other axis.
|
-- and the largest sized sub widget in the other direction.
|
||||||
-- @param orig_width The available width.
|
-- @param orig_width The available width.
|
||||||
-- @param orig_height The available height.
|
-- @param orig_height The available height.
|
||||||
function align:fit(orig_width, orig_height)
|
function align:fit(orig_width, orig_height)
|
||||||
local used_max = 0
|
local used_in_dir = 0
|
||||||
|
local used_in_other = 0
|
||||||
|
|
||||||
for k, v in pairs{self.first, self.second, self.third} do
|
for k, v in pairs{self.first, self.second, self.third} do
|
||||||
local w, h = base.fit_widget(v, orig_width, orig_height)
|
local w, h = base.fit_widget(v, orig_width, orig_height)
|
||||||
|
|
||||||
local max = self.dir == "y" and w or h
|
local max = self.dir == "y" and w or h
|
||||||
|
if max > used_in_other then
|
||||||
if max > used_max then
|
used_in_other = max
|
||||||
used_max = max
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
used_in_dir = used_in_dir + (self.dir == "y" and h or w)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
return used_max, orig_height
|
return used_in_other, used_in_dir
|
||||||
end
|
end
|
||||||
return orig_width, used_max
|
return used_in_dir, used_in_other
|
||||||
end
|
end
|
||||||
|
|
||||||
function align:reset()
|
function align:reset()
|
||||||
|
|
Loading…
Reference in New Issue