mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
FZ editor: Splitted zones positioning (#2158)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
@@ -161,23 +161,67 @@ namespace PowerToysTests
|
||||
public void CreateSplitter()
|
||||
{
|
||||
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
|
||||
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
|
||||
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);
|
||||
WaitSeconds(2);
|
||||
|
||||
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);
|
||||
|
||||
//check that zone was splitted horizontally
|
||||
Assert.AreNotEqual(zones[0].Rect.Height, zones[1].Rect.Height);
|
||||
Assert.AreNotEqual(zones[3].Rect.Height, zones[1].Rect.Height);
|
||||
Assert.AreEqual(zones[1].Rect.Height, zones[2].Rect.Height);
|
||||
//check splitted zone
|
||||
Assert.AreEqual(zones[0].Rect.Top, defaultSpacing);
|
||||
Assert.IsTrue(Math.Abs(zones[0].Rect.Bottom - splitPos + defaultSpacing / 2) <= 2);
|
||||
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]
|
||||
|
||||
@@ -17,9 +17,11 @@ namespace PowerToysTests
|
||||
protected static void OpenEditor()
|
||||
{
|
||||
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
|
||||
WaitSeconds(2);
|
||||
//editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
|
||||
editorWindow = WaitElementByName("FancyZones Editor");
|
||||
//may not find editor by name in 0.16.1
|
||||
editorWindow = WaitElementByAccessibilityId("MainWindow1");
|
||||
//editorWindow = WaitElementByAccessibilityId("MainWindow1");
|
||||
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")
|
||||
{
|
||||
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
|
||||
session.FindElementByXPath(elementXPath).Click();
|
||||
session.FindElementByAccessibilityId(buttonId).Click();
|
||||
WaitElementByXPath(elementXPath).Click();
|
||||
WaitElementByAccessibilityId(buttonId).Click();
|
||||
|
||||
WindowsElement creatorWindow = session.FindElementByName(creatorWindowName);
|
||||
WindowsElement creatorWindow = WaitElementByName(creatorWindowName);
|
||||
Assert.IsNotNull(creatorWindow, "Creator window didn't open");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user