[FancyZones Editor] Scale canvas layout on editing (#17668)

* canvas scaling

* zero check
This commit is contained in:
Seraphima Zykova 2022-04-14 17:08:15 +03:00 committed by GitHub
parent 1727f2b813
commit 038e8e1510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -51,6 +51,10 @@ namespace FancyZonesEditor
if (model != null)
{
_model = model;
var workArea = App.Overlay.WorkArea;
_model.ScaleLayout(workAreaWidth: workArea.Width, workAreaHeight: workArea.Height);
UpdateZoneRects();
_model.PropertyChanged += OnModelChanged;

View File

@ -91,6 +91,30 @@ namespace FancyZonesEditor.Models
UpdateLayout();
}
public void ScaleLayout(double workAreaWidth, double workAreaHeight)
{
if (CanvasRect.Height == 0 || CanvasRect.Width == 0)
{
return;
}
Int32Rect[] zones = new Int32Rect[Zones.Count];
Zones.CopyTo(zones, 0);
Zones.Clear();
foreach (Int32Rect zone in zones)
{
var x = zone.X * workAreaWidth / CanvasRect.Width;
var y = zone.Y * workAreaHeight / CanvasRect.Height;
var width = zone.Width * workAreaWidth / CanvasRect.Width;
var height = zone.Height * workAreaHeight / CanvasRect.Height;
Zones.Add(new Int32Rect(x: (int)x, y: (int)y, width: (int)width, height: (int)height));
}
CanvasRect = new Rect(CanvasRect.X, CanvasRect.Y, workAreaWidth, workAreaHeight);
}
private void AddNewZone()
{
if (Zones.Count == 0)