Add resize functionality and improve dialog controls
This commit introduces the ability to resize dialogs by adding `CanResize` properties to dialog options and control classes. It also refines dialog controls' behavior and layout, ensuring consistent resizing capabilities across different dialog types. Additionally, it enhances the overlay feedback element's positioning logic and updates the resizer's appearance and visibility handling.
This commit is contained in:
@@ -205,6 +205,8 @@ public static class Dialog
|
||||
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
window.ShowInTaskbar = options.ShowInTaskBar;
|
||||
window.CanDragMove = options.CanDragMove;
|
||||
window.CanResize = options.CanResize;
|
||||
window.IsManagedResizerVisible = options.CanResize;
|
||||
if (options.StartupLocation == WindowStartupLocation.Manual)
|
||||
{
|
||||
if (options.Position is not null)
|
||||
@@ -229,6 +231,8 @@ public static class Dialog
|
||||
window.ShowInTaskbar = options.ShowInTaskBar;
|
||||
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
window.CanDragMove = options.CanDragMove;
|
||||
window.IsManagedResizerVisible = options.CanResize;
|
||||
window.CanResize = options.CanResize;
|
||||
if (options.StartupLocation == WindowStartupLocation.Manual)
|
||||
{
|
||||
if (options.Position is not null)
|
||||
|
||||
@@ -24,6 +24,9 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
||||
AvaloniaProperty.RegisterDirect<DialogControlBase, bool>(
|
||||
nameof(IsFullScreen), o => o.IsFullScreen, (o, v) => o.IsFullScreen = v);
|
||||
|
||||
public static readonly StyledProperty<bool> CanResizeProperty = AvaloniaProperty.Register<DialogControlBase, bool>(
|
||||
nameof(CanResize));
|
||||
|
||||
protected internal Button? _closeButton;
|
||||
|
||||
private bool _isFullScreen;
|
||||
@@ -36,6 +39,12 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
||||
IsFullScreenProperty.AffectsPseudoClass<DialogControlBase>(PC_FullScreen);
|
||||
}
|
||||
|
||||
public bool CanResize
|
||||
{
|
||||
get => GetValue(CanResizeProperty);
|
||||
set => SetValue(CanResizeProperty, value);
|
||||
}
|
||||
|
||||
internal HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
|
||||
internal VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
|
||||
internal HorizontalPosition ActualHorizontalAnchor { get; set; }
|
||||
|
||||
@@ -17,8 +17,17 @@ public class DialogWindow : Window
|
||||
public const string PART_TitleArea = "PART_TitleArea";
|
||||
|
||||
protected internal Button? _closeButton;
|
||||
|
||||
private Panel? _titleArea;
|
||||
public bool CanDragMove { get; set; } = true;
|
||||
|
||||
public static readonly StyledProperty<bool> IsManagedResizerVisibleProperty = AvaloniaProperty.Register<DialogWindow, bool>(
|
||||
nameof(IsManagedResizerVisible));
|
||||
|
||||
public bool IsManagedResizerVisible
|
||||
{
|
||||
get => GetValue(IsManagedResizerVisibleProperty);
|
||||
set => SetValue(IsManagedResizerVisibleProperty, value);
|
||||
}
|
||||
|
||||
static DialogWindow()
|
||||
{
|
||||
@@ -26,9 +35,11 @@ public class DialogWindow : Window
|
||||
window.OnDataContextChange(e));
|
||||
}
|
||||
|
||||
public bool CanDragMove { get; set; } = true;
|
||||
internal bool? IsCloseButtonVisible { get; set; }
|
||||
|
||||
protected override Type StyleKeyOverride { get; } = typeof(DialogWindow);
|
||||
|
||||
internal bool? IsCloseButtonVisible { get; set; }
|
||||
|
||||
private void OnDataContextChange(AvaloniaPropertyChangedEventArgs<object?> args)
|
||||
{
|
||||
|
||||
@@ -30,4 +30,6 @@ public class DialogOptions
|
||||
public bool ShowInTaskBar { get; set; } = true;
|
||||
|
||||
public bool CanDragMove { get; set; } = true;
|
||||
|
||||
public bool CanResize { get; set; }
|
||||
}
|
||||
@@ -62,4 +62,6 @@ public class OverlayDialogOptions
|
||||
/// id.
|
||||
/// </summary>
|
||||
public int? TopLevelHashCode { get; set; }
|
||||
|
||||
public bool CanResize { get; set; }
|
||||
}
|
||||
@@ -204,6 +204,7 @@ public static class OverlayDialog
|
||||
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
|
||||
control.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
control.CanLightDismiss = options.CanLightDismiss;
|
||||
control.CanResize = options.CanResize;
|
||||
DialogControlBase.SetCanDragMove(control, options.CanDragMove);
|
||||
}
|
||||
|
||||
@@ -229,6 +230,7 @@ public static class OverlayDialog
|
||||
control.Title = options.Title;
|
||||
control.CanLightDismiss = options.CanLightDismiss;
|
||||
control.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
control.CanResize = options.CanResize;
|
||||
DialogControlBase.SetCanDragMove(control, options.CanDragMove);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,10 +149,14 @@ public abstract class OverlayFeedbackElement : ContentControl
|
||||
{
|
||||
if (containerBounds is not null)
|
||||
{
|
||||
var minX = -left;
|
||||
var minY = -top;
|
||||
var maxX = containerBounds.Value.Width - left - width;
|
||||
var maxY = containerBounds.Value.Height - top - height;
|
||||
var minX = windowEdge is WindowEdge.West or WindowEdge.NorthWest or WindowEdge.SouthWest
|
||||
? -left
|
||||
: double.NegativeInfinity;
|
||||
var minY = windowEdge is WindowEdge.North or WindowEdge.NorthEast or WindowEdge.NorthWest
|
||||
? -top
|
||||
: double.NegativeInfinity;
|
||||
var maxX = containerBounds.Value.Width - left - MinWidth;
|
||||
var maxY = containerBounds.Value.Height - top - MinHeight;
|
||||
diff = new Point(MathHelpers.SafeClamp(diff.X, minX, maxX), MathHelpers.SafeClamp(diff.Y, minY, maxY));
|
||||
}
|
||||
switch (windowEdge)
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class DialogResizer: TemplatedControl
|
||||
{
|
||||
public const string PART_Top = "PART_Top";
|
||||
public const string PART_Bottom = "PART_Bottom";
|
||||
public const string PART_Left = "PART_Left";
|
||||
public const string PART_Right = "PART_Right";
|
||||
public const string PART_TopLeft = "PART_TopLeft";
|
||||
public const string PART_TopRight = "PART_TopRight";
|
||||
public const string PART_BottomLeft = "PART_BottomLeft";
|
||||
public const string PART_BottomRight = "PART_BottomRight";
|
||||
|
||||
private Thumb? _top;
|
||||
private Thumb? _bottom;
|
||||
private Thumb? _left;
|
||||
private Thumb? _right;
|
||||
private Thumb? _topLeft;
|
||||
private Thumb? _topRight;
|
||||
private Thumb? _bottomLeft;
|
||||
private Thumb? _bottomRight;
|
||||
|
||||
public static readonly StyledProperty<ResizeDirection> ResizeDirectionProperty = AvaloniaProperty.Register<DialogResizer, ResizeDirection>(
|
||||
nameof(ResizeDirection));
|
||||
|
||||
@@ -16,4 +36,39 @@ public class DialogResizer: TemplatedControl
|
||||
get => GetValue(ResizeDirectionProperty);
|
||||
set => SetValue(ResizeDirectionProperty, value);
|
||||
}
|
||||
|
||||
static DialogResizer()
|
||||
{
|
||||
ResizeDirectionProperty.Changed.AddClassHandler<DialogResizer, ResizeDirection>((resizer, e) => resizer.OnResizeDirectionChanged(e));
|
||||
}
|
||||
|
||||
private void OnResizeDirectionChanged(AvaloniaPropertyChangedEventArgs<ResizeDirection> args)
|
||||
{
|
||||
UpdateThumbVisibility(args.NewValue.Value);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
_top = e.NameScope.Find<Thumb>(PART_Top);
|
||||
_bottom = e.NameScope.Find<Thumb>(PART_Bottom);
|
||||
_left = e.NameScope.Find<Thumb>(PART_Left);
|
||||
_right = e.NameScope.Find<Thumb>(PART_Right);
|
||||
_topLeft = e.NameScope.Find<Thumb>(PART_TopLeft);
|
||||
_topRight = e.NameScope.Find<Thumb>(PART_TopRight);
|
||||
_bottomLeft = e.NameScope.Find<Thumb>(PART_BottomLeft);
|
||||
_bottomRight = e.NameScope.Find<Thumb>(PART_BottomRight);
|
||||
}
|
||||
|
||||
private void UpdateThumbVisibility(ResizeDirection direction)
|
||||
{
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Top), _top);
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Bottom), _bottom);
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Left), _left);
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Right), _right);
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.TopLeft), _topLeft);
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.TopRight), _topRight);
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.BottomLeft), _bottomLeft);
|
||||
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.BottomRight), _bottomRight);
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,16 @@ namespace Ursa.Controls;
|
||||
[Flags]
|
||||
public enum ResizeDirection
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right,
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
Top = 1,
|
||||
Bottom = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
TopLeft = 16,
|
||||
TopRight = 32,
|
||||
BottomLeft = 64,
|
||||
BottomRight = 128,
|
||||
|
||||
Sides = Top | Bottom | Left | Right,
|
||||
Corners = TopLeft | TopRight | BottomLeft | BottomRight,
|
||||
All = Sides | Corners,
|
||||
}
|
||||
Reference in New Issue
Block a user