Files
OpenNest/OpenNest.Avalonia/MainWindow.Zoom.cs
T
ajandClaude Opus 5.5 ca6e8cd4ce feat(avalonia): zoom commands, zoom window, measure area and plate menu items
View > Zoom To (Area, Fit, Plate, Selected), Zoom In (Ctrl+Plus) and Zoom Out
(Ctrl+Minus), the nest header's zoom buttons, Nest > First/Last/Next
(Ctrl+Right)/Previous (Ctrl+Left) Plate and Tools > Measure Area, as WinForms.
The wheel zooms by the WinForms step, panning hides the hover highlight, and
resting on a part shows its drawing name after a second.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 20:09:17 -05:00

66 lines
2.4 KiB
C#

using System;
using Avalonia.Input;
using Avalonia.Interactivity;
using OpenNest.Avalonia.Controls;
namespace OpenNest.Avalonia
{
/// <summary>
/// View &gt; Zoom To (Area, Fit, Plate, Selected), Zoom In (Ctrl+Plus) and Zoom Out
/// (Ctrl+Minus); Nest &gt; First, Last, Next (Ctrl+Right) and Previous (Ctrl+Left) Plate; and
/// Tools &gt; Measure Area, as the WinForms main form's menus.
/// </summary>
public partial class MainWindow
{
private void AddViewKeyBindings()
{
foreach (var (key, action) in new (Key, Action)[]
{
(Key.OemPlus, () => OnZoomIn(null, null)),
(Key.OemMinus, () => OnZoomOut(null, null)),
(Key.Right, () => StepPlate(1)),
(Key.Left, () => StepPlate(-1)),
})
{
KeyBindings.Add(new KeyBinding
{
Gesture = new KeyGesture(key, KeyModifiers.Control),
Command = new Command(action),
});
}
}
private void OnZoomIn(object sender, RoutedEventArgs e) => ActiveView?.PlateView.ZoomIn();
private void OnZoomOut(object sender, RoutedEventArgs e) => ActiveView?.PlateView.ZoomOut();
private void OnZoomToPlate(object sender, RoutedEventArgs e) => ActiveView?.PlateView.ZoomToPlate();
private void OnZoomToSelected(object sender, RoutedEventArgs e) => ActiveView?.PlateView.ZoomToSelected();
private void OnZoomToArea(object sender, RoutedEventArgs e) => StartTool(canvas => canvas.StartZoomWindow());
private void OnMeasureArea(object sender, RoutedEventArgs e) => StartTool(canvas => canvas.StartMeasureArea());
// The view takes the keyboard, so Escape (and Space for Measure Area) reach the tool after
// a menu click.
private void StartTool(Action<PlateCanvas> start)
{
if (ActiveView is not { PlateView: { } canvas } view)
return;
start(canvas);
// Focusing the view would otherwise place a drawing picked up in the list.
view.CancelPickup();
canvas.Focus();
}
private void OnFirstPlate(object sender, RoutedEventArgs e) => ActiveView?.ShowPlate(0);
private void OnLastPlate(object sender, RoutedEventArgs e)
{
if (ActiveView is { } view)
view.ShowPlate(view.PlateCount - 1);
}
}
}