Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 60e1123

Browse files
committed
ListBox image caching, Dark Theme
1 parent f40ec99 commit 60e1123

18 files changed

+2020
-4706
lines changed

OnnxStack.UI/App.xaml

Lines changed: 1781 additions & 13 deletions
Large diffs are not rendered by default.

OnnxStack.UI/Dialogs/CropImageDialog.xaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
Name="UI"
1010
Icon="/Images/Icon.png"
1111
Title="Crop Image"
12+
MinHeight="620"
13+
MinWidth="400"
1214
SizeToContent="WidthAndHeight"
13-
WindowStartupLocation="CenterScreen"
14-
MinHeight="620" MinWidth="400">
15-
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15">
16-
<DockPanel.Resources>
17-
<SolidColorBrush x:Key="CropFrameBrush" Color="WhiteSmoke" />
18-
</DockPanel.Resources>
15+
WindowStartupLocation="CenterOwner"
16+
SnapsToDevicePixels="True"
17+
UseLayoutRounding="True"
18+
Style="{StaticResource BaseWindow}"
19+
ContentRendered="OnContentRendered">
20+
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
21+
1922
<StackPanel DockPanel.Dock="Bottom" >
2023
<DockPanel VerticalAlignment="Bottom">
2124
<StackPanel DockPanel.Dock="Right" VerticalAlignment="Bottom">
@@ -44,7 +47,7 @@
4447
<Button IsDefault="True" Command="{Binding DoneCommand}" MinWidth="100" Height="30">_Done</Button>
4548
</UniformGrid>
4649
</StackPanel>
47-
<Border BorderThickness="2" BorderBrush="Gainsboro" >
50+
<Border BorderThickness="2" BorderBrush="{StaticResource ContainerBorder}" >
4851
<Canvas Width="{Binding ImageWidth}" Height="{Binding ImageHeight}" MouseWheel="CropFrame_MouseWheel">
4952
<Image Source="{Binding SourceImage, FallbackValue={StaticResource PlaceholderImage}, TargetNullValue={StaticResource PlaceholderImage}}" Width="{Binding ImageWidth}" Height="{Binding ImageHeight}" />
5053
<Canvas x:Name="CropFrame" Width="{Binding ZoomWidth}" Height="{Binding ZoomHeight}" Visibility="{Binding IsCropped, Converter={StaticResource InverseBooleanToVisibilityConverter}}" MouseLeftButtonUp="CropFrame_MouseLeftButtonUp" MouseLeftButtonDown="CropFrame_MouseLeftButtonDown" MouseMove="CropFrame_MouseMove" >

OnnxStack.UI/Dialogs/CropImageDialog.xaml.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,23 @@ public partial class CropImageDialog : Window, INotifyPropertyChanged
4848
public CropImageDialog(ILogger<CropImageDialog> logger)
4949
{
5050
_logger = logger;
51+
52+
WindowCloseCommand = new AsyncRelayCommand(WindowClose);
53+
WindowRestoreCommand = new AsyncRelayCommand(WindowRestore);
54+
WindowMinimizeCommand = new AsyncRelayCommand(WindowMinimize);
55+
WindowMaximizeCommand = new AsyncRelayCommand(WindowMaximize);
56+
5157
DoneCommand = new AsyncRelayCommand(Done, CanExecuteDone);
5258
CancelCommand = new AsyncRelayCommand(Cancel, CanExecuteCancel);
5359
CropCommand = new AsyncRelayCommand(Crop, CanExecuteCrop);
5460
ResetCommand = new AsyncRelayCommand(ResetSource);
5561
InitializeComponent();
5662
}
5763

64+
public AsyncRelayCommand WindowMinimizeCommand { get; }
65+
public AsyncRelayCommand WindowRestoreCommand { get; }
66+
public AsyncRelayCommand WindowMaximizeCommand { get; }
67+
public AsyncRelayCommand WindowCloseCommand { get; }
5868
public AsyncRelayCommand DoneCommand { get; }
5969
public AsyncRelayCommand CancelCommand { get; }
6070
public AsyncRelayCommand CropCommand { get; }
@@ -402,6 +412,42 @@ private void CropFrame_MouseWheel(object sender, MouseWheelEventArgs e)
402412
}
403413

