From 3d5c790fb6d457857abc9be974bc2130cabb30d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Sto=C5=A1i=C4=87?= Date: Mon, 14 Sep 2020 10:05:28 +0200 Subject: [PATCH] [FZ Editor] Improved a function in GridData.cs (#6565) * Improved a function in GridData.cs * Allocate the extra values proportionally * Refactor a constant --- .../editor/FancyZonesEditor/GridData.cs | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs index 9d0755de5e..6b2dcd4b39 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs @@ -12,6 +12,9 @@ namespace FancyZonesEditor { public class GridData { + // The sum of row/column percents should be equal to this number + private const int _multiplier = 10000; + public class ResizeInfo { public ResizeInfo() @@ -70,7 +73,7 @@ namespace FancyZonesEditor total += info[i].Percent; } - int diff = total - 10000; + int diff = total - _multiplier; if (diff != 0) { TotalPercent -= diff; @@ -1025,26 +1028,13 @@ namespace FancyZonesEditor total += info[i].Percent; } - int totalDiff = total - 10000; - if (totalDiff != 0) + int prefixTotal = 0; + for (int i = 0; i < percents.Count; i++) { - int perLineDiff = totalDiff / percents.Count; - int lastLineDiff = totalDiff - (perLineDiff * (percents.Count - 1)); - - for (int i = 0; i < percents.Count - 1 && perLineDiff != 0; i++) - { - 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; + int first = prefixTotal * _multiplier / total; + prefixTotal += info[i].Percent; + int last = prefixTotal * _multiplier / total; + percents[i] = info[i].Percent = last - first; } }