Browse Source

Add progress ring before image update

pull/5/head
Ionite 2 years ago
parent
commit
7660dba406
No known key found for this signature in database
  1. 12
      StabilityMatrix/TextToImagePage.xaml
  2. 16
      StabilityMatrix/ViewModels/TextToImageViewModel.cs

12
StabilityMatrix/TextToImagePage.xaml

@ -107,9 +107,21 @@
Width="500" /> Width="500" />
</StackPanel> </StackPanel>
<Grid Background="{DynamicResource ApplicationBackgroundBrush}" Grid.Row="1"> <Grid Background="{DynamicResource ApplicationBackgroundBrush}" Grid.Row="1">
<ui:ProgressRing
Background="DarkRed"
Grid.Row="0"
Height="72"
HorizontalAlignment="Center"
IsIndeterminate="True"
Margin="8"
VerticalAlignment="Center"
Visibility="{Binding ProgressRingVisibility, FallbackValue=Collapsed}"
Width="72"
x:Name="ImageProgressRing" />
<Image <Image
Margin="8" Margin="8"
Source="{Binding ImagePreview}" Source="{Binding ImagePreview}"
Visibility="{Binding ImagePreviewVisibility, FallbackValue=Visible}"
d:DesignHeight="512" d:DesignHeight="512"
d:DesignWidth="512" /> d:DesignWidth="512" />
</Grid> </Grid>

16
StabilityMatrix/ViewModels/TextToImageViewModel.cs

@ -23,6 +23,15 @@ public partial class TextToImageViewModel : ObservableObject
[ObservableProperty] [ObservableProperty]
private bool isGenerating; private bool isGenerating;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(ProgressRingVisibility))]
[NotifyPropertyChangedFor(nameof(ImagePreviewVisibility))]
private bool isProgressRingActive;
public Visibility ProgressRingVisibility => IsProgressRingActive ? Visibility.Visible : Visibility.Collapsed;
public Visibility ImagePreviewVisibility => IsProgressRingActive ? Visibility.Collapsed : Visibility.Visible;
[ObservableProperty] [ObservableProperty]
[NotifyPropertyChangedFor(nameof(ProgressBarVisibility))] [NotifyPropertyChangedFor(nameof(ProgressBarVisibility))]
private int progressValue; private int progressValue;
@ -63,6 +72,7 @@ public partial class TextToImageViewModel : ObservableObject
private void StopProgressTracking() private void StopProgressTracking()
{ {
IsProgressRingActive = false;
ProgressValue = 0; ProgressValue = 0;
progressQueryTimer?.Stop(); progressQueryTimer?.Stop();
} }
@ -86,6 +96,9 @@ public partial class TextToImageViewModel : ObservableObject
var result = response.CurrentImage; var result = response.CurrentImage;
if (result != null) if (result != null)
{ {
// Stop indeterminate progress ring
IsProgressRingActive = false;
// Set preview image
var bitmap = Base64ToBitmap(result); var bitmap = Base64ToBitmap(result);
ImagePreview = bitmap; ImagePreview = bitmap;
} }
@ -109,6 +122,9 @@ public partial class TextToImageViewModel : ObservableObject
[RelayCommand] [RelayCommand]
private async void TextToImageGenerate() private async void TextToImageGenerate()
{ {
// Start indeterminate progress ring
IsProgressRingActive = true;
var request = new TextToImageRequest var request = new TextToImageRequest
{ {
Prompt = PositivePromptText, Prompt = PositivePromptText,

Loading…
Cancel
Save