404414

415+
#region BaseWindow
416+
417+
private Task WindowClose()
418+
{
419+
Close();
420+
return Task.CompletedTask;
421+
}
422+
423+
private Task WindowRestore()
424+
{
425+
if (WindowState == WindowState.Maximized)
426+
WindowState = WindowState.Normal;
427+
else
428+
WindowState = WindowState.Maximized;
429+
return Task.CompletedTask;
430+
}
431+
432+
private Task WindowMinimize()
433+
{
434+
WindowState = WindowState.Minimized;
435+
return Task.CompletedTask;
436+
}
437+
438+
private Task WindowMaximize()
439+
{
440+
WindowState = WindowState.Maximized;
441+
return Task.CompletedTask;
442+
}
443+
444+
private void OnContentRendered(object sender, EventArgs e)
445+
{
446+
InvalidateVisual();
447+
}
448+
449+
#endregion
450+
405451
#region INotifyPropertyChanged
406452
public event PropertyChangedEventHandler PropertyChanged;
407453
public void NotifyPropertyChanged([CallerMemberName] string property = "")

OnnxStack.UI/Dialogs/MessageDialog.xaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
mc:Ignorable="d"
77
Name="UI"
88
Icon="/Images/Icon.png"
9+
MinWidth="400"
10+
MaxWidth="400"
911
SizeToContent="WidthAndHeight"
10-
WindowStartupLocation="CenterScreen"
11-
MinWidth="400" MaxWidth="400">
12-
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15">
12+
WindowStartupLocation="CenterOwner"
13+
SnapsToDevicePixels="True"
14+
UseLayoutRounding="True"
15+
Style="{StaticResource BaseWindow}"
16+
ContentRendered="OnContentRendered">
17+
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
1318
<StackPanel DockPanel.Dock="Top">
1419
<TextBlock Text="{Binding Message}" TextAlignment="Center" TextWrapping="Wrap" />
1520
</StackPanel>

OnnxStack.UI/Dialogs/MessageDialog.xaml.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using OnnxStack.UI.Commands;
2+
using System;
23
using System.ComponentModel;
34
using System.Runtime.CompilerServices;
45
using System.Threading.Tasks;
@@ -16,12 +17,20 @@ public partial class MessageDialog : Window, INotifyPropertyChanged
1617

1718
public MessageDialog()
1819
{
20+
WindowCloseCommand = new AsyncRelayCommand(WindowClose);
21+
WindowRestoreCommand = new AsyncRelayCommand(WindowRestore);
22+
WindowMinimizeCommand = new AsyncRelayCommand(WindowMinimize);
23+
WindowMaximizeCommand = new AsyncRelayCommand(WindowMaximize);
1924
OkCommand = new AsyncRelayCommand(Ok);
2025
NoCommand = new AsyncRelayCommand(No);
2126
YesCommand = new AsyncRelayCommand(Yes);
2227
InitializeComponent();
2328
}
2429

30+
public AsyncRelayCommand WindowMinimizeCommand { get; }
31+
public AsyncRelayCommand WindowRestoreCommand { get; }
32+
public AsyncRelayCommand WindowMaximizeCommand { get; }
33+
public AsyncRelayCommand WindowCloseCommand { get; }
2534
public AsyncRelayCommand OkCommand { get; }
2635
public AsyncRelayCommand NoCommand { get; }
2736
public AsyncRelayCommand YesCommand { get; }
@@ -70,6 +79,40 @@ public enum MessageDialogType
7079
YesNo
7180
}
7281

82+
#region BaseWindow
83+
private Task WindowClose()
84+
{
85+
Close();
86+
return Task.CompletedTask;
87+
}
88+
89+
private Task WindowRestore()
90+
{
91+
if (WindowState == WindowState.Maximized)
92+
WindowState = WindowState.Normal;
93+
else
94+
WindowState = WindowState.Maximized;
95+
return Task.CompletedTask;
96+
}
97+
98+
private Task WindowMinimize()
99+
{
100+
WindowState = WindowState.Minimized;
101+
return Task.CompletedTask;
102+
}
103+
104+
private Task WindowMaximize()
105+
{
106+
WindowState = WindowState.Maximized;
107+
return Task.CompletedTask;
108+
}
109+
110+
private void OnContentRendered(object sender, EventArgs e)
111+
{
112+
InvalidateVisual();
113+
}
114+
#endregion
115+
73116
#region INotifyPropertyChanged
74117
public event PropertyChangedEventHandler PropertyChanged;
75118
public void NotifyPropertyChanged([CallerMemberName] string property = "")

