Multi-Platform Package Manager for Stable Diffusion
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

using CommunityToolkit.Mvvm.ComponentModel;
using StabilityMatrix.Avalonia.Models;
1 year ago
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.Views.Dialogs;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models.Database;
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
[View(typeof(ImageViewerDialog))]
public partial class ImageViewerViewModel : ContentDialogViewModelBase
{
[ObservableProperty]
private ImageSource? imageSource;
[ObservableProperty]
private LocalImageFile? localImageFile;
[ObservableProperty]
private bool isFooterEnabled;
[ObservableProperty]
private string? fileNameText;
[ObservableProperty]
private string? fileSizeText;
[ObservableProperty]
private string? imageSizeText;
partial void OnLocalImageFileChanged(LocalImageFile? value)
{
ImageSource?.Dispose();
if (value?.GlobalFullPath is { } path)
{
ImageSource = new ImageSource(path);
}
}
partial void OnImageSourceChanged(ImageSource? value)
{
if (value?.LocalFile is { } localFile)
{
FileNameText = localFile.Name;
FileSizeText = Size.FormatBase10Bytes(localFile.GetSize(true));
if (LocalImageFile?.GenerationParameters is { Width: > 0, Height: > 0 } parameters)
{
ImageSizeText = $"{parameters.Width} x {parameters.Height}";
}
}
}
}