mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[FZ Editor] Improved a function in GridData.cs (#6565)
* Improved a function in GridData.cs * Allocate the extra values proportionally * Refactor a constant
This commit is contained in:
@@ -12,6 +12,9 @@ namespace FancyZonesEditor
|
|||||||
{
|
{
|
||||||
public class GridData
|
public class GridData
|
||||||
{
|
{
|
||||||
|
// The sum of row/column percents should be equal to this number
|
||||||
|
private const int _multiplier = 10000;
|
||||||
|
|
||||||
public class ResizeInfo
|
public class ResizeInfo
|
||||||
{
|
{
|
||||||
public ResizeInfo()
|
public ResizeInfo()
|
||||||
@@ -70,7 +73,7 @@ namespace FancyZonesEditor
|
|||||||
total += info[i].Percent;
|
total += info[i].Percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff = total - 10000;
|
int diff = total - _multiplier;
|
||||||
if (diff != 0)
|
if (diff != 0)
|
||||||
{
|
{
|
||||||
TotalPercent -= diff;
|
TotalPercent -= diff;
|
||||||
@@ -1025,26 +1028,13 @@ namespace FancyZonesEditor
|
|||||||
total += info[i].Percent;
|
total += info[i].Percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalDiff = total - 10000;
|
int prefixTotal = 0;
|
||||||
if (totalDiff != 0)
|
for (int i = 0; i < percents.Count; i++)
|
||||||
{
|
{
|
||||||
int perLineDiff = totalDiff / percents.Count;
|
int first = prefixTotal * _multiplier / total;
|
||||||
int lastLineDiff = totalDiff - (perLineDiff * (percents.Count - 1));
|
prefixTotal += info[i].Percent;
|
||||||
|
int last = prefixTotal * _multiplier / total;
|
||||||
for (int i = 0; i < percents.Count - 1 && perLineDiff != 0; i++)
|
percents[i] = info[i].Percent = last - first;
|
||||||
{
|
|
||||||
int percent = percents[i] - perLineDiff;
|
|
||||||
if (percent < 0)
|
|
||||||
{
|
|
||||||
percent = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
percents[i] = percent;
|
|
||||||
info[i].Percent = percent;
|
|
||||||
}
|
|
||||||
|
|
||||||
info[percents.Count - 1].Percent -= lastLineDiff;
|
|
||||||
percents[percents.Count - 1] -= lastLineDiff;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user