OnnxStack.UI/Dialogs/TextInputDialog.xaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
mc:Ignorable="d"
77
Name="UI"
88
Icon="/Images/Icon.png"
9+
MinWidth="400"
910
SizeToContent="WidthAndHeight"
10-
WindowStartupLocation="CenterScreen"
11-
MinWidth="400">
12-
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15">
11+
WindowStartupLocation="CenterOwner"
12+
SnapsToDevicePixels="True"
13+
UseLayoutRounding="True"
14+
Style="{StaticResource BaseWindow}"
15+
ContentRendered="OnContentRendered">
16+
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
1317
<StackPanel DockPanel.Dock="Top">
1418
<TextBlock Text="{Binding ErrorMessage}" FontSize="13" FontWeight="DemiBold" HorizontalAlignment="Center" Foreground="Red" Margin="0,10">
1519
<TextBlock.Style>

OnnxStack.UI/Dialogs/TextInputDialog.xaml.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Extensions.Logging;
22
using OnnxStack.Core;
33
using OnnxStack.UI.Commands;
4+
using System;
45
using System.Collections.Generic;
56
using System.ComponentModel;
67
using System.Runtime.CompilerServices;
@@ -26,11 +27,19 @@ public partial class TextInputDialog : Window, INotifyPropertyChanged
2627
public TextInputDialog(ILogger<TextInputDialog> logger)
2728
{
2829
_logger = logger;
30+
WindowCloseCommand = new AsyncRelayCommand(WindowClose);
31+
WindowRestoreCommand = new AsyncRelayCommand(WindowRestore);
32+
WindowMinimizeCommand = new AsyncRelayCommand(WindowMinimize);
33+
WindowMaximizeCommand = new AsyncRelayCommand(WindowMaximize);
2934
SaveCommand = new AsyncRelayCommand(Save, CanExecuteSave);
3035
CancelCommand = new AsyncRelayCommand(Cancel, CanExecuteCancel);
3136
InitializeComponent();
37+
ErrorMessage = string.Empty;
3238
}
33-
39+
public AsyncRelayCommand WindowMinimizeCommand { get; }
40+
public AsyncRelayCommand WindowRestoreCommand { get; }
41+
public AsyncRelayCommand WindowMaximizeCommand { get; }
42+
public AsyncRelayCommand WindowCloseCommand { get; }
3443
public AsyncRelayCommand SaveCommand { get; }
3544
public AsyncRelayCommand CancelCommand { get; }
3645

@@ -113,6 +122,41 @@ private bool CanExecuteCancel()
113122
return true;
114123
}
115124

125+
#region BaseWindow
126+
127+
private Task WindowClose()
128+
{
129+
Close();
130+
return Task.CompletedTask;
131+
}
132+
133+
private Task WindowRestore()
134+
{
135+
if (WindowState == WindowState.Maximized)
136+
WindowState = WindowState.Normal;
137+
else
138+
WindowState = WindowState.Maximized;
139+
return Task.CompletedTask;
140+
}
141+
142+
private Task WindowMinimize()
143+
{
144+
WindowState = WindowState.Minimized;
145+
return Task.CompletedTask;
146+
}
147+
148+
private Task WindowMaximize()
149+
{
150+
WindowState = WindowState.Maximized;
151+
return Task.CompletedTask;
152+
}
153+
154+
private void OnContentRendered(object sender, EventArgs e)
155+
{
156+
InvalidateVisual();
157+
}
158+
#endregion
159+
116160
#region INotifyPropertyChanged
117161
public event PropertyChangedEventHandler PropertyChanged;
118162
public void NotifyPropertyChanged([CallerMemberName] string property = "")

