Merge branch 'layout_spacing' of git://github.com/Elv13/awesome-1
This commit is contained in:
commit
6f992f13b0
|
@ -19,7 +19,7 @@ local fixed = {}
|
||||||
-- @param height The available height.
|
-- @param height The available height.
|
||||||
-- @return The total space needed by the layout.
|
-- @return The total space needed by the layout.
|
||||||
function fixed:draw(wibox, cr, width, height)
|
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
|
for k, v in pairs(self.widgets) do
|
||||||
local x, y, w, h, _
|
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
|
if k ~= #self.widgets or not self._fill_space then
|
||||||
_, h = base.fit_widget(v, w, h);
|
_, h = base.fit_widget(v, w, h);
|
||||||
end
|
end
|
||||||
pos = pos + h
|
pos = pos + h + spacing
|
||||||
in_dir = h
|
in_dir = h
|
||||||
else
|
else
|
||||||
x, y = pos, 0
|
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
|
if k ~= #self.widgets or not self._fill_space then
|
||||||
w, _ = base.fit_widget(v, w, h);
|
w, _ = base.fit_widget(v, w, h);
|
||||||
end
|
end
|
||||||
pos = pos + w
|
pos = pos + w + spacing
|
||||||
in_dir = w
|
in_dir = w
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.dir == "y" and pos > height) or
|
if (self.dir == "y" and pos-spacing > height) or
|
||||||
(self.dir ~= "y" and pos > width) then
|
(self.dir ~= "y" and pos-spacing > width) then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
base.draw_widget(wibox, cr, v, x, y, w, h)
|
base.draw_widget(wibox, cr, v, x, y, w, h)
|
||||||
|
@ -90,10 +90,12 @@ function fixed:fit(orig_width, orig_height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local spacing = ((self._spacing or 0)*(#self.widgets-1))
|
||||||
|
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
return used_max, used_in_dir
|
return used_max, used_in_dir + spacing
|
||||||
end
|
end
|
||||||
return used_in_dir, used_max
|
return used_in_dir + spacing, used_max
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Reset a fixed layout. This removes all widgets from the layout.
|
--- Reset a fixed layout. This removes all widgets from the layout.
|
||||||
|
@ -145,6 +147,12 @@ function fixed.vertical()
|
||||||
return get_layout("y")
|
return get_layout("y")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Add spacing between each layout widgets
|
||||||
|
function fixed:set_spacing(spacing)
|
||||||
|
self._spacing = spacing
|
||||||
|
self:emit_signal("widget::updated")
|
||||||
|
end
|
||||||
|
|
||||||
return fixed
|
return fixed
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
|
@ -24,14 +24,15 @@ end
|
||||||
-- @param height The available height.
|
-- @param height The available height.
|
||||||
-- @return The total space needed by the layout.
|
-- @return The total space needed by the layout.
|
||||||
function flex:draw(wibox, cr, width, height)
|
function flex:draw(wibox, cr, width, height)
|
||||||
local pos = 0
|
local pos,spacing = 0,self._spacing or 0
|
||||||
|
|
||||||
local num = #self.widgets
|
local num = #self.widgets
|
||||||
|
local total_spacing = (spacing*(num-1))
|
||||||
|
|
||||||
local space_per_item
|
local space_per_item
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
space_per_item = height / num
|
space_per_item = height / num - total_spacing/num
|
||||||
else
|
else
|
||||||
space_per_item = width / num
|
space_per_item = width / num - total_spacing/num
|
||||||
end
|
end
|
||||||
|
|
||||||
if self._max_widget_size then
|
if self._max_widget_size then
|
||||||
|
@ -49,10 +50,10 @@ function flex:draw(wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
base.draw_widget(wibox, cr, v, x, y, w, h)
|
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
|
if (self.dir == "y" and pos-spacing >= height) or
|
||||||
(self.dir ~= "y" and pos >= width) then
|
(self.dir ~= "y" and pos-spacing >= width) then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -100,10 +101,12 @@ function flex:fit(orig_width, orig_height)
|
||||||
#self.widgets * self._max_widget_size)
|
#self.widgets * self._max_widget_size)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local spacing = ((self._spacing or 0)*(#self.widgets-1))
|
||||||
|
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
return used_in_other, used_in_dir
|
return used_in_other, used_in_dir + spacing
|
||||||
end
|
end
|
||||||
return used_in_dir, used_in_other
|
return used_in_dir + spacing, used_in_other
|
||||||
end
|
end
|
||||||
|
|
||||||
function flex:reset()
|
function flex:reset()
|
||||||
|
@ -145,6 +148,12 @@ function flex.vertical()
|
||||||
return get_layout("y")
|
return get_layout("y")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Add spacing between each layout widgets
|
||||||
|
function flex:set_spacing(spacing)
|
||||||
|
self._spacing = spacing
|
||||||
|
self:emit_signal("widget::updated")
|
||||||
|
end
|
||||||
|
|
||||||
return flex
|
return flex
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue