Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kikipoulet committed Aug 14, 2024
1 parent 32082c9 commit 83d10db
Show file tree
Hide file tree
Showing 74 changed files with 1,833 additions and 3,563 deletions.
14 changes: 12 additions & 2 deletions SukiUI.Demo/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using SukiUI.Demo.Services;
using System;
using System.Linq;
using SukiUI.Controls;
using SukiUI.Dialogs;
using SukiUI.Toasts;

namespace SukiUI.Demo;

Expand All @@ -28,8 +31,9 @@ public override void OnFrameworkInitializationCompleted()
{
var viewLocator = _provider?.GetRequiredService<IDataTemplate>();
var mainViewModel = _provider?.GetRequiredService<SukiUIDemoViewModel>();

desktop.MainWindow = viewLocator?.Build(mainViewModel) as Window;
var mainView = _provider?.GetRequiredService<SukiUIDemoView>();
mainView.DataContext = mainViewModel;
desktop.MainWindow = mainView;
}

base.OnFrameworkInitializationCompleted();
Expand All @@ -40,10 +44,16 @@ private static ServiceProvider ConfigureServices()
var viewLocator = Current?.DataTemplates.First(x => x is ViewLocator);
var services = new ServiceCollection();

// Views
services.AddSingleton<SukiUIDemoView>();

// Services
if (viewLocator is not null)
services.AddSingleton(viewLocator);
services.AddSingleton<PageNavigationService>();
services.AddSingleton<ClipboardService>();
services.AddSingleton<ISukiToastManager, SukiToastManager>();
services.AddSingleton<ISukiDialogManager, SukiDialogManager>();

// ViewModels
services.AddSingleton<SukiUIDemoViewModel>();
Expand Down
3 changes: 2 additions & 1 deletion SukiUI.Demo/Features/ControlsLibrary/Colors/ColorsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<DataTemplate>
<suki:GlassCard Margin="15"
IsInteractive="True"
PointerPressed="InputElement_OnPointerPressed">
Command="{Binding $parent[colors:ColorsView].((colors:ColorsViewModel)DataContext).ColorClickedCommand}"
CommandParameter="{Binding}">
<suki:GroupBox Header="{Binding Name}">
<Rectangle Width="50"
Height="50"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,4 @@ public ColorsView()
{
InitializeComponent();
}

private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (VisualRoot is not Window win) return;
if (sender is not Control control) return;
if (control.DataContext is not ColorViewModel vm) return;
win.Clipboard!.SetTextAsync(vm.Name);
SukiHost.ShowToast("Copied To Clipboard", $"Copied the name of {vm.Name} to clipboard.");
}
}
23 changes: 21 additions & 2 deletions SukiUI.Demo/Features/ControlsLibrary/Colors/ColorsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Styling;
using CommunityToolkit.Mvvm.Input;
using Material.Icons;
using SukiUI.Demo.Services;
using SukiUI.Models;
using SukiUI.Toasts;

namespace SukiUI.Demo.Features.ControlsLibrary.Colors;

