diff --git a/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsView.axaml b/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsView.axaml index 01ddd38fb..482c96801 100644 --- a/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsView.axaml +++ b/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsView.axaml @@ -14,7 +14,7 @@ - SukiUI contains an API for creating and dismissing toasts, with the ability to set limits on the number of toasts. + SukiUI contains an API for creating and dismissing 4 kinds of toasts, with the ability to set limits on the number of toasts. It is also possible to set the toasts to appear in the bottom right (default) or in the bottom left. diff --git a/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsViewModel.cs b/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsViewModel.cs index 25000f25d..60999fd7c 100644 --- a/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsViewModel.cs +++ b/SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsViewModel.cs @@ -22,19 +22,19 @@ private static Task ShowSingleStandardToast() => [RelayCommand] private static Task ShowInfoToast() => - SukiHost.ShowToast("A Simple Toast", "This is the content of an info toast.", SukiToastType.Info); + SukiHost.ShowToast("A Simple Toast", "This is the content of an info toast.", ToastType.Info); [RelayCommand] private static Task ShowSuccessToast() => - SukiHost.ShowToast("A Simple Toast", "This is the content of a success toast.", SukiToastType.Success); + SukiHost.ShowToast("A Simple Toast", "This is the content of a success toast.", ToastType.Success); [RelayCommand] private static Task ShowWarningToast() => - SukiHost.ShowToast("A Simple Toast", "This is the content of a warning toast.", SukiToastType.Warning); + SukiHost.ShowToast("A Simple Toast", "This is the content of a warning toast.", ToastType.Warning); [RelayCommand] private static Task ShowErrorToast() => - SukiHost.ShowToast("A Simple Toast", "This is the content of an error toast.", SukiToastType.Error); + SukiHost.ShowToast("A Simple Toast", "This is the content of an error toast.", ToastType.Error); [RelayCommand] private static async Task ShowThreeInfoToasts() @@ -46,7 +46,7 @@ private static async Task ShowThreeInfoToasts() [RelayCommand] private static Task ShowToastWithCallback() { - return SukiHost.ShowToast("Click This Toast", "Click this toast to open a dialog.", SukiToastType.Info, TimeSpan.FromSeconds(15), + return SukiHost.ShowToast("Click This Toast", "Click this toast to open a dialog.", ToastType.Info, TimeSpan.FromSeconds(15), () => SukiHost.ShowDialog( new TextBlock { Text = "You clicked the toast! - Click anywhere outside of this dialog to close." }, allowBackgroundClose: true)); diff --git a/SukiUI/MessageBox/MessageBox.axaml b/SukiUI/Controls/MessageBox.axaml similarity index 95% rename from SukiUI/MessageBox/MessageBox.axaml rename to SukiUI/Controls/MessageBox.axaml index c3cf1c31d..3c2b5d01c 100644 --- a/SukiUI/MessageBox/MessageBox.axaml +++ b/SukiUI/Controls/MessageBox.axaml @@ -1,100 +1,99 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SukiUI/Controls/MessageBox.axaml.cs b/SukiUI/Controls/MessageBox.axaml.cs new file mode 100644 index 000000000..b85973d5f --- /dev/null +++ b/SukiUI/Controls/MessageBox.axaml.cs @@ -0,0 +1,66 @@ +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using Avalonia.Media; +using SukiUI.Content; +using SukiUI.Extensions; + +namespace SukiUI.Controls; + +public partial class MessageBox : Window +{ + private static readonly SolidColorBrush InfoBrush = new(Color.FromRgb(47, 84, 235)); + + public MessageBox() + { + InitializeComponent(); + } + + public MessageBox(string title, string message) + { + InitializeComponent(); + this.FindRequiredControl("Title").Text = title; + this.FindRequiredControl("Message").Text = message; + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + CanResize = false; + } + + public static void Info(Window owner, string title, string message, WindowStartupLocation startupLocation = WindowStartupLocation.CenterScreen) + { + var mbox = new MessageBox(title, message); + if (mbox.FindControl("InfoIcon") is not { } icon) return; + icon.Data = Icons.CircleInformation; + icon.Foreground = InfoBrush; + mbox.WindowStartupLocation = startupLocation; + mbox.ShowDialog(owner); + } + + public static void Success(Window owner, string title, string message, WindowStartupLocation startupLocation = WindowStartupLocation.CenterScreen) + { + var mbox = new MessageBox(title, message); + if (mbox.FindControl("InfoIcon") is not { } icon) return; + icon.Data = Icons.CircleCheck; + icon.Foreground = Brushes.DarkGreen; + mbox.WindowStartupLocation = startupLocation; + mbox.ShowDialog(owner); + } + + public static void Error(Window owner, string title, string message, WindowStartupLocation startupLocation = WindowStartupLocation.CenterScreen) + { + var mbox = new MessageBox(title, message); + if (mbox.FindControl("InfoIcon") is not { } icon) return; + icon.Data = Icons.CircleClose; + icon.Foreground = Brushes.DarkRed; + mbox.WindowStartupLocation = startupLocation; + mbox.ShowDialog(owner); + } + + private void Close(object sender, RoutedEventArgs e) + { + Close(); + } +} \ No newline at end of file diff --git a/SukiUI/Controls/SukiHost.axaml.cs b/SukiUI/Controls/SukiHost.axaml.cs index 077a60238..9d4f340d0 100644 --- a/SukiUI/Controls/SukiHost.axaml.cs +++ b/SukiUI/Controls/SukiHost.axaml.cs @@ -176,14 +176,14 @@ private static void BackgroundRequestClose(SukiHost host) /// The window who's SukiHost should be used to display the toast. /// A pre-constructed . /// Thrown if there is no SukiHost associated with the specified window. - public static async Task ShowToast(Window window, SukiToastModel model) + public static async Task ShowToast(Window window, ToastModel model) { try { if (!Instances.TryGetValue(window, out var host)) throw new InvalidOperationException("No SukiHost present in this window"); - var toast = SukiToastPool.Get(); + var toast = ToastPool.Get(); toast.Initialize(model, host); if (host.ToastsCollection.Count >= host._maxToasts) await ClearToast(host.ToastsCollection.First()); @@ -202,7 +202,7 @@ public static async Task ShowToast(Window window, SukiToastModel model) /// This method will show the toast in the earliest opened window. /// /// A pre-constructed . - public static Task ShowToast(SukiToastModel model) => + public static Task ShowToast(ToastModel model) => ShowToast(_mainWindow, model); /// @@ -214,11 +214,11 @@ public static Task ShowToast(SukiToastModel model) => /// The type of the toast, including Info, Success, Warning and Error /// Duration for this toast to be active. Default is 2 seconds. /// A callback that will be fired if the Toast is cleared by clicking. - public static Task ShowToast(string title, object content, SukiToastType? type = SukiToastType.Info, TimeSpan? duration = null, Action? onClicked = null) => - ShowToast(new SukiToastModel( + public static Task ShowToast(string title, object content, ToastType? type = ToastType.Info, TimeSpan? duration = null, Action? onClicked = null) => + ShowToast(new ToastModel( title, content as Control ?? ViewLocator.TryBuild(content), - type ?? SukiToastType.Info, + type ?? ToastType.Info, duration ?? TimeSpan.FromSeconds(4), onClicked)); @@ -232,12 +232,12 @@ public static Task ShowToast(string title, object content, SukiToastType? type = /// The type of the toast, including Info, Success, Warning and Error /// Duration for this toast to be active. Default is 2 seconds. /// A callback that will be fired if the Toast is cleared by clicking. - public static Task ShowToast(Window window, string title, object content, SukiToastType? type = SukiToastType.Info, TimeSpan? duration = null, + public static Task ShowToast(Window window, string title, object content, ToastType? type = ToastType.Info, TimeSpan? duration = null, Action? onClicked = null) => - ShowToast(window, new SukiToastModel( + ShowToast(window, new ToastModel( title, content as Control ?? ViewLocator.TryBuild(content), - type ?? SukiToastType.Info, + type ?? ToastType.Info, duration ?? TimeSpan.FromSeconds(4), onClicked)); @@ -260,7 +260,7 @@ public static async Task ClearToast(SukiToast toast) }); if (!wasRemoved) return; - SukiToastPool.Return(toast); + ToastPool.Return(toast); } /// @@ -270,7 +270,7 @@ public static void ClearAllToasts(Window window) { if (!Instances.TryGetValue(window, out var host)) throw new InvalidOperationException("No SukiHost present in this window"); - SukiToastPool.Return(host.ToastsCollection); + ToastPool.Return(host.ToastsCollection); Dispatcher.UIThread.Invoke(() => host.ToastsCollection.Clear()); } diff --git a/SukiUI/Controls/SukiToast.axaml.cs b/SukiUI/Controls/SukiToast.axaml.cs index ebcc01ce0..90b983767 100644 --- a/SukiUI/Controls/SukiToast.axaml.cs +++ b/SukiUI/Controls/SukiToast.axaml.cs @@ -71,25 +71,25 @@ private async void ToastCardClickedHandler(object o, PointerPressedEventArgs poi private readonly SolidColorBrush _warningIconForeground = new(Color.FromRgb(177,113,20)); private readonly SolidColorBrush _errorIconForeground = new(Color.FromRgb(216,63,48)); - public void Initialize(SukiToastModel model, SukiHost host) + public void Initialize(ToastModel model, SukiHost host) { Host = host; Title = model.Title; Content = model.Content; Icon = model.Type switch { - SukiToastType.Info => Icons.InformationOutline, - SukiToastType.Success => Icons.CircleOutlineCheck, - SukiToastType.Warning => Icons.AlertOutline, - SukiToastType.Error => Icons.CircleOutlineMinus, + ToastType.Info => Icons.InformationOutline, + ToastType.Success => Icons.CircleOutlineCheck, + ToastType.Warning => Icons.AlertOutline, + ToastType.Error => Icons.CircleOutlineMinus, _ => Icons.InformationOutline }; Foreground = model.Type switch { - SukiToastType.Info => _infoIconForeground, - SukiToastType.Success => _successIconForeground, - SukiToastType.Warning => _warningIconForeground, - SukiToastType.Error => _errorIconForeground, + ToastType.Info => _infoIconForeground, + ToastType.Success => _successIconForeground, + ToastType.Warning => _warningIconForeground, + ToastType.Error => _errorIconForeground, _ => _infoIconForeground }; _onClickedCallback = model.OnClicked; diff --git a/SukiUI/Controls/WaveProgress/WaveProgress.axaml b/SukiUI/Controls/WaveProgress.axaml similarity index 92% rename from SukiUI/Controls/WaveProgress/WaveProgress.axaml rename to SukiUI/Controls/WaveProgress.axaml index 0dc9f6aaf..34a0a8e02 100644 --- a/SukiUI/Controls/WaveProgress/WaveProgress.axaml +++ b/SukiUI/Controls/WaveProgress.axaml @@ -5,21 +5,16 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:suki="clr-namespace:SukiUI.Controls" + xmlns:waveProgress="clr-namespace:SukiUI.Converters.WaveProgress" d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> - +