Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Aug 8, 2024
1 parent de79aaa commit efcc522
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/OneWare.Essentials/Controls/CustomZoomBorder.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.PanAndZoom;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.ReactiveUI;
using Avalonia.Threading;

namespace OneWare.Essentials.Controls;

public class CustomZoomBorder : ZoomBorder
{
private const int KeyPanSpeed = 5;

protected override Type StyleKeyOverride => typeof(ZoomBorder);

private CompositeDisposable _disposables = new();

private readonly List<Key> _keysDown = [];
Expand All @@ -23,11 +23,6 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);

PointerEntered += (_, _) =>
{
this.Focus();
};

DispatcherTimer.Run(() =>
{
if (_keysDown.Contains(Key.Down) || _keysDown.Contains(Key.S))
Expand All @@ -42,6 +37,16 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
return true;
}, TimeSpan.FromMilliseconds(10))
.DisposeWith(_disposables);

KeyDownEvent.AddClassHandler<TopLevel>((sender, args) =>
{
if(IsPointerOver) _keysDown.Add(args.Key);
}, handledEventsToo: true).DisposeWith(_disposables);

KeyUpEvent.AddClassHandler<TopLevel>((sender, args) =>
{
_keysDown.RemoveAll(x => x == args.Key);
}, handledEventsToo: true).DisposeWith(_disposables);
}

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
Expand All @@ -51,22 +56,10 @@ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e
_disposables = new CompositeDisposable();
}

protected override void OnKeyDown(KeyEventArgs e)
{
_keysDown.Add(e.Key);
base.OnKeyDown(e);
}

protected override void OnKeyUp(KeyEventArgs e)
{
_keysDown.RemoveAll(x => x == e.Key);
base.OnKeyUp(e);
}

protected override void OnLostFocus(RoutedEventArgs e)
protected override void OnPointerExited(PointerEventArgs e)
{
_keysDown.Clear();
base.OnLostFocus(e);
base.OnPointerExited(e);
}

public void AutoFit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<Interaction.Behaviors>
<behaviors:CommandOnKeyPressedBehavior HandledEventsToo="True" TriggerKey="Delete"
Command="{Binding SelectedFpgaModel.DisconnectCommand, FallbackValue={x:Null}}" />
<behaviors:CommandOnKeyPressedBehavior HandledEventsToo="False" TriggerKey="Back"
Command="{Binding SelectedFpgaModel.DisconnectCommand, FallbackValue={x:Null}}" />
<behaviors:CommandOnKeyPressedBehavior HandledEventsToo="True" TriggerKey="Enter"
Command="{Binding SelectedFpgaModel.ConnectCommand, FallbackValue={x:Null}}" />
<behaviors:CommandOnKeyPressedBehavior TriggerKey="Escape"
Expand Down

0 comments on commit efcc522

Please sign in to comment.