作者 linmadan

修复布局算法

... ... @@ -62,17 +62,18 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
if len(cells) > 0 {
addedRows := 0
addedColumns := 0
preRowMaxDownLength := 0
preRowMaxDownLength := 1
preRawCellX := 0
for _, cell := range cells {
if preRawCellX != cell.X {
addedColumns = 0
addedRows = addedRows + preRowMaxDownLength - 1
preRowMaxDownLength = 0
preRowMaxDownLength = 1
preRawCellX = cell.X
}
cell.X = addedRows + cell.X
cell.Y = addedColumns + cell.Y
println("=======")
switch cell.Direction {
case domain.DirectionRight:
addedColumns = addedColumns + cell.Length - 1
... ...
... ... @@ -97,6 +97,75 @@ func TestNewDataLayout(t *testing.T) {
},
flag: Location{X: 2, Y: 2},
},
{
title: "全部无方向",
cells: []*domain.LayoutCell{
{
X: 0,
Y: 0,
Length: 1,
ImageData: "1",
Direction: domain.DirectionNone,
},
{
X: 0,
Y: 1,
Length: 1,
ImageData: "2",
Direction: domain.DirectionNone,
},
{
X: 0,
Y: 2,
Length: 1,
ImageData: "3",
Direction: domain.DirectionNone,
},
{
X: 1,
Y: 0,
Length: 1,
ImageData: "4",
Direction: domain.DirectionNone,
},
{
X: 1,
Y: 1,
Length: 1,
ImageData: "5",
Direction: domain.DirectionNone,
},
{
X: 1,
Y: 2,
Length: 1,
ImageData: "6",
Direction: domain.DirectionNone,
},
{
X: 2,
Y: 0,
Length: 1,
ImageData: "7",
Direction: domain.DirectionNone,
},
{
X: 2,
Y: 1,
Length: 1,
ImageData: "8",
Direction: domain.DirectionDown,
},
{
X: 2,
Y: 2,
Length: 1,
ImageData: "9",
Direction: domain.DirectionNone,
},
},
flag: Location{X: 2, Y: 2},
},
}
padding := func(cells []*domain.LayoutCell) {
for _, cell := range cells {
... ...