feat: basic position.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
@@ -21,6 +22,33 @@ public class DefaultDrawerControl: DrawerControlBase
|
||||
private Button? _noButton;
|
||||
private Button? _okButton;
|
||||
private Button? _cancelButton;
|
||||
|
||||
public static readonly StyledProperty<DialogButton> ButtonsProperty = AvaloniaProperty.Register<DefaultDrawerControl, DialogButton>(
|
||||
nameof(Buttons), DialogButton.OKCancel);
|
||||
|
||||
public DialogButton Buttons
|
||||
{
|
||||
get => GetValue(ButtonsProperty);
|
||||
set => SetValue(ButtonsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<DialogMode> ModeProperty = AvaloniaProperty.Register<DefaultDrawerControl, DialogMode>(
|
||||
nameof(Mode), DialogMode.None);
|
||||
|
||||
public DialogMode Mode
|
||||
{
|
||||
get => GetValue(ModeProperty);
|
||||
set => SetValue(ModeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<string?> TitleProperty = AvaloniaProperty.Register<DefaultDrawerControl, string?>(
|
||||
nameof(Title));
|
||||
|
||||
public string? Title
|
||||
{
|
||||
get => GetValue(TitleProperty);
|
||||
set => SetValue(TitleProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
using Avalonia.Controls;
|
||||
using Ursa.Common;
|
||||
using Ursa.Controls.Options;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public static class Drawer
|
||||
{
|
||||
public static Task<TResult?> Show<TView, TViewModel, TResult>(TViewModel vm, Position position = Position.Right)
|
||||
public static Task<TResult?> Show<TView, TViewModel, TResult>(TViewModel vm, DefaultDrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(null);
|
||||
if (host is null) return Task.FromResult(default(TResult));
|
||||
var drawer = new DefaultDrawerControl()
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddDrawer(drawer);
|
||||
return drawer.ShowAsync<TResult>();
|
||||
}
|
||||
|
||||
public static Task<TResult?> ShowCustom<TView, TViewModel, TResult>(TViewModel vm, CustomDrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(null);
|
||||
@@ -14,9 +30,51 @@ public static class Drawer
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
Position = position,
|
||||
};
|
||||
ConfigureCustomDrawer(dialog, options);
|
||||
host.AddDrawer(dialog);
|
||||
return dialog.ShowAsync<TResult>();
|
||||
}
|
||||
|
||||
private static void ConfigureCustomDrawer(CustomDrawerControl drawer, CustomDrawerOptions? options)
|
||||
{
|
||||
options ??= CustomDrawerOptions.Default;
|
||||
drawer.Position = options.Position;
|
||||
drawer.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
||||
drawer.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
drawer.ShowMask = options.ShowMask;
|
||||
drawer.CanLightDismiss = options.CanLightDismiss;
|
||||
if (options.Position == Position.Left || options.Position == Position.Right)
|
||||
{
|
||||
drawer.MinWidth = options.MinWidth ?? 0.0;
|
||||
drawer.MaxWidth = options.MaxWidth ?? double.PositiveInfinity;
|
||||
}
|
||||
if (options.Position is Position.Top or Position.Bottom)
|
||||
{
|
||||
drawer.MinHeight = options.MinHeight ?? 0.0;
|
||||
drawer.MaxHeight = options.MaxHeight ?? double.PositiveInfinity;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConfigureDefaultDrawer(DefaultDrawerControl drawer, DefaultDrawerOptions? options)
|
||||
{
|
||||
options ??= DefaultDrawerOptions.Default;
|
||||
drawer.Position = options.Position;
|
||||
drawer.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
||||
drawer.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
drawer.Buttons = options.Buttons;
|
||||
drawer.Title = options.Title;
|
||||
drawer.ShowMask = options.ShowMask;
|
||||
drawer.CanLightDismiss = options.CanLightDismiss;
|
||||
if (options.Position == Position.Left || options.Position == Position.Right)
|
||||
{
|
||||
drawer.MinWidth = options.MinWidth ?? 0.0;
|
||||
drawer.MaxWidth = options.MaxWidth ?? double.PositiveInfinity;
|
||||
}
|
||||
if (options.Position is Position.Top or Position.Bottom)
|
||||
{
|
||||
drawer.MinHeight = options.MinHeight ?? 0.0;
|
||||
drawer.MaxHeight = options.MaxHeight ?? double.PositiveInfinity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,12 @@ public abstract class DrawerControlBase: OverlayFeedbackElement
|
||||
public const string PART_CloseButton = "PART_CloseButton";
|
||||
|
||||
internal bool CanClickOnMaskToClose { get; set; }
|
||||
internal bool ShowCloseButton { get; set; }
|
||||
|
||||
protected internal Button? _closeButton;
|
||||
|
||||
public static readonly StyledProperty<Position> PositionProperty = AvaloniaProperty.Register<DrawerControlBase, Position>(
|
||||
nameof(Position));
|
||||
|
||||
public static readonly StyledProperty<Position> PositionProperty =
|
||||
AvaloniaProperty.Register<DrawerControlBase, Position>(
|
||||
nameof(Position), defaultValue: Position.Right);
|
||||
|
||||
public Position Position
|
||||
{
|
||||
@@ -48,6 +48,9 @@ public const string PART_CloseButton = "PART_CloseButton";
|
||||
set => SetValue(IsCloseButtonVisibleProperty, value);
|
||||
}
|
||||
|
||||
protected internal bool ShowMask { get; set; }
|
||||
protected internal bool CanLightDismiss { get; set; }
|
||||
|
||||
static DrawerControlBase()
|
||||
{
|
||||
DataContextProperty.Changed.AddClassHandler<DrawerControlBase, object?>((o, e) => o.OnDataContextChange(e));
|
||||
|
||||
17
src/Ursa/Controls/Drawer/Options/CustomDrawerOptions.cs
Normal file
17
src/Ursa/Controls/Drawer/Options/CustomDrawerOptions.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Ursa.Common;
|
||||
|
||||
namespace Ursa.Controls.Options;
|
||||
|
||||
public class CustomDrawerOptions
|
||||
{
|
||||
internal static CustomDrawerOptions Default => new ();
|
||||
public Position Position { get; set; } = Position.Right;
|
||||
public bool CanClickOnMaskToClose { get; set; } = true;
|
||||
public bool CanLightDismiss { get; set; } = false;
|
||||
public bool ShowMask { get; set; } = true;
|
||||
public bool IsCloseButtonVisible { get; set; } = true;
|
||||
public double? MinWidth { get; set; } = null;
|
||||
public double? MinHeight { get; set; } = null;
|
||||
public double? MaxWidth { get; set; } = null;
|
||||
public double? MaxHeight { get; set; } = null;
|
||||
}
|
||||
19
src/Ursa/Controls/Drawer/Options/DefaultDrawerOptions.cs
Normal file
19
src/Ursa/Controls/Drawer/Options/DefaultDrawerOptions.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Ursa.Common;
|
||||
|
||||
namespace Ursa.Controls.Options;
|
||||
|
||||
public class DefaultDrawerOptions
|
||||
{
|
||||
internal static DefaultDrawerOptions Default => new ();
|
||||
public Position Position { get; set; } = Position.Right;
|
||||
public bool CanClickOnMaskToClose { get; set; } = true;
|
||||
public bool CanLightDismiss { get; set; } = false;
|
||||
public bool ShowMask { get; set; } = true;
|
||||
public bool IsCloseButtonVisible { get; set; } = true;
|
||||
public double? MinWidth { get; set; } = null;
|
||||
public double? MinHeight { get; set; } = null;
|
||||
public double? MaxWidth { get; set; } = null;
|
||||
public double? MaxHeight { get; set; } = null;
|
||||
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user