Skip to content

Commit

Permalink
fixed a bunch more
Browse files Browse the repository at this point in the history
  • Loading branch information
crutkas committed Dec 12, 2019
1 parent 4c88c9b commit 151a937
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 173 deletions.
26 changes: 13 additions & 13 deletions src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class CanvasZone : UserControl
public CanvasZone()
{
InitializeComponent();
Canvas.SetZIndex(this, c_zIndex++);
Panel.SetZIndex(this, _zIndex++);
}

public CanvasLayoutModel Model;
Expand Down Expand Up @@ -66,9 +66,9 @@ private void SizeMove(double xDelta, double yDelta)
}
else if (xDelta > 0)
{
if ((rect.Width - (int)xDelta) < c_minZoneWidth)
if ((rect.Width - (int)xDelta) < _minZoneWidth)
{
xDelta = rect.Width - c_minZoneWidth;
xDelta = rect.Width - _minZoneWidth;
}
}

Expand All @@ -81,9 +81,9 @@ private void SizeMove(double xDelta, double yDelta)
}
else if (yDelta > 0)
{
if ((rect.Height - (int)yDelta) < c_minZoneHeight)
if ((rect.Height - (int)yDelta) < _minZoneHeight)
{
yDelta = rect.Height - c_minZoneHeight;
yDelta = rect.Height - _minZoneHeight;
}
}

