mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 14:41:21 +08:00
Fixed an issue where zones do not fill up the whole screen (#1458)
* Fixed an issue where zones do not fill up the whole screen * Fixup: Added comments, removed extra semicolons
This commit is contained in:
parent
db8472a6e5
commit
9860e2bc75
@ -286,7 +286,11 @@ namespace FancyZonesEditor
|
|||||||
{
|
{
|
||||||
_rowsModel.CellChildMap[i, 0] = i;
|
_rowsModel.CellChildMap[i, 0] = i;
|
||||||
_columnsModel.CellChildMap[0, i] = i;
|
_columnsModel.CellChildMap[0, i] = i;
|
||||||
_rowsModel.RowPercents[i] = _multiplier / ZoneCount; // _columnsModel is sharing the same array
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the "Grid" Default Layout
|
// Update the "Grid" Default Layout
|
||||||
@ -313,14 +317,16 @@ namespace FancyZonesEditor
|
|||||||
_gridModel.ColumnPercents = new int[cols];
|
_gridModel.ColumnPercents = new int[cols];
|
||||||
_gridModel.CellChildMap = new int[rows, 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++)
|
for (int row = 0; row < rows; row++)
|
||||||
{
|
{
|
||||||
_gridModel.RowPercents[row] = _multiplier / rows;
|
_gridModel.RowPercents[row] = ((_multiplier * (row + 1)) / rows) - ((_multiplier * row) / rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int col = 0; col < cols; col++)
|
for (int col = 0; col < cols; col++)
|
||||||
{
|
{
|
||||||
_gridModel.ColumnPercents[col] = _multiplier / cols;
|
_gridModel.ColumnPercents[col] = ((_multiplier * (col + 1)) / cols) - ((_multiplier * col) / cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -373,36 +373,40 @@ bool ZoneSet::CalculateColumnsAndRowsLayout(Rect workArea, JSONHelpers::ZoneSetL
|
|||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
int zonePercent = C_MULTIPLIER / zoneCount;
|
|
||||||
|
|
||||||
long totalWidth;
|
long totalWidth;
|
||||||
long totalHeight;
|
long totalHeight;
|
||||||
|
|
||||||
long cellWidth;
|
|
||||||
long cellHeight;
|
|
||||||
|
|
||||||
if (type == JSONHelpers::ZoneSetLayoutType::Columns)
|
if (type == JSONHelpers::ZoneSetLayoutType::Columns)
|
||||||
{
|
{
|
||||||
totalWidth = workArea.width() - (spacing * (zoneCount + 1));
|
totalWidth = workArea.width() - (spacing * (zoneCount + 1));
|
||||||
totalHeight = workArea.height() - (spacing * 2);
|
totalHeight = workArea.height() - (spacing * 2);
|
||||||
cellWidth = totalWidth * zonePercent / C_MULTIPLIER;
|
|
||||||
cellHeight = totalHeight;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //Rows
|
{ //Rows
|
||||||
totalWidth = workArea.width() - (spacing * 2);
|
totalWidth = workArea.width() - (spacing * 2);
|
||||||
totalHeight = workArea.height() - (spacing * (zoneCount + 1));
|
totalHeight = workArea.height() - (spacing * (zoneCount + 1));
|
||||||
cellWidth = totalWidth;
|
|
||||||
cellHeight = totalHeight * zonePercent / C_MULTIPLIER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long top = spacing;
|
long top = spacing;
|
||||||
long left = spacing;
|
long left = spacing;
|
||||||
long bottom = top + cellHeight;
|
long bottom;
|
||||||
long right = left + cellWidth;
|
long right;
|
||||||
|
|
||||||
|
// Note: The expressions below are NOT equal to total{Width|Height} / zoneCount and are done
|
||||||
|
// like this to make the sum of all zones' sizes exactly total{Width|Height}.
|
||||||
for (int zone = 0; zone < zoneCount; zone++)
|
for (int zone = 0; zone < zoneCount; zone++)
|
||||||
{
|
{
|
||||||
|
if (type == JSONHelpers::ZoneSetLayoutType::Columns)
|
||||||
|
{
|
||||||
|
right = left + (zone + 1) * totalWidth / zoneCount - zone * totalWidth / zoneCount;
|
||||||
|
bottom = totalHeight - spacing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ //Rows
|
||||||
|
right = totalWidth - spacing;
|
||||||
|
bottom = top + (zone + 1) * totalHeight / zoneCount - zone * totalHeight / zoneCount;
|
||||||
|
}
|
||||||
|
|
||||||
if (left >= right || top >= bottom || left < 0 || right < 0 || top < 0 || bottom < 0)
|
if (left >= right || top >= bottom || left < 0 || right < 0 || top < 0 || bottom < 0)
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
@ -413,13 +417,11 @@ bool ZoneSet::CalculateColumnsAndRowsLayout(Rect workArea, JSONHelpers::ZoneSetL
|
|||||||
|
|
||||||
if (type == JSONHelpers::ZoneSetLayoutType::Columns)
|
if (type == JSONHelpers::ZoneSetLayoutType::Columns)
|
||||||
{
|
{
|
||||||
left += cellWidth + spacing;
|
left = right + spacing;
|
||||||
right = left + cellWidth;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //Rows
|
{ //Rows
|
||||||
top += cellHeight + spacing;
|
top = bottom + spacing;
|
||||||
bottom = top + cellHeight;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,13 +454,15 @@ bool ZoneSet::CalculateGridLayout(Rect workArea, JSONHelpers::ZoneSetLayoutType
|
|||||||
|
|
||||||
JSONHelpers::GridLayoutInfo gridLayoutInfo(JSONHelpers::GridLayoutInfo::Minimal{ .rows = rows, .columns = columns });
|
JSONHelpers::GridLayoutInfo gridLayoutInfo(JSONHelpers::GridLayoutInfo::Minimal{ .rows = rows, .columns = columns });
|
||||||
|
|
||||||
|
// Note: The expressions below are NOT equal to C_MULTIPLIER / {rows|columns} and are done
|
||||||
|
// like this to make the sum of all percents exactly C_MULTIPLIER
|
||||||
for (int row = 0; row < rows; row++)
|
for (int row = 0; row < rows; row++)
|
||||||
{
|
{
|
||||||
gridLayoutInfo.rowsPercents()[row] = C_MULTIPLIER / rows;
|
gridLayoutInfo.rowsPercents()[row] = C_MULTIPLIER * (row + 1) / rows - C_MULTIPLIER * row / rows;
|
||||||
}
|
}
|
||||||
for (int col = 0; col < columns; col++)
|
for (int col = 0; col < columns; col++)
|
||||||
{
|
{
|
||||||
gridLayoutInfo.columnsPercents()[col] = C_MULTIPLIER / columns;
|
gridLayoutInfo.columnsPercents()[col] = C_MULTIPLIER * (col + 1) / columns - C_MULTIPLIER * col / columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < rows; ++i)
|
for (int i = 0; i < rows; ++i)
|
||||||
@ -554,22 +558,24 @@ bool ZoneSet::CalculateGridZones(Rect workArea, JSONHelpers::GridLayoutInfo grid
|
|||||||
std::vector<Info> rowInfo(gridLayoutInfo.rows());
|
std::vector<Info> rowInfo(gridLayoutInfo.rows());
|
||||||
std::vector<Info> columnInfo(gridLayoutInfo.columns());
|
std::vector<Info> columnInfo(gridLayoutInfo.columns());
|
||||||
|
|
||||||
long top = spacing;
|
// Note: The expressions below are carefully written to
|
||||||
|
// make the sum of all zones' sizes exactly total{Width|Height}
|
||||||
|
long long totalPercents = 0;
|
||||||
for (int row = 0; row < gridLayoutInfo.rows(); row++)
|
for (int row = 0; row < gridLayoutInfo.rows(); row++)
|
||||||
{
|
{
|
||||||
rowInfo[row].Start = top;
|
rowInfo[row].Start = totalPercents * totalHeight / C_MULTIPLIER + (row + 1) * spacing;
|
||||||
rowInfo[row].Extent = totalHeight * gridLayoutInfo.rowsPercents()[row] / C_MULTIPLIER;
|
totalPercents += gridLayoutInfo.rowsPercents()[row];
|
||||||
rowInfo[row].End = rowInfo[row].Start + rowInfo[row].Extent;
|
rowInfo[row].End = totalPercents * totalHeight / C_MULTIPLIER + (row + 1) * spacing;
|
||||||
top += rowInfo[row].Extent + spacing;
|
rowInfo[row].Extent = rowInfo[row].End - rowInfo[row].Start;
|
||||||
}
|
}
|
||||||
|
|
||||||
long left = spacing;
|
totalPercents = 0;
|
||||||
for (int col = 0; col < gridLayoutInfo.columns(); col++)
|
for (int col = 0; col < gridLayoutInfo.columns(); col++)
|
||||||
{
|
{
|
||||||
columnInfo[col].Start = left;
|
columnInfo[col].Start = totalPercents * totalWidth / C_MULTIPLIER + (col + 1) * spacing;
|
||||||
columnInfo[col].Extent = totalWidth * gridLayoutInfo.columnsPercents()[col] / C_MULTIPLIER;
|
totalPercents += gridLayoutInfo.columnsPercents()[col];
|
||||||
columnInfo[col].End = columnInfo[col].Start + columnInfo[col].Extent;
|
columnInfo[col].End = totalPercents * totalWidth / C_MULTIPLIER + (col + 1) * spacing;
|
||||||
left += columnInfo[col].Extent + spacing;
|
columnInfo[col].Extent = columnInfo[col].End - columnInfo[col].Start;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int row = 0; row < gridLayoutInfo.rows(); row++)
|
for (int row = 0; row < gridLayoutInfo.rows(); row++)
|
||||||
@ -580,8 +586,8 @@ bool ZoneSet::CalculateGridZones(Rect workArea, JSONHelpers::GridLayoutInfo grid
|
|||||||
if (((row == 0) || (gridLayoutInfo.cellChildMap()[row - 1][col] != i)) &&
|
if (((row == 0) || (gridLayoutInfo.cellChildMap()[row - 1][col] != i)) &&
|
||||||
((col == 0) || (gridLayoutInfo.cellChildMap()[row][col - 1] != i)))
|
((col == 0) || (gridLayoutInfo.cellChildMap()[row][col - 1] != i)))
|
||||||
{
|
{
|
||||||
left = columnInfo[col].Start;
|
long left = columnInfo[col].Start;
|
||||||
top = rowInfo[row].Start;
|
long top = rowInfo[row].Start;
|
||||||
|
|
||||||
int maxRow = row;
|
int maxRow = row;
|
||||||
while (((maxRow + 1) < gridLayoutInfo.rows()) && (gridLayoutInfo.cellChildMap()[maxRow + 1][col] == i))
|
while (((maxRow + 1) < gridLayoutInfo.rows()) && (gridLayoutInfo.cellChildMap()[maxRow + 1][col] == i))
|
||||||
|
Loading…
Reference in New Issue
Block a user