Refactor and optimize overlay dialog handling and resizing logic

- Remove unused `_moveDragging` variable in `OverlayFeedbackElement.cs`
- Rename private static animations to follow PascalCase in `OverlayDialogHost.Shared.cs`
- Simplify and streamline `ClickMaskToCloseDialog`, `OnPointerMoved`, `OnPointerPressed`, and `OnPointerReleased` methods in `OverlayDialogHost.Dialog.cs`
- Remove redundant null checks and streamline method calls in various files
- Optimize `_moveDragging` logic and pointer event handling in `DialogControlBase.cs`

This commit enhances readability, maintains consistency in naming conventions, and optimizes the code for better performance and clarity.
This commit is contained in:
rabbitism
2024-09-18 02:37:17 +08:00
parent 5799646488
commit dccb3c029c
5 changed files with 102 additions and 155 deletions

View File

@@ -31,6 +31,9 @@ public abstract class DialogControlBase : OverlayFeedbackElement
private bool _isFullScreen;
private Panel? _titleArea;
private bool _moveDragging;
private Point _moveDragStartPoint;
static DialogControlBase()
{
@@ -88,17 +91,44 @@ public abstract class DialogControlBase : OverlayFeedbackElement
private void OnTitlePointerPressed(InputElement sender, PointerPressedEventArgs e)
{
e.Source = this;
//e.Source = this;
if (ContainerPanel is OverlayDialogHost h)
{
if (h.IsTopLevel && this.IsFullScreen)
{
var top = TopLevel.GetTopLevel(this);
if (top is Window w)
{
w.BeginMoveDrag(e);
return;
}
}
}
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
if (IsFullScreen) return;
_moveDragging = true;
_moveDragStartPoint = e.GetPosition(this);
}
private void OnTitlePointerMove(InputElement sender, PointerEventArgs e)
{
e.Source = this;
//e.Source = this;
if (!_moveDragging) return;
if (ContainerPanel is null) return;
var p = e.GetPosition(this);
var left = Canvas.GetLeft(this) + p.X - _moveDragStartPoint.X;
var top = Canvas.GetTop(this) + p.Y - _moveDragStartPoint.Y;
left = MathHelpers.SafeClamp(left, 0, ContainerPanel.Bounds.Width - Bounds.Width);
top = MathHelpers.SafeClamp(top, 0, ContainerPanel.Bounds.Height - Bounds.Height);
Canvas.SetLeft(this, left);
Canvas.SetTop(this, top);
}
private void OnTitlePointerRelease(InputElement sender, PointerReleasedEventArgs e)
{
e.Source = this;
// e.Source = this;
_moveDragging = false;
AnchorAndUpdatePositionInfo();
}
private void OnCloseButtonClick(object? sender, RoutedEventArgs args)