Skip to content

Commit fb25678

Browse files
authored
Activate a clickable SettingsCard on release instead of on press (#5478)
1 parent af1431e commit fb25678

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎src/UniGetUI.Avalonia/Views/Controls/Settings/SettingsCard.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Avalonia.Interactivity;
77
using Avalonia.Layout;
88
using Avalonia.Media;
9+
using Avalonia.VisualTree;
910
using UniGetUI.Avalonia.Views.Controls;
1011
using UniGetUI.Core.Tools;
1112
using ICommand = System.Windows.Input.ICommand;
@@ -54,6 +55,7 @@ public class SettingsCard : UserControl
5455
private Control? _headerIcon;
5556
private object? _rightContent;
5657
private bool _isClickEnabled;
58+
private bool _pointerPressed;
5759

5860
/// <summary>
5961
/// Keep compact toggle-style content at the right edge when the card wraps.
@@ -239,6 +241,8 @@ public SettingsCard()
239241
base.Content = _border;
240242

241243
PointerPressed += OnPointerPressed;
244+
PointerReleased += OnPointerReleased;
245+
PointerCaptureLost += OnPointerCaptureLost;
242246
KeyDown += OnKeyDown;
243247
SizeChanged += (_, e) => UpdateResponsiveLayout(e.NewSize.Width);
244248
// Keyboard focus keeps the SettingsCard itself as the focus target. A card-specific
@@ -395,10 +399,28 @@ private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
395399

396400
// Pointer activation leaves the card's normal stroke untouched; keyboard focus is
397401
// handled solely by the external focus adorner.
402+
_pointerPressed = true;
403+
e.Handled = true;
404+
}
405+
406+
private void OnPointerReleased(object? sender, PointerReleasedEventArgs e)
407+
{
408+
if (!_pointerPressed) return;
409+
_pointerPressed = false;
410+
411+
if (!_isClickEnabled) return;
412+
if (e.InitialPressMouseButton is not MouseButton.Left) return;
413+
if (!this.GetVisualsAt(e.GetPosition(this)).Any(c => this == c || this.IsVisualAncestorOf(c))) return;
414+
398415
InvokeClick();
399416
e.Handled = true;
400417
}
401418

419+
private void OnPointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
420+
{
421+
_pointerPressed = false;
422+
}
423+
402424
private void OnKeyDown(object? sender, KeyEventArgs e)
403425
{
404426
if (!_isClickEnabled) return;

0 commit comments

Comments
 (0)