fixed layout: Test signal emission
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
0e7ae1cb25
commit
dcd4db69e6
|
@ -17,7 +17,7 @@ local fixed = {}
|
||||||
-- @param height The available height.
|
-- @param height The available height.
|
||||||
function fixed:layout(context, width, height)
|
function fixed:layout(context, width, height)
|
||||||
local result = {}
|
local result = {}
|
||||||
local pos,spacing = 0,self._spacing or 0
|
local pos,spacing = 0, self._spacing
|
||||||
|
|
||||||
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, _
|
||||||
|
@ -89,7 +89,7 @@ function fixed:fit(context, orig_width, orig_height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local spacing = ((self._spacing or 0)*(#self.widgets-1))
|
local spacing = self._spacing * (#self.widgets-1)
|
||||||
|
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
return used_max, used_in_dir + spacing
|
return used_max, used_in_dir + spacing
|
||||||
|
@ -107,8 +107,10 @@ end
|
||||||
-- widget will get all the space that is left. If this is false, the last widget
|
-- widget will get all the space that is left. If this is false, the last widget
|
||||||
-- won't be handled specially and there can be space left unused.
|
-- won't be handled specially and there can be space left unused.
|
||||||
function fixed:fill_space(val)
|
function fixed:fill_space(val)
|
||||||
self._fill_space = val
|
if self._fill_space ~= val then
|
||||||
self:emit_signal("widget::layout_changed")
|
self._fill_space = not not val
|
||||||
|
self:emit_signal("widget::layout_changed")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_layout(dir)
|
local function get_layout(dir)
|
||||||
|
@ -122,6 +124,8 @@ local function get_layout(dir)
|
||||||
|
|
||||||
ret.dir = dir
|
ret.dir = dir
|
||||||
ret.widgets = {}
|
ret.widgets = {}
|
||||||
|
ret:set_spacing(0)
|
||||||
|
ret:fill_space(false)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
@ -143,8 +147,10 @@ end
|
||||||
--- Add spacing between each layout widgets
|
--- Add spacing between each layout widgets
|
||||||
-- @param spacing Spacing between widgets.
|
-- @param spacing Spacing between widgets.
|
||||||
function fixed:set_spacing(spacing)
|
function fixed:set_spacing(spacing)
|
||||||
self._spacing = spacing
|
if self._spacing ~= spacing then
|
||||||
self:emit_signal("widget::layout_changed")
|
self._spacing = spacing
|
||||||
|
self:emit_signal("widget::layout_changed")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return fixed
|
return fixed
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
local fixed = require("wibox.layout.fixed")
|
local fixed = require("wibox.layout.fixed")
|
||||||
|
local base = require("wibox.widget.base")
|
||||||
local utils = require("wibox.test_utils")
|
local utils = require("wibox.test_utils")
|
||||||
local p = require("wibox.widget.base").place_widget_at
|
local p = require("wibox.widget.base").place_widget_at
|
||||||
|
|
||||||
|
@ -76,6 +77,59 @@ describe("wibox.layout.fixed", function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("emitting signals", function()
|
||||||
|
local layout_changed
|
||||||
|
before_each(function()
|
||||||
|
layout:connect_signal("widget::layout_changed", function()
|
||||||
|
layout_changed = layout_changed + 1
|
||||||
|
end)
|
||||||
|
layout_changed = 0
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("add", function()
|
||||||
|
local w1, w2 = base.empty_widget(), base.empty_widget()
|
||||||
|
assert.is.equal(layout_changed, 0)
|
||||||
|
layout:add(w1)
|
||||||
|
assert.is.equal(layout_changed, 1)
|
||||||
|
layout:add(w2)
|
||||||
|
assert.is.equal(layout_changed, 2)
|
||||||
|
layout:add(w2)
|
||||||
|
assert.is.equal(layout_changed, 3)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("set_spacing", function()
|
||||||
|
assert.is.equal(layout_changed, 0)
|
||||||
|
layout:set_spacing(0)
|
||||||
|
assert.is.equal(layout_changed, 0)
|
||||||
|
layout:set_spacing(5)
|
||||||
|
assert.is.equal(layout_changed, 1)
|
||||||
|
layout:set_spacing(2)
|
||||||
|
assert.is.equal(layout_changed, 2)
|
||||||
|
layout:set_spacing(2)
|
||||||
|
assert.is.equal(layout_changed, 2)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("reset", function()
|
||||||
|
assert.is.equal(layout_changed, 0)
|
||||||
|
layout:add(base.make_widget())
|
||||||
|
assert.is.equal(layout_changed, 1)
|
||||||
|
layout:reset()
|
||||||
|
assert.is.equal(layout_changed, 2)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("fill_space", function()
|
||||||
|
assert.is.equal(layout_changed, 0)
|
||||||
|
layout:fill_space(false)
|
||||||
|
assert.is.equal(layout_changed, 0)
|
||||||
|
layout:fill_space(true)
|
||||||
|
assert.is.equal(layout_changed, 1)
|
||||||
|
layout:fill_space(true)
|
||||||
|
assert.is.equal(layout_changed, 1)
|
||||||
|
layout:fill_space(false)
|
||||||
|
assert.is.equal(layout_changed, 2)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- 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