feat: support dialog resize.
This commit is contained in:
19
src/Ursa/Controls/Resizers/DialogResizer.cs
Normal file
19
src/Ursa/Controls/Resizers/DialogResizer.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
48
src/Ursa/Controls/Resizers/DialogResizerThumb.cs
Normal file
48
src/Ursa/Controls/Resizers/DialogResizerThumb.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[Flags]
|
||||
public enum ResizeDirection
|
||||
{
|
||||
Top,
|
||||
|
||||
Reference in New Issue
Block a user