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. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
@@ -222,6 +222,7 @@ namespace FancyZonesEditor
int newChildIndex = AddZone(); int newChildIndex = AddZone();
double offset = e.Offset; double offset = e.Offset;
double space = e.Space;
if (e.Orientation == Orientation.Vertical) if (e.Orientation == Orientation.Vertical)
{ {
@@ -294,22 +295,28 @@ namespace FancyZonesEditor
model.CellChildMap = newCellChildMap; model.CellChildMap = newCellChildMap;
sourceCol = 0; sourceCol = 0;
double newTotalExtent = ActualWidth - (space * (cols + 1));
for (int col = 0; col < cols; col++) for (int col = 0; col < cols; col++)
{ {
if (col == foundCol) 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; newColPercents[col] = split[0].Percent;
newColInfo[col++] = split[0]; col++;
newColPercents[col] = split[1].Percent;
newColInfo[col] = split[1]; newColInfo[col] = split[1];
sourceCol++; newColPercents[col] = split[1].Percent;
} }
else else
{ {
newColInfo[col] = _colInfo[sourceCol];
newColInfo[col].RecalculatePercent(newTotalExtent);
newColPercents[col] = model.ColumnPercents[sourceCol]; newColPercents[col] = model.ColumnPercents[sourceCol];
newColInfo[col] = _colInfo[sourceCol++];
} }
sourceCol++;
} }
_colInfo = newColInfo; _colInfo = newColInfo;
@@ -389,22 +396,28 @@ namespace FancyZonesEditor
model.CellChildMap = newCellChildMap; model.CellChildMap = newCellChildMap;
sourceRow = 0; sourceRow = 0;
double newTotalExtent = ActualHeight - (space * (rows + 1));
for (int row = 0; row < rows; row++) for (int row = 0; row < rows; row++)
{ {
if (row == foundRow) 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; newRowPercents[row] = split[0].Percent;
newRowInfo[row++] = split[0]; row++;
newRowPercents[row] = split[1].Percent;
newRowInfo[row] = split[1]; newRowInfo[row] = split[1];
sourceRow++; newRowPercents[row] = split[1].Percent;
} }
else else
{ {
newRowInfo[row] = _rowInfo[sourceRow];
newRowInfo[row].RecalculatePercent(newTotalExtent);
newRowPercents[row] = model.RowPercents[sourceRow]; newRowPercents[row] = model.RowPercents[sourceRow];
newRowInfo[row] = _rowInfo[sourceRow++];
} }
sourceRow++;
} }
_rowInfo = newRowInfo; _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. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
@@ -277,7 +277,14 @@ namespace FancyZonesEditor
private void DoSplit(Orientation orientation, double offset) 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) 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. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
@@ -34,13 +34,24 @@ namespace FancyZonesEditor
return Extent; 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]; RowColInfo[] info = new RowColInfo[2];
int newPercent = (int)(Percent * offset / Extent); double totalExtent = Extent * _multiplier / Percent;
info[0] = new RowColInfo(newPercent); totalExtent -= space;
info[1] = new RowColInfo(Percent - newPercent);
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; 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. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // 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; Orientation = orientation;
Offset = offset; Offset = offset;
Space = thickness;
} }
public Orientation Orientation { get; } public Orientation Orientation { get; }
public double Offset { get; } public double Offset { get; }
public double Space { get; }
} }
public delegate void SplitEventHandler(object sender, SplitEventArgs args); public delegate void SplitEventHandler(object sender, SplitEventArgs args);

View File

