FZ editor: Splitted zones positioning (#2158)

This commit is contained in:
Seraphima Zykova
2020-04-20 11:54:25 +03:00
committed by GitHub
parent 5cfa8889f4
commit cab5a97117
6 changed files with 119 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -222,6 +222,7 @@ namespace FancyZonesEditor
int newChildIndex = AddZone();
double offset = e.Offset;
double space = e.Space;
if (e.Orientation == Orientation.Vertical)
{
@@ -294,22 +295,28 @@ namespace FancyZonesEditor
model.CellChildMap = newCellChildMap;
sourceCol = 0;
double newTotalExtent = ActualWidth - (space * (cols + 1));
for (int col = 0; col < cols; col++)
{
if (col == foundCol)
{
RowColInfo[] split = _colInfo[col].Split(offset);
RowColInfo[] split = _colInfo[col].Split(offset, space);
newColInfo[col] = split[0];
newColPercents[col] = split[0].Percent;
newColInfo[col++] = split[0];
newColPercents[col] = split[1].Percent;
col++;
newColInfo[col] = split[1];
sourceCol++;
newColPercents[col] = split[1].Percent;
}
else
{
newColInfo[col] = _colInfo[sourceCol];
newColInfo[col].RecalculatePercent(newTotalExtent);
newColPercents[col] = model.ColumnPercents[sourceCol];
newColInfo[col] = _colInfo[sourceCol++];
}
sourceCol++;
}
_colInfo = newColInfo;
@@ -389,22 +396,28 @@ namespace FancyZonesEditor
model.CellChildMap = newCellChildMap;
sourceRow = 0;
double newTotalExtent = ActualHeight - (space * (rows + 1));
for (int row = 0; row < rows; row++)
{
if (row == foundRow)
{
RowColInfo[] split = _rowInfo[row].Split(offset);
RowColInfo[] split = _rowInfo[row].Split(offset, space);
newRowInfo[row] = split[0];
newRowPercents[row] = split[0].Percent;
newRowInfo[row++] = split[0];
newRowPercents[row] = split[1].Percent;
row++;
newRowInfo[row] = split[1];
sourceRow++;
newRowPercents[row] = split[1].Percent;
}
else
{
newRowInfo[row] = _rowInfo[sourceRow];
newRowInfo[row].RecalculatePercent(newTotalExtent);
newRowPercents[row] = model.RowPercents[sourceRow];
newRowInfo[row] = _rowInfo[sourceRow++];
}
sourceRow++;
}
_rowInfo = newRowInfo;

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -276,8 +276,15 @@ namespace FancyZonesEditor
}
private void DoSplit(Orientation orientation, double offset)
{
Split?.Invoke(this, new SplitEventArgs(orientation, offset));
{
int spacing = 0;
Settings settings = ((App)Application.Current).ZoneSettings;
if (settings.ShowSpacing)
{
spacing = settings.Spacing;
}
Split?.Invoke(this, new SplitEventArgs(orientation, offset, spacing));
}
private void FullSplit_Click(object sender, RoutedEventArgs e)

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -34,13 +34,24 @@ namespace FancyZonesEditor
return Extent;
}
public RowColInfo[] Split(double offset)
public void RecalculatePercent(double newTotalExtent)
{
Percent = (int)(Extent * _multiplier / newTotalExtent);
}
public RowColInfo[] Split(double offset, double space)
{
RowColInfo[] info = new RowColInfo[2];
int newPercent = (int)(Percent * offset / Extent);
info[0] = new RowColInfo(newPercent);
info[1] = new RowColInfo(Percent - newPercent);
double totalExtent = Extent * _multiplier / Percent;
totalExtent -= space;
int percent0 = (int)(offset * _multiplier / totalExtent);
int percent1 = (int)((Extent - space - offset) * _multiplier / totalExtent);
info[0] = new RowColInfo(percent0);
info[1] = new RowColInfo(percent1);
return info;
}
}

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -13,15 +13,18 @@ namespace FancyZonesEditor
{
}
public SplitEventArgs(Orientation orientation, double offset)
public SplitEventArgs(Orientation orientation, double offset, double thickness)
{
Orientation = orientation;
Offset = offset;
Space = thickness;
}
public Orientation Orientation { get; }
public double Offset { get; }
public double Space { get; }
}
public delegate void SplitEventHandler(object sender, SplitEventArgs args);