feat: improve dialog demo layout.

This commit is contained in:
rabbitism
2024-08-25 21:49:48 +08:00
parent 1553a936b5
commit 9758e1b826
8 changed files with 388 additions and 229 deletions

View File

@@ -1,5 +1,6 @@
using Avalonia.Controls.Primitives;
using Irihi.Avalonia.Shared.Contracts;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -8,7 +9,12 @@ public class CustomDialogControl : DialogControlBase
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
if (_closeButton is not null) _closeButton.IsVisible = IsCloseButtonVisible ?? true;
var closeButtonVisible = IsCloseButtonVisible ??DataContext is IDialogContext;
IsHitTestVisibleProperty.SetValue(closeButtonVisible, _closeButton);
if (!closeButtonVisible)
{
OpacityProperty.SetValue(0, _closeButton);
}
}
public override void Close()

View File

@@ -70,9 +70,12 @@ public class DefaultDialogControl : DialogControlBase
private void SetButtonVisibility()
{
var isCloseButtonVisible =
IsCloseButtonVisible ?? (DataContext is IDialogContext || Buttons != DialogButton.YesNo);
IsVisibleProperty.SetValue(isCloseButtonVisible, _closeButton);
var closeButtonVisible = IsCloseButtonVisible ??DataContext is IDialogContext;
IsHitTestVisibleProperty.SetValue(closeButtonVisible, _closeButton);
if (!closeButtonVisible)
{
OpacityProperty.SetValue(0, _closeButton);
}
switch (Buttons)
{
case DialogButton.None:

View File

@@ -72,9 +72,15 @@ public class DefaultDialogWindow : DialogWindow
private void SetButtonVisibility()
{
// Close button should be hidden instead if invisible to retain layout.
IsVisibleProperty.SetValue(true, _closeButton);
var closeButtonVisible =
IsCloseButtonVisible ?? (DataContext is IDialogContext || Buttons != DialogButton.YesNo);
IsVisibleProperty.SetValue(closeButtonVisible, _closeButton);
IsHitTestVisibleProperty.SetValue(closeButtonVisible, _closeButton);
if (!closeButtonVisible)
{
OpacityProperty.SetValue(0, _closeButton);
}
switch (Buttons)
{
case DialogButton.None:

View File

@@ -240,6 +240,7 @@ public static class Dialog
window.Buttons = options.Button;
window.Mode = options.Mode;
window.ShowInTaskbar = options.ShowInTaskBar;
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
if (options.StartupLocation == WindowStartupLocation.Manual)
{
if (options.Position is not null)

View File

@@ -16,40 +16,50 @@ public enum VerticalPosition
public class OverlayDialogOptions
{
internal static OverlayDialogOptions Default { get; } = new OverlayDialogOptions();
internal static OverlayDialogOptions Default { get; } = new();
public bool FullScreen { get; set; }
public HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
public VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
/// <summary>
/// This attribute is only used when HorizontalAnchor is not Center
/// This attribute is only used when HorizontalAnchor is not Center
/// </summary>
public double? HorizontalOffset { get; set; } = null;
/// <summary>
/// This attribute is only used when VerticalAnchor is not Center
/// This attribute is only used when VerticalAnchor is not Center
/// </summary>
public double? VerticalOffset { get; set; } = null;
/// <summary>
/// Only works for DefaultDialogControl
/// Only works for DefaultDialogControl
/// </summary>
public DialogMode Mode { get; set; } = DialogMode.None;
/// <summary>
/// Only works for DefaultDialogControl
/// Only works for DefaultDialogControl
/// </summary>
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
/// <summary>
/// Only works for DefaultDialogControl
/// Only works for DefaultDialogControl
/// </summary>
public string? Title { get; set; } = null;
/// <summary>
/// Only works for CustomDialogControl
/// Only works for CustomDialogControl
/// </summary>
public bool? IsCloseButtonVisible { get; set; } = true;
[Obsolete()]
public bool ShowCloseButton { get; set; } = true;
[Obsolete] public bool ShowCloseButton { get; set; } = true;
public bool CanLightDismiss { get; set; }
public bool CanDragMove { get; set; } = true;
/// <summary>
/// The hash code of the top level dialog host. This is used to identify the dialog host if there are multiple dialog hosts with the same id. If this is not provided, the dialog will be added to the first dialog host with the same id.
/// The hash code of the top level dialog host. This is used to identify the dialog host if there are multiple dialog
/// hosts with the same id. If this is not provided, the dialog will be added to the first dialog host with the same
/// id.
/// </summary>
public int? TopLevelHashCode { get; set; }
}