Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/UniGetUI.Avalonia/Views/Controls/Settings/SettingsCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.VisualTree;
using UniGetUI.Avalonia.Views.Controls;
using UniGetUI.Core.Tools;
using ICommand = System.Windows.Input.ICommand;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class SettingsCard : UserControl
private Control? _headerIcon;
private object? _rightContent;
private bool _isClickEnabled;
private bool _pointerPressed;

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

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

// Pointer activation leaves the card's normal stroke untouched; keyboard focus is
// handled solely by the external focus adorner.
_pointerPressed = true;
e.Handled = true;
}

private void OnPointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (!_pointerPressed) return;
_pointerPressed = false;

if (!_isClickEnabled) return;
if (e.InitialPressMouseButton is not MouseButton.Left) return;
if (!this.GetVisualsAt(e.GetPosition(this)).Any(c => this == c || this.IsVisualAncestorOf(c))) return;

InvokeClick();
e.Handled = true;
}

private void OnPointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
{
_pointerPressed = false;
}

private void OnKeyDown(object? sender, KeyEventArgs e)
{
if (!_isClickEnabled) return;
Expand Down
Loading