OnnxStack.UI/MainWindow.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
Width="1200"
1212
Height="700"
1313
MinWidth="820"
14-
MinHeight="780"
14+
MinHeight="600"
1515
Icon="/Images/Icon.png" Name="UI"
1616
RenderOptions.BitmapScalingMode="HighQuality"
1717
RenderOptions.ClearTypeHint="Enabled"
1818
TextOptions.TextFormattingMode="Ideal"
1919
TextOptions.TextRenderingMode="ClearType"
2020
TextOptions.TextHintingMode="Fixed"
2121
UseLayoutRounding="True"
22-
SnapsToDevicePixels="True">
22+
SnapsToDevicePixels="True"
23+
Style="{StaticResource BaseWindow}">
2324
<Grid DataContext="{Binding ElementName=UI}">
2425
<TabControl Style="{StaticResource SplitTabControl}" SelectedIndex="{Binding SelectedTabIndex}" SelectedValue="{Binding SelectedTabItem}" SelectedValuePath="Content" DockPanel.Dock="Top" Margin="4">
2526

OnnxStack.UI/MainWindow.xaml.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,20 @@ public MainWindow(StableDiffusionConfig configuration, ILogger<MainWindow> logge
3737
NavigateImageToImageCommand = new AsyncRelayCommand<ImageResult>(NavigateImageToImage);
3838
NavigateImageInpaintCommand = new AsyncRelayCommand<ImageResult>(NavigateImageInpaint);
3939
NavigateImageUpscaleCommand = new AsyncRelayCommand<ImageResult>(NavigateImageUpscale);
40+
41+
WindowCloseCommand = new AsyncRelayCommand(WindowClose);
42+
WindowRestoreCommand = new AsyncRelayCommand(WindowRestore);
43+
WindowMinimizeCommand = new AsyncRelayCommand(WindowMinimize);
44+
WindowMaximizeCommand = new AsyncRelayCommand(WindowMaximize);
4045
Models = CreateModelOptions(configuration.OnnxModelSets);
4146
InitializeComponent();
4247
}
4348

49+
public AsyncRelayCommand WindowMinimizeCommand { get; }
50+
public AsyncRelayCommand WindowRestoreCommand { get; }
51+
public AsyncRelayCommand WindowMaximizeCommand { get; }
52+
public AsyncRelayCommand WindowCloseCommand { get; }
53+
4454
public AsyncRelayCommand<ImageResult> SaveImageCommand { get; }
4555
public AsyncRelayCommand<ImageResult> SaveBlueprintCommand { get; }
4656
public AsyncRelayCommand<ImageResult> NavigateTextToImageCommand { get; }
@@ -186,6 +196,37 @@ public void UpdateOutputLog(string message)
186196
OutputLog += message;
187197
}
188198

199+
#region BaseWindow
200+
201+
private Task WindowClose()
202+
{
203+
Close();
204+
return Task.CompletedTask;
205+
}
206+
207+
private Task WindowRestore()
208+
{
209+
if (WindowState == WindowState.Maximized)
210+
WindowState = WindowState.Normal;
211+
else
212+
WindowState = WindowState.Maximized;
213+
return Task.CompletedTask;
214+
}
215+
216+
private Task WindowMinimize()
217+
{
218+
WindowState = WindowState.Minimized;
219+
return Task.CompletedTask;
220+
}
221+
222+
private Task WindowMaximize()
223+
{
224+
WindowState = WindowState.Maximized;
225+
return Task.CompletedTask;
226+
}
227+
228+
#endregion
229+
189230
#region INotifyPropertyChanged
190231
public event PropertyChangedEventHandler PropertyChanged;
191232
public void NotifyPropertyChanged([CallerMemberName] string property = "")

OnnxStack.UI/OnnxStack.UI.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
<None Remove="Images\placeholder_sm.png" />
2424
</ItemGroup>
2525

26-
<ItemGroup>
27-
<Page Remove="Themes\DarkTheme.xaml" />
28-
</ItemGroup>
29-
3026
<ItemGroup>
3127
<Content Include="appsettings.json">
3228
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -41,7 +37,6 @@
4137
<Resource Include="Images\Icon.png" />
4238
<Resource Include="Images\placeholder.png" />
4339
<Resource Include="Images\placeholder_sm.png" />
44-
<Resource Include="Themes\DarkTheme.xaml" />
4540
</ItemGroup>
4641

4742
<ItemGroup>

0 commit comments

Comments
 (0)