mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-01 09:59:06 +08:00
[FZ Editor] Turn off magnetic snapping when moving/resizing a zone with the keyboard (#11430)
This commit is contained in:
parent
9f6e1966ae
commit
7180278c33
@ -19,7 +19,8 @@ namespace FancyZonesEditor
|
||||
/// </summary>
|
||||
public partial class CanvasZone : UserControl
|
||||
{
|
||||
private readonly int moveAmount = 10;
|
||||
private readonly int defaultMoveAmount = 10;
|
||||
private readonly int smallMoveAmount = 1;
|
||||
|
||||
public CanvasZone()
|
||||
{
|
||||
@ -220,10 +221,24 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
|
||||
private class SnappyHelperNonMagnetic : SnappyHelperBase
|
||||
{
|
||||
public SnappyHelperNonMagnetic(IList<Int32Rect> zones, int zoneIndex, bool isX, ResizeMode mode, int screenAxisOrigin, int screenAxisSize)
|
||||
: base(zones, zoneIndex, isX, mode, screenAxisOrigin, screenAxisSize)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Move(int delta)
|
||||
{
|
||||
var pos = Position + delta;
|
||||
Position = Math.Max(Math.Min(MaxValue, pos), MinValue);
|
||||
}
|
||||
}
|
||||
|
||||
private SnappyHelperBase snappyX;
|
||||
private SnappyHelperBase snappyY;
|
||||
|
||||
private SnappyHelperBase NewDefaultSnappyHelper(bool isX, ResizeMode mode)
|
||||
private SnappyHelperBase NewMagneticSnapper(bool isX, ResizeMode mode)
|
||||
{
|
||||
Rect workingArea = App.Overlay.WorkArea;
|
||||
int screenAxisOrigin = (int)(isX ? workingArea.Left : workingArea.Top);
|
||||
@ -231,6 +246,14 @@ namespace FancyZonesEditor
|
||||
return new SnappyHelperMagnetic(Model.Zones, ZoneIndex, isX, mode, screenAxisOrigin, screenAxisSize);
|
||||
}
|
||||
|
||||
private SnappyHelperBase NewNonMagneticSnapper(bool isX, ResizeMode mode)
|
||||
{
|
||||
Rect workingArea = App.Overlay.WorkArea;
|
||||
int screenAxisOrigin = (int)(isX ? workingArea.Left : workingArea.Top);
|
||||
int screenAxisSize = (int)(isX ? workingArea.Width : workingArea.Height);
|
||||
return new SnappyHelperNonMagnetic(Model.Zones, ZoneIndex, isX, mode, screenAxisOrigin, screenAxisSize);
|
||||
}
|
||||
|
||||
private void UpdateFromSnappyHelpers()
|
||||
{
|
||||
Int32Rect rect = Model.Zones[ZoneIndex];
|
||||
@ -310,8 +333,8 @@ namespace FancyZonesEditor
|
||||
// Corner dragging
|
||||
private void Caption_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, ResizeMode.BothEdges);
|
||||
snappyY = NewDefaultSnappyHelper(false, ResizeMode.BothEdges);
|
||||
snappyX = NewMagneticSnapper(true, ResizeMode.BothEdges);
|
||||
snappyY = NewMagneticSnapper(false, ResizeMode.BothEdges);
|
||||
}
|
||||
|
||||
public CanvasLayoutModel Model { get => model; set => model = value; }
|
||||
@ -320,50 +343,50 @@ namespace FancyZonesEditor
|
||||
|
||||
private void NWResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, ResizeMode.BottomEdge);
|
||||
snappyY = NewDefaultSnappyHelper(false, ResizeMode.BottomEdge);
|
||||
snappyX = NewMagneticSnapper(true, ResizeMode.BottomEdge);
|
||||
snappyY = NewMagneticSnapper(false, ResizeMode.BottomEdge);
|
||||
}
|
||||
|
||||
private void NEResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, ResizeMode.TopEdge);
|
||||
snappyY = NewDefaultSnappyHelper(false, ResizeMode.BottomEdge);
|
||||
snappyX = NewMagneticSnapper(true, ResizeMode.TopEdge);
|
||||
snappyY = NewMagneticSnapper(false, ResizeMode.BottomEdge);
|
||||
}
|
||||
|
||||
private void SWResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, ResizeMode.BottomEdge);
|
||||
snappyY = NewDefaultSnappyHelper(false, ResizeMode.TopEdge);
|
||||
snappyX = NewMagneticSnapper(true, ResizeMode.BottomEdge);
|
||||
snappyY = NewMagneticSnapper(false, ResizeMode.TopEdge);
|
||||
}
|
||||
|
||||
private void SEResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, ResizeMode.TopEdge);
|
||||
snappyY = NewDefaultSnappyHelper(false, ResizeMode.TopEdge);
|
||||
snappyX = NewMagneticSnapper(true, ResizeMode.TopEdge);
|
||||
snappyY = NewMagneticSnapper(false, ResizeMode.TopEdge);
|
||||
}
|
||||
|
||||
// Edge dragging
|
||||
private void NResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = null;
|
||||
snappyY = NewDefaultSnappyHelper(false, ResizeMode.BottomEdge);
|
||||
snappyY = NewMagneticSnapper(false, ResizeMode.BottomEdge);
|
||||
}
|
||||
|
||||
private void SResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = null;
|
||||
snappyY = NewDefaultSnappyHelper(false, ResizeMode.TopEdge);
|
||||
snappyY = NewMagneticSnapper(false, ResizeMode.TopEdge);
|
||||
}
|
||||
|
||||
private void WResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, ResizeMode.BottomEdge);
|
||||
snappyX = NewMagneticSnapper(true, ResizeMode.BottomEdge);
|
||||
snappyY = null;
|
||||
}
|
||||
|
||||
private void EResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, ResizeMode.TopEdge);
|
||||
snappyX = NewMagneticSnapper(true, ResizeMode.TopEdge);
|
||||
snappyY = null;
|
||||
}
|
||||
|
||||
@ -380,39 +403,51 @@ namespace FancyZonesEditor
|
||||
|
||||
private void Border_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key != Key.Tab)
|
||||
if (e.Key == Key.Tab)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
|
||||
if (e.Key == Key.Delete)
|
||||
{
|
||||
RemoveZone();
|
||||
return;
|
||||
}
|
||||
else if (e.Key == Key.Right)
|
||||
|
||||
var moveValue = IsCtrlKeyDown() ? smallMoveAmount : defaultMoveAmount;
|
||||
if (IsShiftKeyDown())
|
||||
{
|
||||
moveValue = Math.Max(1, moveValue / 2);
|
||||
}
|
||||
|
||||
if (e.Key == Key.Right)
|
||||
{
|
||||
if (IsShiftKeyDown())
|
||||
{
|
||||
// Make the zone larger (height)
|
||||
MoveZoneX(moveAmount / 2, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneX(-moveAmount / 2, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
// Make the zone larger (width)
|
||||
MoveZoneX(moveValue, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneX(-moveValue, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move zone right
|
||||
MoveZoneX(moveAmount, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
MoveZoneX(moveValue, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
}
|
||||
}
|
||||
else if (e.Key == Key.Left)
|
||||
{
|
||||
if (IsShiftKeyDown())
|
||||
{
|
||||
// Make the zone smaller (height)
|
||||
MoveZoneX(-moveAmount / 2, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneX(moveAmount / 2, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
// Make the zone smaller (width)
|
||||
MoveZoneX(-moveValue, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneX(moveValue, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move zone left
|
||||
MoveZoneX(-moveAmount, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
MoveZoneX(-moveValue, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
}
|
||||
}
|
||||
else if (e.Key == Key.Up)
|
||||
@ -420,13 +455,13 @@ namespace FancyZonesEditor
|
||||
if (IsShiftKeyDown())
|
||||
{
|
||||
// Make the zone larger (height)
|
||||
MoveZoneY(moveAmount / 2, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneY(-moveAmount / 2, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneY(moveValue, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneY(-moveValue, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move zone up
|
||||
MoveZoneY(-moveAmount, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
MoveZoneY(-moveValue, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
}
|
||||
}
|
||||
else if (e.Key == Key.Down)
|
||||
@ -434,30 +469,29 @@ namespace FancyZonesEditor
|
||||
if (IsShiftKeyDown())
|
||||
{
|
||||
// Make the zone smaller (height)
|
||||
MoveZoneY(-moveAmount / 2, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneY(moveAmount / 2, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneY(-moveValue, ResizeMode.TopEdge, ResizeMode.BottomEdge);
|
||||
MoveZoneY(moveValue, ResizeMode.BottomEdge, ResizeMode.BottomEdge);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move zone down
|
||||
MoveZoneY(moveAmount, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
}
|
||||
MoveZoneY(moveValue, ResizeMode.BothEdges, ResizeMode.BothEdges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveZoneX(int value, ResizeMode top, ResizeMode bottom)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, top);
|
||||
snappyY = NewDefaultSnappyHelper(false, bottom);
|
||||
snappyX = NewNonMagneticSnapper(true, top);
|
||||
snappyY = NewNonMagneticSnapper(false, bottom);
|
||||
snappyX.Move(value);
|
||||
UpdateFromSnappyHelpers();
|
||||
}
|
||||
|
||||
private void MoveZoneY(int value, ResizeMode top, ResizeMode bottom)
|
||||
{
|
||||
snappyX = NewDefaultSnappyHelper(true, bottom);
|
||||
snappyY = NewDefaultSnappyHelper(false, top);
|
||||
snappyX = NewNonMagneticSnapper(true, bottom);
|
||||
snappyY = NewNonMagneticSnapper(false, top);
|
||||
snappyY.Move(value);
|
||||
UpdateFromSnappyHelpers();
|
||||
}
|
||||
@ -474,6 +508,18 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsCtrlKeyDown()
|
||||
{
|
||||
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Border_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// Set (keyboard)focus on this zone when click
|
||||
|
Loading…
Reference in New Issue
Block a user