Merge pull request #2463 from psychon/flex_no_space

wibox.layout.flex: Do not leave empty space behind
This commit is contained in:
mergify[bot] 2018-11-06 14:43:22 +00:00 committed by GitHub
commit 99672875f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -10,7 +10,6 @@ local base = require("wibox.widget.base")
local fixed = require("wibox.layout.fixed") local fixed = require("wibox.layout.fixed")
local table = table local table = table
local pairs = pairs local pairs = pairs
local floor = math.floor
local gmath = require("gears.math") local gmath = require("gears.math")
local gtable = require("gears.table") local gtable = require("gears.table")
@ -68,7 +67,7 @@ local flex = {}
function flex:layout(_, width, height) function flex:layout(_, width, height)
local result = {} local result = {}
local pos,spacing = 0, self._private.spacing local spacing = self._private.spacing
local num = #self._private.widgets local num = #self._private.widgets
local total_spacing = (spacing*(num-1)) local total_spacing = (spacing*(num-1))
local spacing_widget = self._private.spacing_widget local spacing_widget = self._private.spacing_widget
@ -88,17 +87,23 @@ function flex:layout(_, width, height)
space_per_item = math.min(space_per_item, self._private.max_widget_size) space_per_item = math.min(space_per_item, self._private.max_widget_size)
end end
local pos, pos_rounded = 0, 0
for k, v in pairs(self._private.widgets) do for k, v in pairs(self._private.widgets) do
local x, y, w, h local x, y, w, h
local next_pos = pos + space_per_item
local next_pos_rounded = gmath.round(next_pos)
if is_y then if is_y then
x, y = 0, gmath.round(pos) x, y = 0, pos_rounded
w, h = width, floor(space_per_item) w, h = width, next_pos_rounded - pos_rounded
else else
x, y = gmath.round(pos), 0 x, y = pos_rounded, 0
w, h = floor(space_per_item), height w, h = next_pos_rounded - pos_rounded, height
end end
pos = pos + space_per_item + spacing pos = next_pos + spacing
pos_rounded = next_pos_rounded + spacing
table.insert(result, base.place_widget_at(v, x, y, w, h)) table.insert(result, base.place_widget_at(v, x, y, w, h))

View File

@ -47,7 +47,7 @@ describe("wibox.layout.flex", function()
it("layout", function() it("layout", function()
assert.widget_layout(layout, { 100, 100 }, { assert.widget_layout(layout, { 100, 100 }, {
p(first, 0, 0, 100, 33), p(first, 0, 0, 100, 33),
p(second, 0, 33, 100, 33), p(second, 0, 33, 100, 34),
p(third, 0, 67, 100, 33), p(third, 0, 67, 100, 33),
}) })
end) end)
@ -61,7 +61,7 @@ describe("wibox.layout.flex", function()
it("layout", function() it("layout", function()
assert.widget_layout(layout, { 5, 100 }, { assert.widget_layout(layout, { 5, 100 }, {
p(first, 0, 0, 5, 33), p(first, 0, 0, 5, 33),
p(second, 0, 33, 5, 33), p(second, 0, 33, 5, 34),
p(third, 0, 67, 5, 33), p(third, 0, 67, 5, 33),
}) })
end) end)
@ -74,9 +74,9 @@ describe("wibox.layout.flex", function()
it("layout", function() it("layout", function()
assert.widget_layout(layout, { 100, 20 }, { assert.widget_layout(layout, { 100, 20 }, {
p(first, 0, 0, 100, 6), p(first, 0, 0, 100, 7),
p(second, 0, 7, 100, 6), p(second, 0, 7, 100, 6),
p(third, 0, 13, 100, 6), p(third, 0, 13, 100, 7),
}) })
end) end)
end) end)