|
6 | 6 | using Avalonia.Interactivity; |
7 | 7 | using Avalonia.Layout; |
8 | 8 | using Avalonia.Media; |
| 9 | +using Avalonia.VisualTree; |
9 | 10 | using UniGetUI.Avalonia.Views.Controls; |
10 | 11 | using UniGetUI.Core.Tools; |
11 | 12 | using ICommand = System.Windows.Input.ICommand; |
@@ -54,6 +55,7 @@ public class SettingsCard : UserControl |
54 | 55 | private Control? _headerIcon; |
55 | 56 | private object? _rightContent; |
56 | 57 | private bool _isClickEnabled; |
| 58 | + private bool _pointerPressed; |
57 | 59 |
|
58 | 60 | /// <summary> |
59 | 61 | /// Keep compact toggle-style content at the right edge when the card wraps. |
@@ -239,6 +241,8 @@ public SettingsCard() |
239 | 241 | base.Content = _border; |
240 | 242 |
|
241 | 243 | PointerPressed += OnPointerPressed; |
| 244 | + PointerReleased += OnPointerReleased; |
| 245 | + PointerCaptureLost += OnPointerCaptureLost; |
242 | 246 | KeyDown += OnKeyDown; |
243 | 247 | SizeChanged += (_, e) => UpdateResponsiveLayout(e.NewSize.Width); |
244 | 248 | // Keyboard focus keeps the SettingsCard itself as the focus target. A card-specific |
@@ -395,10 +399,28 @@ private void OnPointerPressed(object? sender, PointerPressedEventArgs e) |
395 | 399 |
|
396 | 400 | // Pointer activation leaves the card's normal stroke untouched; keyboard focus is |
397 | 401 | // 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 | + |
398 | 415 | InvokeClick(); |
399 | 416 | e.Handled = true; |
400 | 417 | } |
401 | 418 |
|
| 419 | + private void OnPointerCaptureLost(object? sender, PointerCaptureLostEventArgs e) |
| 420 | + { |
| 421 | + _pointerPressed = false; |
| 422 | + } |
| 423 | + |
402 | 424 | private void OnKeyDown(object? sender, KeyEventArgs e) |
403 | 425 | { |
404 | 426 | if (!_isClickEnabled) return; |
|
0 commit comments