feat: add window resizer for Ursa.
This commit is contained in:
13
src/Ursa/Controls/Resizers/ResizeDirection.cs
Normal file
13
src/Ursa/Controls/Resizers/ResizeDirection.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public enum ResizeDirection
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right,
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
}
|
||||
8
src/Ursa/Controls/Resizers/WindowResizer.cs
Normal file
8
src/Ursa/Controls/Resizers/WindowResizer.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Avalonia.Controls.Primitives;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class WindowResizer : TemplatedControl
|
||||
{
|
||||
|
||||
}
|
||||
45
src/Ursa/Controls/Resizers/WindowResizerThumb.cs
Normal file
45
src/Ursa/Controls/Resizers/WindowResizerThumb.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class WindowResizerThumb: Thumb
|
||||
{
|
||||
private Window? _window;
|
||||
|
||||
public static readonly StyledProperty<ResizeDirection> ResizeDirectionProperty = AvaloniaProperty.Register<WindowResizerThumb, ResizeDirection>(
|
||||
nameof(ResizeDirection));
|
||||
|
||||
public ResizeDirection ResizeDirection
|
||||
{
|
||||
get => GetValue(ResizeDirectionProperty);
|
||||
set => SetValue(ResizeDirectionProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
_window = TopLevel.GetTopLevel(this) as Window;
|
||||
}
|
||||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
{
|
||||
base.OnPointerPressed(e);
|
||||
if (_window is null || !_window.CanResize) 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()
|
||||
};
|
||||
_window.BeginResizeDrag(windowEdge, e);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,15 @@ public class UrsaWindow: Window
|
||||
get => GetValue(IsTitleBarVisibleProperty);
|
||||
set => SetValue(IsTitleBarVisibleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> IsManagedResizerVisibleProperty = AvaloniaProperty.Register<UrsaWindow, bool>(
|
||||
nameof(IsManagedResizerVisible));
|
||||
|
||||
public bool IsManagedResizerVisible
|
||||
{
|
||||
get => GetValue(IsManagedResizerVisibleProperty);
|
||||
set => SetValue(IsManagedResizerVisibleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> TitleBarContentProperty = AvaloniaProperty.Register<UrsaWindow, object?>(
|
||||
nameof(TitleBarContent));
|
||||
|
||||
Reference in New Issue
Block a user