feat: support dialog resize.

This commit is contained in:
rabbitism
2024-09-17 21:10:54 +08:00
parent 8493d8454c
commit a70f7205e9
6 changed files with 239 additions and 36 deletions

View File

@@ -0,0 +1,19 @@
using Avalonia;
using Avalonia.Controls.Primitives;
namespace Ursa.Controls;
public class DialogResizer: TemplatedControl
{
public static readonly StyledProperty<ResizeDirection> ResizeDirectionProperty = AvaloniaProperty.Register<DialogResizer, ResizeDirection>(
nameof(ResizeDirection));
/// <summary>
/// Defines what direction the dialog is allowed to be resized.
/// </summary>
public ResizeDirection ResizeDirection
{
get => GetValue(ResizeDirectionProperty);
set => SetValue(ResizeDirectionProperty, value);
}
}

View File

@@ -0,0 +1,48 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.LogicalTree;
using Ursa.Controls.OverlayShared;
namespace Ursa.Controls;
public class DialogResizerThumb: Thumb
{
private OverlayFeedbackElement? _dialog;
public static readonly StyledProperty<ResizeDirection> ResizeDirectionProperty = AvaloniaProperty.Register<DialogResizerThumb, ResizeDirection>(
nameof(ResizeDirection));
public ResizeDirection ResizeDirection
{
get => GetValue(ResizeDirectionProperty);
set => SetValue(ResizeDirectionProperty, value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_dialog = this.FindLogicalAncestorOfType<OverlayFeedbackElement>();
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
if (_dialog is null) return;
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
var windowEdge = ResizeDirection switch
{
ResizeDirection.Top => WindowEdge.North,
ResizeDirection.TopRight => WindowEdge.NorthEast,
ResizeDirection.Right => WindowEdge.East,
ResizeDirection.BottomRight => WindowEdge.SouthEast,
ResizeDirection.Bottom => WindowEdge.South,
ResizeDirection.BottomLeft => WindowEdge.SouthWest,
ResizeDirection.Left => WindowEdge.West,
ResizeDirection.TopLeft => WindowEdge.NorthWest,
_ => throw new ArgumentOutOfRangeException()
};
_dialog.BeginResizeDrag(windowEdge, e);
}
}

View File

@@ -1,5 +1,6 @@
namespace Ursa.Controls;
[Flags]
public enum ResizeDirection
{
Top,