From 07b1977d54720a0880d219ea0d60a52547fce4be Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Mon, 16 Mar 2020 02:17:20 +0100 Subject: [PATCH] Shortcuts Guide, PowerRename, ImageResizer and PowerLauncher settings pages (#1589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed one mishandled case when computing zones (#1470) * Fix spelling mistake (#1476) * Move ZoneSetPersistedDataOLD to JsonHelpers (#1405) * Remove unused check for pClassFactory (#1419) * Update dllmain.cpp * Update dllmain.cpp * Switch WindowWalker C# project to use PackageReference (#1374) * Switch WindowWalker C# project to use PackageReference * Remove packages.config leftovers Co-authored-by: William Kent * Update bundle.js and html index files. (#1502) * Editor IO exception handling (#1491) * Close input stream Show MessageBox with exception message Remove unused arguments Guard all of the Editor input/output code parts and show MessageBox with appropriate message and issue reporting link * Extract showing messageBox into method * Ui rename Zone highlight Opacity (%) - > Zone Opacity (#1504) * Document fancy zones (#1496) * added in dialog, tweaked layout to be more resiliant to longer text (#1361) * Fix deleting custom layouts when closing on SaveApply (#1512) * Fix deleting custom layouts when closing on SaveApply * Only serialize if SaveApply, not on Cancel or X * Fix compiler warning (#1492) * Use default options for Utf8JsonWriter (#1497) * Move window to last known zone. Support movement in multi-monitor scenario (#1511) * FancyZones editor magnetic snapping effect (#1503) * FancyZones editor magnetic snapping effect Implemented a solution to Issue #585: FancyZones: Alignment/Snapping/Ruler * Fixed VS complaining about names and access modifiers * Removed reference to unused implementation of snapping in FZE * Converted integer constants to enums in FZE/Canvas * Convert a portion of code to a switch statement * Improved code maintainability * Fixed a screen resolution bug in FZE/Canvas Fixed a bug where the editor doesn't respect the new screen resolution. * Further maintainability improvements * Fixed a compiler warning * Changed some variables to camelCase * Now working on 0.15.3 (#1525) * Fixed a Grid editor issue (#1308) * Fixed a Grid editor issue * Explained the fix in ExtendRangeToHaveEvenCellEdges * Simplified code in ExtendRangeToHaveEvenCellEdges * Removed redundant comment, more camelCase * Improve readability of EditorWindow (#1515) Co-authored-by: Ivan Stošić Co-authored-by: ItzLevvie Co-authored-by: stefansjfw <57057282+stefansjfw@users.noreply.github.com> Co-authored-by: pi1024e <49824824+pi1024e@users.noreply.github.com> Co-authored-by: William Kent Co-authored-by: William Kent Co-authored-by: Enrico Giordani Co-authored-by: PrzemyslawTusinski <61138537+PrzemyslawTusinski@users.noreply.github.com> Co-authored-by: vldmr11080 <57061786+vldmr11080@users.noreply.github.com> Co-authored-by: Clint Rutkas --- installer/Version.props | 2 +- .../FancyZonesEditor/CanvasEditor.xaml.cs | 4 +- .../editor/FancyZonesEditor/CanvasZone.xaml | 18 +- .../FancyZonesEditor/CanvasZone.xaml.cs | 342 +++++++++++++----- .../editor/FancyZonesEditor/EditorWindow.cs | 13 +- .../FancyZonesEditor/GridEditor.xaml.cs | 65 +--- .../FancyZonesEditor/GridEditorWindow.xaml | 17 +- .../FancyZonesEditor/MainWindow.xaml.cs | 4 +- .../Models/CanvasLayoutModel.cs | 65 ++-- .../Models/GridLayoutModel.cs | 82 +++-- .../FancyZonesEditor/Models/LayoutModel.cs | 241 ++++++------ .../FancyZonesEditor/Models/Settings.cs | 82 +++-- .../Properties/Resources.Designer.cs | 2 +- .../Properties/Resources.resx | 2 +- src/modules/fancyzones/lib/FancyZones.cpp | 44 +-- src/modules/fancyzones/lib/FancyZones.h | 72 ++++ src/modules/fancyzones/lib/JsonHelpers.cpp | 13 + src/modules/fancyzones/lib/Zone.h | 36 ++ src/modules/fancyzones/lib/ZoneSet.cpp | 4 +- src/modules/fancyzones/lib/ZoneSet.h | 77 +++- src/modules/fancyzones/lib/ZoneWindow.cpp | 4 +- src/modules/fancyzones/lib/ZoneWindow.h | 65 ++++ src/modules/fancyzones/lib/fancyzones.rc | Bin 6384 -> 6356 bytes src/modules/fancyzones/lib/util.h | 4 +- src/modules/powerrename/dll/dllmain.cpp | 21 +- .../app/Window Walker/Window Walker.csproj | 27 +- .../app/Window Walker/packages.config | 6 - .../src/components/GeneralSettings.tsx | 2 +- src/settings/settings-html/dist/bundle.js | 10 +- src/settings/settings-html/index-dark.html | 4 +- src/settings/settings-html/index.html | 4 +- 31 files changed, 846 insertions(+), 486 deletions(-) delete mode 100644 src/modules/windowwalker/app/Window Walker/packages.config diff --git a/installer/Version.props b/installer/Version.props index af4557669620..a73cd02a5324 100644 --- a/installer/Version.props +++ b/installer/Version.props @@ -1,7 +1,7 @@ - 0.15.2 + 0.15.3 Version=$(Version); \ No newline at end of file diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs index 344bdeed9a29..00ce0a98ca80 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs @@ -63,8 +63,8 @@ private void UpdateZoneRects() zone.ZoneIndex = i; Canvas.SetLeft(zone, rect.X); Canvas.SetTop(zone, rect.Y); - zone.MinHeight = rect.Height; - zone.MinWidth = rect.Width; + zone.Height = rect.Height; + zone.Width = rect.Width; } } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml index 03b272cb30ad..fb3fb316cc20 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml +++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml @@ -24,19 +24,19 @@ - - - - - - - - + + + + + + + + - + diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs index 1d0bc9d9a676..085bb79b4664 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -16,192 +17,333 @@ namespace FancyZonesEditor /// public partial class CanvasZone : UserControl { - public CanvasLayoutModel Model { get; set; } - - public int ZoneIndex { get; set; } + public CanvasZone() + { + InitializeComponent(); + Canvas.SetZIndex(this, zIndex++); + } private readonly Settings _settings = ((App)Application.Current).ZoneSettings; - private static readonly int _minZoneWidth = 64; - private static readonly int _minZoneHeight = 72; - private static int _zIndex = 0; + private CanvasLayoutModel model; - public CanvasZone() + private int zoneIndex; + + public enum ResizeMode { - InitializeComponent(); - Panel.SetZIndex(this, _zIndex++); + BottomEdge, + TopEdge, + BothEdges, } - private void Move(double xDelta, double yDelta) + private abstract class SnappyHelperBase { - Int32Rect rect = Model.Zones[ZoneIndex]; - if (xDelta < 0) - { - xDelta = Math.Max(xDelta, -rect.X); - } - else if (xDelta > 0) - { - xDelta = Math.Min(xDelta, _settings.WorkArea.Width - rect.Width - rect.X); - } + public int ScreenW { get; private set; } - if (yDelta < 0) - { - yDelta = Math.Max(yDelta, -rect.Y); - } - else if (yDelta > 0) + protected List Snaps { get; private set; } + + protected int MinValue { get; private set; } + + protected int MaxValue { get; private set; } + + public int Position { get; protected set; } + + public ResizeMode Mode { get; private set; } + + /// + /// Initializes a new instance of the class. + /// Just pass it the canvas arguments. Use mode + /// to tell it which edges of the existing masks to use when building its list + /// of snap points, and generally which edges to track. There will be two + /// SnappyHelpers, one for X-coordinates and one for + /// Y-coordinates, they work independently but share the same logic. + /// + /// The list of rectangles describing all zones + /// The index of the zone to track + /// Whether this is the X or Y SnappyHelper + /// One of the three modes of operation (for example: tracking left/right/both edges) + /// The size of the screen in this (X or Y) dimension + public SnappyHelperBase(IList zones, int zoneIndex, bool isX, ResizeMode mode, int screenAxisSize) { - yDelta = Math.Min(yDelta, _settings.WorkArea.Height - rect.Height - rect.Y); - } + int zonePosition = isX ? zones[zoneIndex].X : zones[zoneIndex].Y; + int zoneAxisSize = isX ? zones[zoneIndex].Width : zones[zoneIndex].Height; + int minAxisSize = isX ? MinZoneWidth : MinZoneHeight; + List keyPositions = new List(); + for (int i = 0; i < zones.Count; ++i) + { + if (i != zoneIndex) + { + int ithZonePosition = isX ? zones[i].X : zones[i].Y; + int ithZoneAxisSize = isX ? zones[i].Width : zones[i].Height; + keyPositions.Add(ithZonePosition); + keyPositions.Add(ithZonePosition + ithZoneAxisSize); + if (mode == ResizeMode.BothEdges) + { + keyPositions.Add(ithZonePosition - zoneAxisSize); + keyPositions.Add(ithZonePosition + ithZoneAxisSize - zoneAxisSize); + } + } + } - rect.X += (int)xDelta; - rect.Y += (int)yDelta; + // Remove duplicates and sort + keyPositions.Sort(); + Snaps = new List(); + if (keyPositions.Count > 0) + { + Snaps.Add(keyPositions[0]); + for (int i = 1; i < keyPositions.Count; ++i) + { + if (keyPositions[i] != keyPositions[i - 1]) + { + Snaps.Add(keyPositions[i]); + } + } + } - Canvas.SetLeft(this, rect.X); - Canvas.SetTop(this, rect.Y); - Model.Zones[ZoneIndex] = rect; + switch (mode) + { + case ResizeMode.BottomEdge: + // We're dragging the low edge, don't go below zero + MinValue = 0; + + // It can't make the zone smaller than minAxisSize + MaxValue = zonePosition + zoneAxisSize - minAxisSize; + Position = zonePosition; + break; + case ResizeMode.TopEdge: + // We're dragging the high edge, don't make the zone smaller than minAxisSize + MinValue = zonePosition + minAxisSize; + + // Don't go off the screen + MaxValue = screenAxisSize; + Position = zonePosition + zoneAxisSize; + break; + case ResizeMode.BothEdges: + // We're moving the window, don't move it below zero + MinValue = 0; + + // Don't go off the screen (this time the lower edge is tracked) + MaxValue = screenAxisSize - zoneAxisSize; + Position = zonePosition; + break; + } + + Mode = mode; + this.ScreenW = screenAxisSize; + } + + public abstract void Move(int delta); } - private void SizeMove(double xDelta, double yDelta) + private class SnappyHelperMagnetic : SnappyHelperBase { - Int32Rect rect = Model.Zones[ZoneIndex]; - if (xDelta < 0) + private List magnetZoneSizes; + private int freePosition; + + private int MagnetZoneMaxSize { - if ((rect.X + xDelta) < 0) - { - xDelta = -rect.X; - } + get => (int)(0.08 * ScreenW); } - else if (xDelta > 0) + + public SnappyHelperMagnetic(IList zones, int zoneIndex, bool isX, ResizeMode mode, int screenAxisSize) + : base(zones, zoneIndex, isX, mode, screenAxisSize) { - if ((rect.Width - (int)xDelta) < _minZoneWidth) + freePosition = Position; + magnetZoneSizes = new List(); + for (int i = 0; i < Snaps.Count; ++i) { - xDelta = rect.Width - _minZoneWidth; + int previous = i == 0 ? 0 : Snaps[i - 1]; + int next = i == Snaps.Count - 1 ? ScreenW : Snaps[i + 1]; + magnetZoneSizes.Add(Math.Min(Snaps[i] - previous, Math.Min(next - Snaps[i], MagnetZoneMaxSize)) / 2); } } - if (yDelta < 0) + public override void Move(int delta) { - if ((rect.Y + yDelta) < 0) + freePosition = Position + delta; + int snapId = -1; + for (int i = 0; i < Snaps.Count; ++i) { - yDelta = -rect.Y; + if (Math.Abs(freePosition - Snaps[i]) <= magnetZoneSizes[i]) + { + snapId = i; + break; + } } - } - else if (yDelta > 0) - { - if ((rect.Height - (int)yDelta) < _minZoneHeight) + + if (snapId == -1) { - yDelta = rect.Height - _minZoneHeight; + Position = freePosition; + } + else + { + int deadZoneWidth = (magnetZoneSizes[snapId] + 1) / 2; + if (Math.Abs(freePosition - Snaps[snapId]) <= deadZoneWidth) + { + Position = Snaps[snapId]; + } + else if (freePosition < Snaps[snapId]) + { + Position = freePosition + (freePosition - (Snaps[snapId] - magnetZoneSizes[snapId])); + } + else + { + Position = freePosition - ((Snaps[snapId] + magnetZoneSizes[snapId]) - freePosition); + } } - } - rect.X += (int)xDelta; - rect.Width -= (int)xDelta; - MinWidth = rect.Width; + Position = Math.Max(Math.Min(MaxValue, Position), MinValue); + } + } - rect.Y += (int)yDelta; - rect.Height -= (int)yDelta; - MinHeight = rect.Height; + private SnappyHelperBase snappyX; + private SnappyHelperBase snappyY; - Canvas.SetLeft(this, rect.X); - Canvas.SetTop(this, rect.Y); - Model.Zones[ZoneIndex] = rect; + private SnappyHelperBase NewDefaultSnappyHelper(bool isX, ResizeMode mode, int screenAxisSize) + { + return new SnappyHelperMagnetic(Model.Zones, ZoneIndex, isX, mode, screenAxisSize); } - private void Size(double xDelta, double yDelta) + private void UpdateFromSnappyHelpers() { Int32Rect rect = Model.Zones[ZoneIndex]; - if (xDelta != 0) - { - int newWidth = rect.Width + (int)xDelta; - if (newWidth < _minZoneWidth) + if (snappyX != null) + { + if (snappyX.Mode == ResizeMode.BottomEdge) + { + int changeX = snappyX.Position - rect.X; + rect.X += changeX; + rect.Width -= changeX; + } + else if (snappyX.Mode == ResizeMode.TopEdge) { - newWidth = _minZoneWidth; + rect.Width = snappyX.Position - rect.X; } - else if (newWidth > (_settings.WorkArea.Width - rect.X)) + else { - newWidth = (int)_settings.WorkArea.Width - rect.X; + int changeX = snappyX.Position - rect.X; + rect.X += changeX; } - MinWidth = rect.Width = newWidth; + Canvas.SetLeft(this, rect.X); + Width = rect.Width; } - if (yDelta != 0) + if (snappyY != null) { - int newHeight = rect.Height + (int)yDelta; - - if (newHeight < _minZoneHeight) + if (snappyY.Mode == ResizeMode.BottomEdge) + { + int changeY = snappyY.Position - rect.Y; + rect.Y += changeY; + rect.Height -= changeY; + } + else if (snappyY.Mode == ResizeMode.TopEdge) { - newHeight = _minZoneHeight; + rect.Height = snappyY.Position - rect.Y; } - else if (newHeight > (_settings.WorkArea.Height - rect.Y)) + else { - newHeight = (int)_settings.WorkArea.Height - rect.Y; + int changeY = snappyY.Position - rect.Y; + rect.Y += changeY; } - MinHeight = rect.Height = newHeight; + Canvas.SetTop(this, rect.Y); + Height = rect.Height; } Model.Zones[ZoneIndex] = rect; } + private static int zIndex = 0; + private const int MinZoneWidth = 64; + private const int MinZoneHeight = 72; + protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { - Panel.SetZIndex(this, _zIndex++); + Canvas.SetZIndex(this, zIndex++); base.OnPreviewMouseDown(e); } - private void NWResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + private void UniversalDragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) { - SizeMove(e.HorizontalChange, e.VerticalChange); + if (snappyX != null) + { + snappyX.Move((int)e.HorizontalChange); + } + + if (snappyY != null) + { + snappyY.Move((int)e.VerticalChange); + } + + UpdateFromSnappyHelpers(); } - private void NEResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + private void OnClose(object sender, RoutedEventArgs e) { - SizeMove(0, e.VerticalChange); - Size(e.HorizontalChange, 0); + ((Panel)Parent).Children.Remove(this); + Model.RemoveZoneAt(ZoneIndex); } - private void SWResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + // Corner dragging + private void Caption_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - SizeMove(e.HorizontalChange, 0); - Size(0, e.VerticalChange); + snappyX = NewDefaultSnappyHelper(true, ResizeMode.BothEdges, (int)_settings.WorkArea.Width); + snappyY = NewDefaultSnappyHelper(false, ResizeMode.BothEdges, (int)_settings.WorkArea.Height); } - private void SEResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + public CanvasLayoutModel Model { get => model; set => model = value; } + + public int ZoneIndex { get => zoneIndex; set => zoneIndex = value; } + + private void NWResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - Size(e.HorizontalChange, e.VerticalChange); + snappyX = NewDefaultSnappyHelper(true, ResizeMode.BottomEdge, (int)_settings.WorkArea.Width); + snappyY = NewDefaultSnappyHelper(false, ResizeMode.BottomEdge, (int)_settings.WorkArea.Height); } - private void NResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + private void NEResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - SizeMove(0, e.VerticalChange); + snappyX = NewDefaultSnappyHelper(true, ResizeMode.TopEdge, (int)_settings.WorkArea.Width); + snappyY = NewDefaultSnappyHelper(false, ResizeMode.BottomEdge, (int)_settings.WorkArea.Height); } - private void SResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + private void SWResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - Size(0, e.VerticalChange); + snappyX = NewDefaultSnappyHelper(true, ResizeMode.BottomEdge, (int)_settings.WorkArea.Width); + snappyY = NewDefaultSnappyHelper(false, ResizeMode.TopEdge, (int)_settings.WorkArea.Height); } - private void WResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + private void SEResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - SizeMove(e.HorizontalChange, 0); + snappyX = NewDefaultSnappyHelper(true, ResizeMode.TopEdge, (int)_settings.WorkArea.Width); + snappyY = NewDefaultSnappyHelper(false, ResizeMode.TopEdge, (int)_settings.WorkArea.Height); } - private void EResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + // Edge dragging + private void NResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - Size(e.HorizontalChange, 0); + snappyX = null; + snappyY = NewDefaultSnappyHelper(false, ResizeMode.BottomEdge, (int)_settings.WorkArea.Height); } - private void Caption_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) + private void SResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - Move(e.HorizontalChange, e.VerticalChange); + snappyX = null; + snappyY = NewDefaultSnappyHelper(false, ResizeMode.TopEdge, (int)_settings.WorkArea.Height); } - private void OnClose(object sender, RoutedEventArgs e) + private void WResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { - ((Panel)Parent).Children.Remove(this); - Model.RemoveZoneAt(ZoneIndex); + snappyX = NewDefaultSnappyHelper(true, ResizeMode.BottomEdge, (int)_settings.WorkArea.Width); + snappyY = null; + } + + private void EResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) + { + snappyX = NewDefaultSnappyHelper(true, ResizeMode.TopEdge, (int)_settings.WorkArea.Width); + snappyY = null; } } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs index ed11e357ddd2..b163f5bc1613 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs @@ -16,17 +16,19 @@ protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e) EditorOverlay mainEditor = EditorOverlay.Current; if (mainEditor.DataContext is LayoutModel model) { - model.Persist(mainEditor.GetZoneRects()); + model.Persist(); } - _choosing = true; + LayoutModel.SerializeDeletedCustomZoneSets(); + + _backToLayoutPicker = false; Close(); EditorOverlay.Current.Close(); } protected void OnClosed(object sender, EventArgs e) { - if (!_choosing) + if (_backToLayoutPicker) { EditorOverlay.Current.ShowLayoutPicker(); } @@ -34,11 +36,10 @@ protected void OnClosed(object sender, EventArgs e) protected void OnCancel(object sender, RoutedEventArgs e) { - _choosing = true; + _backToLayoutPicker = true; Close(); - EditorOverlay.Current.ShowLayoutPicker(); } - private bool _choosing = false; + private bool _backToLayoutPicker = true; } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs index 2183a3a91d3b..a4d8b7595330 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs @@ -134,83 +134,50 @@ private void OnFullSplit(object o, SplitEventArgs e) private void ExtendRangeToHaveEvenCellEdges() { - // extend each edge of the [(_startCol, _startRow) - (_endCol, _endRow)] range based on merged cells until you have 4 straight edges with no "straddling cells" + // As long as there is an edge of the 2D range such that some zone crosses its boundary, extend + // that boundary. A single pass is not enough, a while loop is needed. This results in the unique + // smallest rectangle containing the initial range such that no zone is "broken", meaning that + // some part of it is inside the 2D range, and some part is outside. GridLayoutModel model = Model; + bool possiblyBroken = true; - while (_startRow > 0) + while (possiblyBroken) { - bool dirty = false; + possiblyBroken = false; + for (int col = _startCol; col <= _endCol; col++) { - if (model.CellChildMap[_startRow - 1, col] == model.CellChildMap[_startRow, col]) + if (_startRow > 0 && model.CellChildMap[_startRow - 1, col] == model.CellChildMap[_startRow, col]) { _startRow--; - dirty = true; + possiblyBroken = true; break; } - } - - if (!dirty) - { - break; - } - } - while (_endRow < model.Rows - 1) - { - bool dirty = false; - for (int col = _startCol; col <= _endCol; col++) - { - if (model.CellChildMap[_endRow + 1, col] == model.CellChildMap[_endRow, col]) + if (_endRow < model.Rows - 1 && model.CellChildMap[_endRow + 1, col] == model.CellChildMap[_endRow, col]) { _endRow++; - dirty = true; + possiblyBroken = true; break; } } - if (!dirty) - { - break; - } - } - - while (_startCol > 0) - { - bool dirty = false; for (int row = _startRow; row <= _endRow; row++) { - if (model.CellChildMap[row, _startCol - 1] == model.CellChildMap[row, _startCol]) + if (_startCol > 0 && model.CellChildMap[row, _startCol - 1] == model.CellChildMap[row, _startCol]) { _startCol--; - dirty = true; + possiblyBroken = true; break; } - } - - if (!dirty) - { - break; - } - } - while (_endCol < model.Columns - 1) - { - bool dirty = false; - for (int row = _startRow; row <= _endRow; row++) - { - if (model.CellChildMap[row, _endCol + 1] == model.CellChildMap[row, _endCol]) + if (_endCol < model.Columns - 1 && model.CellChildMap[row, _endCol + 1] == model.CellChildMap[row, _endCol]) { _endCol++; - dirty = true; + possiblyBroken = true; break; } } - - if (!dirty) - { - break; - } } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditorWindow.xaml b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditorWindow.xaml index 6c0f34225a60..9e7e74ac27e0 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditorWindow.xaml +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditorWindow.xaml @@ -21,7 +21,7 @@ - + - + - + - + - +