Expand All @@ -107,9 +107,9 @@ private void Size(double xDelta, double yDelta)
{
int newWidth = rect.Width + (int)xDelta;

if (newWidth < c_minZoneWidth)
if (newWidth < _minZoneWidth)
{
newWidth = c_minZoneWidth;
newWidth = _minZoneWidth;
}
else if (newWidth > (_settings.WorkArea.Width - rect.X))
{
Expand All @@ -123,9 +123,9 @@ private void Size(double xDelta, double yDelta)
{
int newHeight = rect.Height + (int)yDelta;

if (newHeight < c_minZoneHeight)
if (newHeight < _minZoneHeight)
{
newHeight = c_minZoneHeight;
newHeight = _minZoneHeight;
}
else if (newHeight > (_settings.WorkArea.Height - rect.Y))
{
Expand All @@ -138,13 +138,13 @@ private void Size(double xDelta, double yDelta)
Model.Zones[ZoneIndex] = rect;
}

private static int c_zIndex = 0;
private static int c_minZoneWidth = 64;
private static int c_minZoneHeight = 72;
private static int _zIndex = 0;
private static int _minZoneWidth = 64;
private static int _minZoneHeight = 72;

protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
Canvas.SetZIndex(this, c_zIndex++);
Panel.SetZIndex(this, _zIndex++);
base.OnPreviewMouseDown(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ namespace FancyZonesEditor
/// </summary>
public partial class EditorOverlay : Window
{
public static EditorOverlay Current { get; set; }

public Int32Rect[] GetZoneRects()
{
// TODO: the ideal here is that the ArrangeRects logic is entirely inside the model, so we don't have to walk the UIElement children to get the rect info
Panel previewPanel = null;

Panel previewPanel;
if (_editor != null)
{
GridEditor gridEditor = _editor as GridEditor;
if (gridEditor != null)
if (_editor is GridEditor gridEditor)
{
previewPanel = gridEditor.PreviewPanel;
}
else
{
//CanvasEditor
// CanvasEditor
previewPanel = ((CanvasEditor)_editor).Preview;
}
}
Expand All @@ -43,7 +43,7 @@ public Int32Rect[] GetZoneRects()
int i = 0;
foreach (FrameworkElement child in previewPanel.Children)
{
Point topLeft = child.TransformToAncestor(previewPanel).Transform(new Point());
Point topLeft = child.TransformToAncestor(previewPanel).Transform(default(Point));

var right = topLeft.X + child.ActualWidth;
var bottom = topLeft.Y + child.ActualHeight;
Expand All @@ -57,8 +57,6 @@ public Int32Rect[] GetZoneRects()
return zones;
}

public static EditorOverlay Current;

public EditorOverlay()
{
InitializeComponent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public class EditorWindow : MetroWindow
protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e)
{
EditorOverlay mainEditor = EditorOverlay.Current;
LayoutModel model = mainEditor.DataContext as LayoutModel;
var model = mainEditor.DataContext as LayoutModel;
if (model != null)
{
model.Persist(mainEditor.GetZoneRects());
}

_choosing = true;
this.Close();
Close();
EditorOverlay.Current.Close();
}

Expand All @@ -36,7 +36,7 @@ protected void OnClosed(object sender, EventArgs e)
protected void OnCancel(object sender, RoutedEventArgs e)
{
_choosing = true;
this.Close();
Close();
EditorOverlay.Current.ShowLayoutPicker();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<DependentUpon>EditorOverlay.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\ModelToVisibilityConverter.xaml.cs" />
<Compile Include="Native.cs" />
<Compile Include="RowColInfo.cs" />
<Compile Include="GridEditorWindow.xaml.cs">
<DependentUpon>GridEditorWindow.xaml</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// 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.

// This file is used by Code Analysis to maintain SuppressMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ private void OnSplit(object o, SplitEventArgs e)

model.Columns++;
}
else // Horizontal
else
{
// Horizontal
if (splitee.HorizontalSnapPoints != null)
{
offset += Canvas.GetTop(splitee);
Expand Down Expand Up @@ -553,7 +554,7 @@ private void ArrangeGridRects(Size arrangeSize)
return;
}

Settings settings = ((App)(Application.Current)).ZoneSettings;
Settings settings = ((App)Application.Current).ZoneSettings;
int spacing = settings.Spacing;
int gutter = settings.Spacing;

Expand All @@ -566,14 +567,14 @@ private void ArrangeGridRects(Size arrangeSize)
double top = gutter;
for (int row = 0; row < rows; row++)
{
double cellHeight = _rowInfo[row].SetExtent(top, totalHeight);
double cellHeight = _rowInfo[row].Recalculate(top, totalHeight);
top += cellHeight + spacing;
}

double left = gutter;
for (int col = 0; col < cols; col++)
{
double cellWidth = _colInfo[col].SetExtent(left, totalWidth);
double cellWidth = _colInfo[col].Recalculate(left, totalWidth);
left += cellWidth + spacing;
}

Expand Down Expand Up @@ -861,7 +862,7 @@ private void OnMergeDrag(object o, MouseEventArgs e)
e.Handled = true;
}

base.OnPreviewMouseMove(e);
OnPreviewMouseMove(e);
}

private void ClearSelection()
Expand Down
46 changes: 25 additions & 21 deletions src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ public partial class GridZone : UserControl
{
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged));

public event SplitEventHandler Split;

public event SplitEventHandler FullSplit;

public event MouseEventHandler MergeDrag;

public event MouseButtonEventHandler MergeComplete;

public double[] VerticalSnapPoints { get; set; }

public double[] HorizontalSnapPoints { get; set; }

private Rectangle _splitter;
private bool _switchOrientation = false;
private Point _lastPos = new Point(-1, -1);
private Point _mouseDownPos = new Point(-1, -1);
private bool _inMergeDrag = false;
private Orientation _splitOrientation;

private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((GridZone)d).OnSelectionChanged();
Expand All @@ -35,15 +54,14 @@ public bool IsSelected
set { SetValue(IsSelectedProperty, value); }
}

public double[] VerticalSnapPoints;
public double[] HorizontalSnapPoints;

public GridZone()
{
InitializeComponent();
OnSelectionChanged();
_splitter = new Rectangle();
_splitter.Fill = Brushes.DarkGray;
_splitter = new Rectangle
{
Fill = Brushes.DarkGray,
};
Body.Children.Add(_splitter);

((App)Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged;
Expand Down Expand Up @@ -169,8 +187,9 @@ protected override void OnMouseMove(MouseEventArgs e)
}
}
}
else // horizontal split
else
{
// horizontal split
if (HorizontalSnapPoints != null)
{
int thickness = SplitterThickness;
Expand Down Expand Up @@ -237,21 +256,6 @@ protected override void OnMouseUp(MouseButtonEventArgs e)
base.OnMouseUp(e);
}

public event SplitEventHandler Split;

public event SplitEventHandler FullSplit;

public event MouseEventHandler MergeDrag;

public event MouseButtonEventHandler MergeComplete;

private Rectangle _splitter;
private bool _switchOrientation = false;
private Point _lastPos = new Point(-1,-1);
private Point _mouseDownPos = new Point(-1,-1);
private bool _inMergeDrag = false;
private Orientation _splitOrientation;

private void DoMergeDrag(MouseEventArgs e)
{
if (MergeDrag != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ private void RenderPreview()

Body.Children.Clear();

GridLayoutModel gridModel = _model as GridLayoutModel;
if (gridModel != null)
if (_model is GridLayoutModel gridModel)
{
RenderGridPreview(gridModel);
}
else
{
CanvasLayoutModel canvasModel = _model as CanvasLayoutModel;
var canvasModel = _model as CanvasLayoutModel;
if (canvasModel != null)
{
RenderCanvasPreview(canvasModel);
Expand Down Expand Up @@ -126,7 +125,7 @@ private void RenderGridPreview(GridLayoutModel grid)
{
for (int col = 0; col < grid.Columns; col++)
{
int childIndex = grid.CellChildMap[row,col];
int childIndex = grid.CellChildMap[row, col];
if (!visited.Contains(childIndex))
{
visited.Add(childIndex);
Expand All @@ -135,7 +134,7 @@ private void RenderGridPreview(GridLayoutModel grid)
Grid.SetColumn(rect, col);
int span = 1;
int walk = row + 1;
while ((walk < grid.Rows) && grid.CellChildMap[walk,col] == childIndex)
while ((walk < grid.Rows) && grid.CellChildMap[walk, col] == childIndex)
{
span++;
walk++;
Expand Down

0 comments on commit 151a937

Please sign in to comment.