Skip to content

Commit

Permalink
Move error to separate window
Browse files Browse the repository at this point in the history
  • Loading branch information
ButterscotchV committed Aug 6, 2024
1 parent 627ee5f commit 88dab52
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 50 deletions.
62 changes: 62 additions & 0 deletions SlimeVrOta.Gui/ErrorDialog.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="SlimeVrOta.Gui.ErrorDialog"
Title="SlimeVR OTA Tool Error"
Icon="/Assets/icon.png"
MinWidth="200"
MinHeight="100"
MaxWidth="700"
MaxHeight="500"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner"
Padding="8"
Background="{DynamicResource BackgroundBrush}">

<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="BackgroundBrush">WhiteSmoke</SolidColorBrush>
<SolidColorBrush x:Key="MidgroundBrush">#e2d8eb</SolidColorBrush>
<BoxShadows x:Key="BorderShadow">1 1 8 2 #c5c5c5</BoxShadows>
<SolidColorBrush x:Key="ProgressBrush">#d080ff</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="BackgroundBrush">#252525</SolidColorBrush>
<SolidColorBrush x:Key="MidgroundBrush">#383442</SolidColorBrush>
<BoxShadows x:Key="BorderShadow">1 1 8 2 #161616</BoxShadows>
<SolidColorBrush x:Key="ProgressBrush">#a070d0</SolidColorBrush>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Window.Resources>

<Grid RowDefinitions="*,Auto">
<Border Grid.Row="0"
CornerRadius="4"
BoxShadow="{DynamicResource BorderShadow}"
Background="{DynamicResource MidgroundBrush}"
VerticalAlignment="Stretch">
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
AllowAutoHide="False">
<SelectableTextBlock Name="ErrorText"
TextWrapping="Wrap"
Padding="8"
SelectionBrush="{DynamicResource ProgressBrush}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
Unknown error.
</SelectableTextBlock>
</ScrollViewer>
</Border>
<Button Grid.Row="1"
Margin="0 8 0 0"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Name="CloseErrorButton">
Close
</Button>
</Grid>
</Window>
16 changes: 16 additions & 0 deletions SlimeVrOta.Gui/ErrorDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Avalonia.Controls;

namespace SlimeVrOta.Gui;

public partial class ErrorDialog : Window
{
public ErrorDialog()
{
InitializeComponent();

CloseErrorButton.Click += (_, _) =>
{
Close();
};
}
}
43 changes: 0 additions & 43 deletions SlimeVrOta.Gui/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="BackgroundBrush">WhiteSmoke</SolidColorBrush>
<SolidColorBrush x:Key="MidgroundBrush">#e2d8eb</SolidColorBrush>
<SolidColorBrush x:Key="BorderBrush">#706080</SolidColorBrush>
<BoxShadows x:Key="BorderShadow">1 1 8 2 #c5c5c5</BoxShadows>
<SolidColorBrush x:Key="ProgressBrush">#d080ff</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="BackgroundBrush">#252525</SolidColorBrush>
<SolidColorBrush x:Key="MidgroundBrush">#383442</SolidColorBrush>
<SolidColorBrush x:Key="BorderBrush">#908892</SolidColorBrush>
<BoxShadows x:Key="BorderShadow">1 1 8 2 #161616</BoxShadows>
<SolidColorBrush x:Key="ProgressBrush">#a070d0</SolidColorBrush>
</ResourceDictionary>
Expand All @@ -32,47 +30,6 @@
</Window.Resources>

<StackPanel x:Name="Root">
<Popup WindowManagerAddShadowHint="False"
Placement="Bottom"
Name="ErrorPopup"
MinWidth="200"
MaxWidth="700"
MaxHeight="500">
<Border Padding="8"
CornerRadius="4"
BorderThickness="3"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource BackgroundBrush}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid RowDefinitions="*,Auto">
<Border Grid.Row="0"
CornerRadius="4"
Background="{DynamicResource MidgroundBrush}"
VerticalAlignment="Stretch">
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
AllowAutoHide="False">
<SelectableTextBlock Name="ErrorText"
TextWrapping="Wrap"
Padding="8"
SelectionBrush="{DynamicResource ProgressBrush}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
Unknown error.
</SelectableTextBlock>
</ScrollViewer>
</Border>
<Button Grid.Row="1"
Margin="0 8 0 0"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Name="CloseErrorButton">
Close
</Button>
</Grid>
</Border>
</Popup>

<Border Padding="8"
CornerRadius="4"
BoxShadow="{DynamicResource BorderShadow}"
Expand Down
12 changes: 5 additions & 7 deletions SlimeVrOta.Gui/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public MainWindow()
{
InitializeComponent();

CloseErrorButton.Click += CloseError;
FirmwareDropBox.AddHandler(DragDrop.DropEvent, SelectFirmwareDrop);
SelectFileButton.Click += SelectFirmwareBrowse;
RemoveTrackerButton.Click += RemoveTracker;
Expand Down Expand Up @@ -118,15 +117,14 @@ protected override void OnClosed(EventArgs e)

private void ShowError(string text)
{
ErrorText.Text = text;
ErrorPopup.IsOpen = true;
var dialog = new ErrorDialog();
dialog.ErrorText.Text = text;
dialog.Closed += OnErrorClose;
dialog.ShowDialog(this);
}

public void CloseError(object? sender, RoutedEventArgs e)
private void OnErrorClose(object? sender, EventArgs e)
{
ErrorText.Text = "Unknown error.";
ErrorPopup.IsOpen = false;

if (_runDiscoveryOnClose && CurrentState == FlashState.Connecting)
{
_ = ReceiveHandshake(5000);
Expand Down

0 comments on commit 88dab52

Please sign in to comment.