@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows; using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions; using OpenQA.Selenium.Interactions;
@@ -161,23 +161,67 @@ namespace PowerToysTests
public void CreateSplitter() public void CreateSplitter()
{ {
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton"); OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); WaitSeconds(2);
Assert.IsNotNull(gridEditor);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
Assert.AreEqual(2, thumbs.Count);
new Actions(session).MoveToElement(thumbs[0]).MoveByOffset(-30, 0).Click().Perform();
Assert.AreEqual(3, gridEditor.FindElementsByClassName("Thumb").Count);
ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone"); ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(3, zones.Count, "Zones count invalid");
const int defaultSpacing = 16;
int splitPos = zones[0].Rect.Y + zones[0].Rect.Height / 2;
new Actions(session).MoveToElement(zones[0]).Click().Perform();
zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(4, zones.Count); Assert.AreEqual(4, zones.Count);
//check that zone was splitted horizontally //check splitted zone
Assert.AreNotEqual(zones[0].Rect.Height, zones[1].Rect.Height); Assert.AreEqual(zones[0].Rect.Top, defaultSpacing);
Assert.AreNotEqual(zones[3].Rect.Height, zones[1].Rect.Height); Assert.IsTrue(Math.Abs(zones[0].Rect.Bottom - splitPos + defaultSpacing / 2) <= 2);
Assert.AreEqual(zones[1].Rect.Height, zones[2].Rect.Height); Assert.IsTrue(Math.Abs(zones[3].Rect.Top - splitPos - defaultSpacing / 2) <= 2);
Assert.AreEqual(zones[3].Rect.Bottom, Screen.PrimaryScreen.Bounds.Bottom - defaultSpacing);
}
[TestMethod]
public void TestSplitterShiftAfterCreation()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WaitSeconds(2);
ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(3, zones.Count, "Zones count invalid");
const int defaultSpacing = 16;
//create first split
int firstSplitPos = zones[0].Rect.Y + zones[0].Rect.Height / 4;
new Actions(session).MoveToElement(zones[0]).MoveByOffset(0, -(zones[0].Rect.Height / 4)).Click().Perform();
zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(4, zones.Count);
Assert.AreEqual(zones[0].Rect.Top, defaultSpacing);
Assert.IsTrue(Math.Abs(zones[0].Rect.Bottom - firstSplitPos + defaultSpacing / 2) <= 2);
Assert.IsTrue(Math.Abs(zones[3].Rect.Top - firstSplitPos - defaultSpacing / 2) <= 2);
Assert.AreEqual(zones[3].Rect.Bottom, Screen.PrimaryScreen.Bounds.Bottom - defaultSpacing);
//create second split
int secondSplitPos = zones[3].Rect.Y + zones[3].Rect.Height / 2;
int expectedTop = zones[3].Rect.Top;
new Actions(session).MoveToElement(zones[3]).Click().Perform();
zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(5, zones.Count);
//check first split on same position
Assert.AreEqual(zones[0].Rect.Top, defaultSpacing);
Assert.IsTrue(Math.Abs(zones[0].Rect.Bottom - firstSplitPos + defaultSpacing / 2) <= 2);
//check second split
Assert.AreEqual(zones[3].Rect.Top, expectedTop);
Assert.IsTrue(Math.Abs(zones[3].Rect.Bottom - secondSplitPos + defaultSpacing / 2) <= 2);
Assert.IsTrue(Math.Abs(zones[4].Rect.Top - secondSplitPos - defaultSpacing / 2) <= 2);
Assert.AreEqual(zones[4].Rect.Bottom, Screen.PrimaryScreen.Bounds.Bottom - defaultSpacing);
} }
[TestMethod] [TestMethod]

View File

@@ -17,9 +17,11 @@ namespace PowerToysTests
protected static void OpenEditor() protected static void OpenEditor()
{ {
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform(); new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
WaitSeconds(2);
//editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]"); //editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
editorWindow = WaitElementByName("FancyZones Editor");
//may not find editor by name in 0.16.1 //may not find editor by name in 0.16.1
editorWindow = WaitElementByAccessibilityId("MainWindow1"); //editorWindow = WaitElementByAccessibilityId("MainWindow1");
Assert.IsNotNull(editorWindow, "Couldn't find editor window"); Assert.IsNotNull(editorWindow, "Couldn't find editor window");
} }
@@ -57,10 +59,10 @@ namespace PowerToysTests
protected static void OpenCreatorWindow(string tabName, string creatorWindowName, string buttonId = "EditCustomButton") protected static void OpenCreatorWindow(string tabName, string creatorWindowName, string buttonId = "EditCustomButton")
{ {
string elementXPath = "//Text[@Name=\"" + tabName + "\"]"; string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
session.FindElementByXPath(elementXPath).Click(); WaitElementByXPath(elementXPath).Click();
session.FindElementByAccessibilityId(buttonId).Click(); WaitElementByAccessibilityId(buttonId).Click();
WindowsElement creatorWindow = session.FindElementByName(creatorWindowName); WindowsElement creatorWindow = WaitElementByName(creatorWindowName);
Assert.IsNotNull(creatorWindow, "Creator window didn't open"); Assert.IsNotNull(creatorWindow, "Creator window didn't open");
} }