mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-08 01:52:52 +08:00
[FancyZones Editor] Scale canvas layout on editing (#17668)
* canvas scaling * zero check
This commit is contained in:
parent
1727f2b813
commit
038e8e1510
@ -51,6 +51,10 @@ namespace FancyZonesEditor
|
|||||||
if (model != null)
|
if (model != null)
|
||||||
{
|
{
|
||||||
_model = model;
|
_model = model;
|
||||||
|
|
||||||
|
var workArea = App.Overlay.WorkArea;
|
||||||
|
_model.ScaleLayout(workAreaWidth: workArea.Width, workAreaHeight: workArea.Height);
|
||||||
|
|
||||||
UpdateZoneRects();
|
UpdateZoneRects();
|
||||||
|
|
||||||
_model.PropertyChanged += OnModelChanged;
|
_model.PropertyChanged += OnModelChanged;
|
||||||
|
@ -91,6 +91,30 @@ namespace FancyZonesEditor.Models
|
|||||||
UpdateLayout();
|
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()
|
private void AddNewZone()
|
||||||
{
|
{
|
||||||
if (Zones.Count == 0)
|
if (Zones.Count == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user