diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs index e898e3e8ec..12a3c007d1 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs @@ -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; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/CanvasLayoutModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/CanvasLayoutModel.cs index e8f13bb7b8..bad7a06aef 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/CanvasLayoutModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/CanvasLayoutModel.cs @@ -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)