Skip to content

Commit

Permalink
Merged PR 174: UI improvements
Browse files Browse the repository at this point in the history
- Add margin around upgrade button on home screen
- Fix default width of the window
- Retain window size across sessions
  • Loading branch information
AArnott committed Aug 25, 2024
2 parents 4620815 + aab4a30 commit 77c6b1c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/Nerdbank.Zcash.App/Nerdbank.Zcash.App/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ public override void OnFrameworkInitializationCompleted()
}

this.ViewModel.TopLevel = TopLevel.GetTopLevel(desktop.MainWindow);

// Remember the size of the window.
if (desktop.MainWindow.CanResize && this.settings is not null)
{
if (this.settings?.WindowSize is Size size)
{
desktop.MainWindow.Width = size.Width;
desktop.MainWindow.Height = size.Height;
}

desktop.MainWindow.Resized += (s, e) =>
{
if (this.settings is not null)
{
this.settings.WindowSize = new(desktop.MainWindow.Width, desktop.MainWindow.Height);
}
};
}
}
else if (this.ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{
Expand Down
19 changes: 19 additions & 0 deletions src/Nerdbank.Zcash.App/Nerdbank.Zcash.App/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel;
using System.Text.Json;
using System.Text.Json.Serialization;
using Avalonia;
using Nerdbank.Cryptocurrencies;

namespace Nerdbank.Zcash.App;
Expand Down Expand Up @@ -84,6 +85,18 @@ public string? LastUsedAccountName
set => this.RaiseAndSetIfChanged(ref this.lastUsedAccountName, value);
}

[JsonIgnore]
public Size? WindowSize
{
get => this.WindowWidth is double w && this.WindowHeight is double h ? new(w, h) : null;
set
{
this.WindowWidth = value?.Width;
this.WindowHeight = value?.Height;
this.RaisePropertyChanged();
}
}

/// <summary>
/// Gets or sets a value indicating whether exchange rates will be automatically downloaded.
/// </summary>
Expand Down Expand Up @@ -112,6 +125,12 @@ public bool IsDirty
set => this.RaiseAndSetIfChanged(ref this.isDirty, value);
}

[JsonInclude]
internal double? WindowWidth { get; set; }

[JsonInclude]
internal double? WindowHeight { get; set; }

public static AppSettings Load(Stream stream) => JsonSerializer.Deserialize(stream, JsonSourceGenerationContext.Default.AppSettings)!;

public Task SaveAsync(Stream stream, CancellationToken cancellationToken) => JsonSerializer.SerializeAsync(stream, this, JsonSourceGenerationContext.Default.AppSettings, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
<StackPanel DockPanel.Dock="Bottom"
DataContext="{Binding SelfUpdating}">
<StackPanel DataContext="{Binding UpdateDownloading}"
Margin="5"
IsVisible="{Binding IsInProgress}">
<TextBlock Text="{Binding Caption}" HorizontalAlignment="Center" />
<ProgressBar Value="{Binding Current}" Minimum="{Binding From}" Maximum="{Binding To}" />
</StackPanel>
<Button Command="{Binding UpdateAndRestartCommand}"
Content="{Binding UpdateAndRestartCommandCaption}"
Margin="5"
IsVisible="{Binding IsUpdateAndRestartCommandVisible}"
HorizontalAlignment="Center" />
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:Nerdbank.Zcash.App.Views"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="600"
Width="500" Height="650"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="650"
Width="600" Height="650"
x:Class="Nerdbank.Zcash.App.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/applogo.ico"
Expand Down

0 comments on commit 77c6b1c

Please sign in to comment.