public class ColorsViewModel : DemoPageBase
public partial class ColorsViewModel : DemoPageBase
{
public AvaloniaList<ColorViewModel> Colors { get; } = [];

private readonly Dictionary<ThemeVariant, Dictionary<string, IBrush>> _baseThemeCache = new();
private readonly Dictionary<SukiColorTheme, Dictionary<string, IBrush>> _colorThemeCache = new();

public ColorsViewModel() : base("Colors", MaterialIconKind.Paintbrush)
private readonly ClipboardService _clipboardService;
private readonly ISukiToastManager _toastManager;

public ColorsViewModel(ClipboardService clipboardService, ISukiToastManager toastManager) : base("Colors", MaterialIconKind.Paintbrush)
{
_clipboardService = clipboardService;
_toastManager = toastManager;

var sukiTheme = SukiTheme.GetInstance();

Colors.AddRange(BuildOrGetColorTheme(sukiTheme.ActiveColorTheme!)
Expand Down Expand Up @@ -67,4 +76,14 @@ private Dictionary<string, IBrush> BuildOrGetBaseTheme(ThemeVariant variant)
_baseThemeCache[variant] = brushes;
return _baseThemeCache[variant];
}

[RelayCommand]
private void OnColorClicked(ColorViewModel color)
{
_clipboardService.CopyToClipboard(color.Name);
_toastManager.CreateSimpleInfoToast()
.WithTitle("Color Copied To Clipboard")
.WithContent($"Copied the name of {color.Name} to your clipboard.")
.Queue();
}
}
17 changes: 12 additions & 5 deletions SukiUI.Demo/Features/ControlsLibrary/ContextMenusViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
using CommunityToolkit.Mvvm.Input;
using Material.Icons;
using SukiUI.Controls;
using SukiUI.Toasts;

namespace SukiUI.Demo.Features.ControlsLibrary;

public partial class ContextMenusViewModel() : DemoPageBase("Context Menus", MaterialIconKind.Menu)
public partial class ContextMenusViewModel(ISukiToastManager toastManager) : DemoPageBase("Context Menus", MaterialIconKind.Menu)
{
[RelayCommand]
private static void OptionClicked(bool withIcon)
private void OptionClicked(bool withIcon)
{
SukiHost.ShowToast("Clicked Context Menu", withIcon ? "You clicked the option with the icon." : "You clicked the option without the icon.");
toastManager.CreateSimpleInfoToast()
.WithTitle("Clicked Context Menu")
.WithContent(withIcon ? "You clicked the option with the icon." : "You clicked the option without the icon.")
.Queue();
}

[RelayCommand]
private static void NestedOptionClicked()
private void NestedOptionClicked()
{
SukiHost.ShowToast("Clicked Context Menu", "You clicked the nested option");
toastManager.CreateSimpleInfoToast()
.WithTitle("Clicked Context Menu")
.WithContent("You clicked the nested option.")
.Queue();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Dialog Window Demo"
Width="550"
Width="760"
Height="400"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<suki:SukiWindow.Hosts>
<suki:SukiDialogHost Name="DialogHost"/>
</suki:SukiWindow.Hosts>
<Grid RowDefinitions="Auto,*">
<suki:GlassCard Classes="HeaderCard">
<suki:GroupBox Header="Toasts">
<suki:GroupBox Header="Dialogs">
<StackPanel Classes="HeaderContent">
<TextBlock>
Demos the ability for individual windows (or the main window) to be addressed by the dialog system.
Expand All @@ -36,6 +39,13 @@
Content="Show Dialog" />
</suki:GroupBox>
</suki:GlassCard>
<suki:GlassCard>
<suki:GroupBox Header="Show In Both Windows">
<Button Margin="15,10,15,0"
Click="ShowDialogInBothWindowsClicked"
Content="Show Dialog" />
</suki:GroupBox>
</suki:GlassCard>
</WrapPanel>
</ScrollViewer>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
using Avalonia.Interactivity;
using SukiUI.Controls;
using SukiUI.Dialogs;

namespace SukiUI.Demo.Features.ControlsLibrary.Dialogs;

public partial class DialogWindowDemo : SukiWindow
{
public DialogWindowDemo()
private readonly ISukiDialogManager _mainWindowManager;
private readonly ISukiDialogManager _thisWindowManager = new SukiDialogManager();

public DialogWindowDemo(ISukiDialogManager mainWindowManager)
{
_mainWindowManager = mainWindowManager;
InitializeComponent();
DialogHost.Manager = _thisWindowManager;
}

private void ShowDialogInThisWindowClicked(object? sender, RoutedEventArgs e) =>
SukiHost.ShowDialog(this, "A simple dialog that is shown in the demo window.\r\nClick outside dialog to close.", allowBackgroundClose: true);
private void ShowDialogInThisWindowClicked(object? sender, RoutedEventArgs e)
{
_thisWindowManager.CreateDialog()
.WithTitle("Dialog Demo")
.WithContent("This dialog is shown in this window.\r\nClick outside the dialog or click dismiss to dismiss this dialog.")
.Dismiss().ByClickingBackground()
.WithActionButton("Dismiss", _ => {}, true)
.TryShow();
}

private void ShowDialogInMainWindowClicked(object? sender, RoutedEventArgs e) =>
SukiHost.ShowDialog("A simple dialog that was shown from the demo window.\r\nClick outside dialog to close.", allowBackgroundClose: true);
private void ShowDialogInMainWindowClicked(object? sender, RoutedEventArgs e)
{
_mainWindowManager.CreateDialog()
.WithTitle("Dialog Demo")
.WithContent("This dialog is shown in the main window from the opened window.\r\nClick outside the dialog or click dismiss to dismiss this dialog.")
.Dismiss().ByClickingBackground()
.WithActionButton("Dismiss", _ => {}, true)
.TryShow();
}
private void ShowDialogInBothWindowsClicked(object? sender, RoutedEventArgs e)
{
_mainWindowManager.CreateDialog()
.WithTitle("Dialog Demo")
.WithContent("This dialog is shown in both windows.\r\nClick outside the dialog or click dismiss to dismiss this dialog.")
.Dismiss().ByClickingBackground()
.WithActionButton("Dismiss", _ => {}, true)
.TryShow();
_thisWindowManager.CreateDialog()
.WithTitle("Dialog Demo")
.WithContent("This dialog is shown in both windows.\r\nClick outside the dialog or click dismiss to dismiss this dialog.")
.Dismiss().ByClickingBackground()
.WithActionButton("Dismiss", _ => {}, true)
.TryShow();
}
}
17 changes: 17 additions & 0 deletions SukiUI.Demo/Features/ControlsLibrary/Dialogs/DialogsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,30 @@
Content="Show Dialog" />
</suki:GroupBox>
</suki:GlassCard>
<suki:GlassCard>
<suki:GroupBox Header="Multi Option Dialog">
<Button Margin="15,10,15,0"
Command="{Binding OpenMultiOptionDialogCommand}"
Content="Show Dialog" />
</suki:GroupBox>
</suki:GlassCard>
<suki:GlassCard>
<suki:GroupBox Header="Background Closable Dialog">
<Button Margin="15,10,15,0"
Command="{Binding OpenBackgroundCloseDialogCommand}"
Content="Show Dialog" />
</suki:GroupBox>
</suki:GlassCard>
<suki:GlassCard>
<suki:GroupBox Header="Messagebox Style Dialogs">
<StackPanel Spacing="5">
<ComboBox ItemsSource="{Binding NotificationTypes}" SelectedItem="{Binding SelectedType}"/>
<Button Margin="15,10,15,0"
Command="{Binding OpenMessageBoxStyleDialogCommand}"
Content="Show Dialog" />
</StackPanel>
</suki:GroupBox>
</suki:GlassCard>
<suki:GlassCard>
<suki:GroupBox Header="ViewModel Dialog">
<Button Margin="15,10,15,0"
Expand Down
79 changes: 68 additions & 11 deletions SukiUI.Demo/Features/ControlsLibrary/Dialogs/DialogsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,82 @@
using System;
using Avalonia.Controls.Notifications;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Material.Icons;
using SukiUI.Controls;
using SukiUI.Demo.Utilities;
using SukiUI.Dialogs;
using SukiUI.Toasts;

namespace SukiUI.Demo.Features.ControlsLibrary.Dialogs;

public partial class DialogsViewModel() : DemoPageBase("Dialogs", MaterialIconKind.Forum)
public partial class DialogsViewModel(ISukiDialogManager dialogManager, ISukiToastManager toastManager) : DemoPageBase("Dialogs", MaterialIconKind.Forum)
{
public NotificationType[] NotificationTypes { get; } = Enum.GetValues<NotificationType>();

[ObservableProperty] private NotificationType _selectedType;

[RelayCommand]
private static void OpenStandardDialog() =>
SukiHost.ShowDialog(new StandardDialog());
private void OpenStandardDialog()
{
dialogManager.CreateDialog()
.WithTitle("A Standard Dialog")
.WithContent("This is a standard dialog. Click the button below to dismiss.")
.WithActionButton("Dismiss", _ => { }, true)
.TryShow();
}

[RelayCommand]
private static void OpenBackgroundCloseDialog() =>
SukiHost.ShowDialog(new BackgroundCloseDialog(), allowBackgroundClose: true);

private void OpenBackgroundCloseDialog()
{
dialogManager.CreateDialog()
.WithTitle("Background Closing Dialog")
.WithContent("Dismiss this dialog by clicking anywhere outside of it.")
.Dismiss().ByClickingBackground()
.TryShow();
}

[RelayCommand]
private void OpenMultiOptionDialog()
{
dialogManager.CreateDialog()
.WithTitle("Multi Option Dialog")
.WithContent("Select any one of the below options:")
.WithActionButton("Option 1", _ => ShowOptionToast(1), true)
.WithActionButton("Option 2", _ => ShowOptionToast(2), true)
.WithActionButton("Option 3", _ => ShowOptionToast(3), true)
.TryShow();
}

private void ShowOptionToast(int option)
{
toastManager.CreateToast()
.WithTitle("Dialog Option Clicked")
.WithContent($"You clicked option #{option}")
.Dismiss().ByClicking()
.Dismiss().After(TimeSpan.FromSeconds(3))
.Queue();
}

[RelayCommand]
private void OpenMessageBoxStyleDialog()
{
dialogManager.CreateDialog()
.OfType(SelectedType)
.WithTitle("MessageBox style dialog.")
.WithContent($"This MessageBox is - {SelectedType}.")
.WithActionButton("Dismiss", _ => { }, true)
.Dismiss().ByClickingBackground()
.TryShow();
}

[RelayCommand]
private static void OpenViewModelDialog() =>
SukiHost.ShowDialog(new VmDialogViewModel(), allowBackgroundClose: true);
private void OpenViewModelDialog()
{
dialogManager.CreateDialog()
.WithViewModel(dialog => new VmDialogViewModel(dialog))
.TryShow();
}

[RelayCommand]
private static void OpenDialogWindowDemo() => new DialogWindowDemo().Show();
private void OpenDialogWindowDemo() => new DialogWindowDemo(dialogManager).Show();

}
Loading

0 comments on commit 83d10db

Please sign in to comment.