wibox.layout: Add fixed and flex layouts widget spacing property

This commit is contained in:
Emmanuel Lepage Vallee 2014-10-18 01:17:46 -04:00
parent dd2f805e09
commit 848aadf95c
2 changed files with 33 additions and 16 deletions

View File

@ -19,7 +19,7 @@ local fixed = {}
-- @param height The available height.
-- @return The total space needed by the layout.
function fixed:draw(wibox, cr, width, height)
local pos = 0
local pos,spacing = 0,self._spacing or 0
for k, v in pairs(self.widgets) do
local x, y, w, h, _
@ -30,7 +30,7 @@ function fixed:draw(wibox, cr, width, height)
if k ~= #self.widgets or not self._fill_space then
_, h = base.fit_widget(v, w, h);
end
pos = pos + h
pos = pos + h + spacing
in_dir = h
else
x, y = pos, 0
@ -38,12 +38,12 @@ function fixed:draw(wibox, cr, width, height)
if k ~= #self.widgets or not self._fill_space then
w, _ = base.fit_widget(v, w, h);
end
pos = pos + w
pos = pos + w + spacing
in_dir = w
end
if (self.dir == "y" and pos > height) or
(self.dir ~= "y" and pos > width) then
if (self.dir == "y" and pos-spacing > height) or
(self.dir ~= "y" and pos-spacing > width) then
break
end
base.draw_widget(wibox, cr, v, x, y, w, h)
@ -90,10 +90,12 @@ function fixed:fit(orig_width, orig_height)
end
end
local spacing = ((self._spacing or 0)*(#self.widgets-1))
if self.dir == "y" then
return used_max, used_in_dir
return used_max, used_in_dir + spacing
end
return used_in_dir, used_max
return used_in_dir + spacing, used_max
end
--- Reset a fixed layout. This removes all widgets from the layout.
@ -145,6 +147,12 @@ function fixed.vertical()
return get_layout("y")
end
-- Add spacing between each layout widgets
function fixed:set_spacing(spacing)
self._spacing = spacing
self:emit_signal("widget::updated")
end
return fixed
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -24,14 +24,15 @@ end
-- @param height The available height.
-- @return The total space needed by the layout.
function flex:draw(wibox, cr, width, height)
local pos = 0
local pos,spacing = 0,self._spacing or 0
local num = #self.widgets
local total_spacing = (spacing*(num-1))
local space_per_item
if self.dir == "y" then
space_per_item = height / num
space_per_item = height / num - total_spacing/num
else
space_per_item = width / num
space_per_item = width / num - total_spacing/num
end
if self._max_widget_size then
@ -49,10 +50,10 @@ function flex:draw(wibox, cr, width, height)
end
base.draw_widget(wibox, cr, v, x, y, w, h)
pos = pos + space_per_item
pos = pos + space_per_item + spacing
if (self.dir == "y" and pos >= height) or
(self.dir ~= "y" and pos >= width) then
if (self.dir == "y" and pos-spacing >= height) or
(self.dir ~= "y" and pos-spacing >= width) then
break
end
end
@ -100,10 +101,12 @@ function flex:fit(orig_width, orig_height)
#self.widgets * self._max_widget_size)
end
local spacing = ((self._spacing or 0)*(#self.widgets-1))
if self.dir == "y" then
return used_in_other, used_in_dir
return used_in_other, used_in_dir + spacing
end
return used_in_dir, used_in_other
return used_in_dir + spacing, used_in_other
end
function flex:reset()
@ -145,6 +148,12 @@ function flex.vertical()
return get_layout("y")
end
-- Add spacing between each layout widgets
function flex:set_spacing(spacing)
self._spacing = spacing
self:emit_signal("widget::updated")
end
return flex
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80