mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
[FZEditor] Grid layout resizers fixes (#4095)
* Swap resizers on drag * Update resizers on split if existing split is used * Fix accuracy error * Zone ids are ordered * Cancel merge on other actions * Split if one of the snapped splitters is dragged
This commit is contained in:
@@ -60,10 +60,10 @@ namespace FancyZonesEditor.Models
|
||||
public int[,] CellChildMap { get; set; }
|
||||
|
||||
// RowPercents - represents the %age height of each row in the grid
|
||||
public int[] RowPercents { get; set; }
|
||||
public List<int> RowPercents { get; set; }
|
||||
|
||||
// ColumnPercents - represents the %age width of each column in the grid
|
||||
public int[] ColumnPercents { get; set; }
|
||||
public List<int> ColumnPercents { get; set; }
|
||||
|
||||
// FreeZones (not persisted) - used to keep track of child indices that are no longer in use in the CellChildMap,
|
||||
// making them candidates for re-use when it's needed to add another child
|
||||
@@ -85,7 +85,7 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
}
|
||||
|
||||
public GridLayoutModel(string uuid, string name, LayoutType type, int rows, int cols, int[] rowPercents, int[] colsPercents, int[,] cellChildMap)
|
||||
public GridLayoutModel(string uuid, string name, LayoutType type, int rows, int cols, List<int> rowPercents, List<int> colsPercents, int[,] cellChildMap)
|
||||
: base(uuid, name, type)
|
||||
{
|
||||
_rows = rows;
|
||||
@@ -103,16 +103,16 @@ namespace FancyZonesEditor.Models
|
||||
Rows = data[i++];
|
||||
Columns = data[i++];
|
||||
|
||||
RowPercents = new int[Rows];
|
||||
RowPercents = new List<int>(Rows);
|
||||
for (int row = 0; row < Rows; row++)
|
||||
{
|
||||
RowPercents[row] = (data[i++] * 256) + data[i++];
|
||||
RowPercents.Add((data[i++] * 256) + data[i++]);
|
||||
}
|
||||
|
||||
ColumnPercents = new int[Columns];
|
||||
ColumnPercents = new List<int>(Columns);
|
||||
for (int col = 0; col < Columns; col++)
|
||||
{
|
||||
ColumnPercents[col] = (data[i++] * 256) + data[i++];
|
||||
ColumnPercents.Add((data[i++] * 256) + data[i++]);
|
||||
}
|
||||
|
||||
CellChildMap = new int[Rows, Columns];
|
||||
@@ -154,18 +154,18 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
layout.CellChildMap = cellChildMap;
|
||||
|
||||
int[] rowPercents = new int[rows];
|
||||
List<int> rowPercents = new List<int>(rows);
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
rowPercents[row] = RowPercents[row];
|
||||
rowPercents.Add(RowPercents[row]);
|
||||
}
|
||||
|
||||
layout.RowPercents = rowPercents;
|
||||
|
||||
int[] colPercents = new int[cols];
|
||||
List<int> colPercents = new List<int>(cols);
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
colPercents[col] = ColumnPercents[col];
|
||||
colPercents.Add(ColumnPercents[col]);
|
||||
}
|
||||
|
||||
layout.ColumnPercents = colPercents;
|
||||
@@ -177,9 +177,9 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
public int Columns { get; set; }
|
||||
|
||||
public int[] RowsPercentage { get; set; }
|
||||
public List<int> RowsPercentage { get; set; }
|
||||
|
||||
public int[] ColumnsPercentage { get; set; }
|
||||
public List<int> ColumnsPercentage { get; set; }
|
||||
|
||||
public int[][] CellChildMap { get; set; }
|
||||
}
|
||||
|
||||
@@ -184,23 +184,22 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
int rows = info.GetProperty("rows").GetInt32();
|
||||
int columns = info.GetProperty("columns").GetInt32();
|
||||
int[] rowsPercentage = new int[rows];
|
||||
|
||||
List<int> rowsPercentage = new List<int>(rows);
|
||||
JsonElement.ArrayEnumerator rowsPercentageEnumerator = info.GetProperty("rows-percentage").EnumerateArray();
|
||||
int i = 0;
|
||||
while (rowsPercentageEnumerator.MoveNext())
|
||||
{
|
||||
rowsPercentage[i++] = rowsPercentageEnumerator.Current.GetInt32();
|
||||
rowsPercentage.Add(rowsPercentageEnumerator.Current.GetInt32());
|
||||
}
|
||||
|
||||
i = 0;
|
||||
int[] columnsPercentage = new int[columns];
|
||||
List<int> columnsPercentage = new List<int>(columns);
|
||||
JsonElement.ArrayEnumerator columnsPercentageEnumerator = info.GetProperty("columns-percentage").EnumerateArray();
|
||||
while (columnsPercentageEnumerator.MoveNext())
|
||||
{
|
||||
columnsPercentage[i++] = columnsPercentageEnumerator.Current.GetInt32();
|
||||
columnsPercentage.Add(columnsPercentageEnumerator.Current.GetInt32());
|
||||
}
|
||||
|
||||
i = 0;
|
||||
int i = 0;
|
||||
JsonElement.ArrayEnumerator cellChildMapRows = info.GetProperty("cell-child-map").EnumerateArray();
|
||||
int[,] cellChildMap = new int[rows, columns];
|
||||
while (cellChildMapRows.MoveNext())
|
||||
|
||||
@@ -133,14 +133,14 @@ namespace FancyZonesEditor
|
||||
_columnsModel = new GridLayoutModel("Columns", LayoutType.Columns)
|
||||
{
|
||||
Rows = 1,
|
||||
RowPercents = new int[1] { _multiplier },
|
||||
RowPercents = new List<int>(1) { _multiplier },
|
||||
};
|
||||
DefaultModels.Add(_columnsModel);
|
||||
|
||||
_rowsModel = new GridLayoutModel("Rows", LayoutType.Rows)
|
||||
{
|
||||
Columns = 1,
|
||||
ColumnPercents = new int[1] { _multiplier },
|
||||
ColumnPercents = new List<int>(1) { _multiplier },
|
||||
};
|
||||
DefaultModels.Add(_rowsModel);
|
||||
|
||||
@@ -308,7 +308,7 @@ namespace FancyZonesEditor
|
||||
_rowsModel.CellChildMap = new int[ZoneCount, 1];
|
||||
_columnsModel.CellChildMap = new int[1, ZoneCount];
|
||||
_rowsModel.Rows = _columnsModel.Columns = ZoneCount;
|
||||
_rowsModel.RowPercents = _columnsModel.ColumnPercents = new int[ZoneCount];
|
||||
_rowsModel.RowPercents = _columnsModel.ColumnPercents = new List<int>(ZoneCount);
|
||||
|
||||
for (int i = 0; i < ZoneCount; i++)
|
||||
{
|
||||
@@ -318,7 +318,7 @@ namespace FancyZonesEditor
|
||||
// Note: This is NOT equal to _multiplier / ZoneCount and is done like this to make
|
||||
// the sum of all RowPercents exactly (_multiplier).
|
||||
// _columnsModel is sharing the same array
|
||||
_rowsModel.RowPercents[i] = ((_multiplier * (i + 1)) / ZoneCount) - ((_multiplier * i) / ZoneCount);
|
||||
_rowsModel.RowPercents.Add(((_multiplier * (i + 1)) / ZoneCount) - ((_multiplier * i) / ZoneCount));
|
||||
}
|
||||
|
||||
// Update the "Grid" Default Layout
|
||||
@@ -341,20 +341,20 @@ namespace FancyZonesEditor
|
||||
|
||||
_gridModel.Rows = rows;
|
||||
_gridModel.Columns = cols;
|
||||
_gridModel.RowPercents = new int[rows];
|
||||
_gridModel.ColumnPercents = new int[cols];
|
||||
_gridModel.RowPercents = new List<int>(rows);
|
||||
_gridModel.ColumnPercents = new List<int>(cols);
|
||||
_gridModel.CellChildMap = new int[rows, cols];
|
||||
|
||||
// Note: The following are NOT equal to _multiplier divided by rows or columns and is
|
||||
// done like this to make the sum of all RowPercents exactly (_multiplier).
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
_gridModel.RowPercents[row] = ((_multiplier * (row + 1)) / rows) - ((_multiplier * row) / rows);
|
||||
_gridModel.RowPercents.Add(((_multiplier * (row + 1)) / rows) - ((_multiplier * row) / rows));
|
||||
}
|
||||
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
_gridModel.ColumnPercents[col] = ((_multiplier * (col + 1)) / cols) - ((_multiplier * col) / cols);
|
||||
_gridModel.ColumnPercents.Add(((_multiplier * (col + 1)) / cols) - ((_multiplier * col) / cols));
|
||||
}
|
||||
|
||||
int index = ZoneCount - 1;
|
||||
|
||||
Reference in New Issue
Block a user