Ionite
1 year ago
17 changed files with 407 additions and 60 deletions
@ -0,0 +1,38 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics.CodeAnalysis; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.Templates; |
||||
using Avalonia.Metadata; |
||||
using StabilityMatrix.Core.Models.Api.Comfy; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] |
||||
public class ComfyUpscalerTemplateSelector : IDataTemplate |
||||
{ |
||||
// ReSharper disable once CollectionNeverUpdated.Global |
||||
[Content] |
||||
public Dictionary<ComfyUpscalerType, IDataTemplate> Templates { get; } = new(); |
||||
|
||||
// Check if we can accept the provided data |
||||
public bool Match(object? data) |
||||
{ |
||||
return data is ComfyUpscaler; |
||||
} |
||||
|
||||
// Build the DataTemplate here |
||||
public Control Build(object? data) |
||||
{ |
||||
if (data is not ComfyUpscaler card) |
||||
throw new ArgumentException(null, nameof(data)); |
||||
|
||||
if (Templates.TryGetValue(card.Type, out var type)) |
||||
{ |
||||
return type.Build(card)!; |
||||
} |
||||
|
||||
// Fallback to None |
||||
return Templates[ComfyUpscalerType.None].Build(card)!; |
||||
} |
||||
} |
@ -1,5 +1,51 @@
|
||||
using Avalonia.Controls.Primitives; |
||||
using System; |
||||
using AsyncAwaitBestPractices; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.Primitives; |
||||
using FluentAvalonia.UI.Controls; |
||||
using StabilityMatrix.Avalonia.ViewModels.Inference; |
||||
using StabilityMatrix.Core.Models.Api.Comfy; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
public class UpscalerCard : TemplatedControl { } |
||||
public class UpscalerCard : TemplatedControl |
||||
{ |
||||
/// <inheritdoc /> |
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) |
||||
{ |
||||
base.OnApplyTemplate(e); |
||||
|
||||
var upscalerComboBox = e.NameScope.Find("UpscalerComboBox") as FAComboBox; |
||||
upscalerComboBox!.SelectionChanged += UpscalerComboBox_OnSelectionChanged; |
||||
} |
||||
|
||||
private void UpscalerComboBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) |
||||
{ |
||||
if (e.AddedItems.Count == 0) |
||||
return; |
||||
|
||||
var item = e.AddedItems[0]; |
||||
if (item is ComfyUpscaler { IsDownloadable: true }) |
||||
{ |
||||
// Reset the selection |
||||
e.Handled = true; |
||||
|
||||
if ( |
||||
e.RemovedItems.Count > 0 |
||||
&& e.RemovedItems[0] is ComfyUpscaler { IsDownloadable: false } removedItem |
||||
) |
||||
{ |
||||
(sender as FAComboBox)!.SelectedItem = removedItem; |
||||
} |
||||
else |
||||
{ |
||||
(sender as FAComboBox)!.SelectedItem = null; |
||||
} |
||||
|
||||
// Show dialog to download the model |
||||
(DataContext as UpscalerCardViewModel)!.RemoteDownloadCommand |
||||
.ExecuteAsync(item) |
||||
.SafeFireAndForget(); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,25 @@
|
||||
using System; |
||||
using System.Globalization; |
||||
using Avalonia.Data.Converters; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Converters; |
||||
|
||||
public class ComfyUpscalerConverter : IValueConverter |
||||
{ |
||||
/// <inheritdoc /> |
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
public object? ConvertBack( |
||||
object? value, |
||||
Type targetType, |
||||
object? parameter, |
||||
CultureInfo culture |
||||
) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
Loading…
Reference in new issue