Added new RHI abstraction layer;

Added new console debug page to UnitTest;
This commit is contained in:
2025-08-25 10:48:59 +09:00
parent eafbfb2fa1
commit 5385141f14
44 changed files with 3473 additions and 357 deletions

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Ghost.UnitTest.Controls.DebugConsole"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Ghost.UnitTest.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<UserControl.Resources>
<local:LogLevelToColorConverter x:Key="LogLevelToColorConverter" />
<local:LogLevelToSymbolConverter x:Key="LogLevelToSymbolConverter" />
<DataTemplate x:Key="LogItemTemplate">
<Border Padding="8,4" Background="Transparent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Margin="0,0,8,0"
VerticalAlignment="Center"
FontFamily="Segoe UI Symbol"
Foreground="{Binding Level, Converter={StaticResource LogLevelToColorConverter}}"
Text="{Binding Level, Converter={StaticResource LogLevelToSymbolConverter}}" />
<TextBlock
Grid.Column="1"
Margin="0,0,8,0"
VerticalAlignment="Center"
FontFamily="Consolas"
Foreground="Gray"
Text="{Binding Timestamp}" />
<TextBlock
Grid.Column="2"
VerticalAlignment="Center"
Text="{Binding Message}"
TextWrapping="Wrap" />
</Grid>
</Border>
</DataTemplate>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Toolbar -->
<Border
Grid.Row="0"
Background="{ThemeResource SystemControlBackgroundAltMediumBrush}"
BorderBrush="{ThemeResource SystemControlForegroundBaseLowBrush}"
BorderThickness="0,0,0,1">
<StackPanel Margin="8,4" Orientation="Horizontal">
<Button
x:Name="ClearButton"
Margin="0,0,8,0"
Click="ClearButton_Click"
Content="Clear" />
<CheckBox
x:Name="AutoScrollCheckBox"
Margin="0,0,8,0"
Content="Auto Scroll"
IsChecked="True" />
<CheckBox
x:Name="ShowStackTraceCheckBox"
Margin="0,0,8,0"
Checked="ShowStackTraceCheckBox_Checked"
Content="Stack Trace"
Unchecked="ShowStackTraceCheckBox_Unchecked" />
<!-- Log level filters -->
<TextBlock
Margin="16,0,8,0"
VerticalAlignment="Center"
Text="Show:" />
<CheckBox
x:Name="ShowInfoCheckBox"
Margin="0,0,4,0"
Content="Info"
IsChecked="True" />
<CheckBox
x:Name="ShowWarningCheckBox"
Margin="0,0,4,0"
Content="Warning"
IsChecked="True" />
<CheckBox
x:Name="ShowErrorCheckBox"
Margin="0,0,4,0"
Content="Error"
IsChecked="True" />
<CheckBox
x:Name="ShowDebugCheckBox"
Margin="0,0,4,0"
Content="Debug"
IsChecked="True" />
</StackPanel>
</Border>
<!-- Log display -->
<ScrollViewer
x:Name="LogScrollViewer"
Grid.Row="1"
HorizontalScrollBarVisibility="Auto"
HorizontalScrollMode="Auto"
VerticalScrollBarVisibility="Auto"
VerticalScrollMode="Auto"
ZoomMode="Disabled">
<ItemsRepeater x:Name="LogItemsRepeater" ItemTemplate="{StaticResource LogItemTemplate}" />
</ScrollViewer>
</Grid>
</UserControl>

View File

@@ -0,0 +1,165 @@
using Ghost.UnitTest.Models;
using Ghost.UnitTest.Services;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
using System.Collections.ObjectModel;
namespace Ghost.UnitTest.Controls;
public sealed partial class DebugConsole : UserControl
{
private readonly ObservableCollection<LogItem> _filteredLogs = [];
private readonly LoggingService _loggingService;
public DebugConsole()
{
InitializeComponent();
_loggingService = LoggingService.Instance;
LogItemsRepeater.ItemsSource = _filteredLogs;
// Subscribe to logging events
_loggingService.LogAdded += OnLogAdded;
_loggingService.LogsCleared += OnLogsCleared;
// Subscribe to filter changes
ShowInfoCheckBox.Checked += OnFilterChanged;
ShowInfoCheckBox.Unchecked += OnFilterChanged;
ShowWarningCheckBox.Checked += OnFilterChanged;
ShowWarningCheckBox.Unchecked += OnFilterChanged;
ShowErrorCheckBox.Checked += OnFilterChanged;
ShowErrorCheckBox.Unchecked += OnFilterChanged;
ShowDebugCheckBox.Checked += OnFilterChanged;
ShowDebugCheckBox.Unchecked += OnFilterChanged;
// Load existing logs
RefreshLogs();
}
private void OnLogAdded(LogItem logItem)
{
DispatcherQueue.TryEnqueue(() =>
{
if (ShouldShowLogItem(logItem))
{
_filteredLogs.Add(logItem);
if (AutoScrollCheckBox.IsChecked == true)
{
LogScrollViewer.ScrollToVerticalOffset(LogScrollViewer.ScrollableHeight);
}
}
});
}
private void OnLogsCleared()
{
DispatcherQueue.TryEnqueue(() =>
{
_filteredLogs.Clear();
});
}
private void OnFilterChanged(object sender, RoutedEventArgs e)
{
RefreshLogs();
}
private bool ShouldShowLogItem(LogItem logItem)
{
return logItem.Level switch
{
LogLevel.Info => ShowInfoCheckBox.IsChecked == true,
LogLevel.Warning => ShowWarningCheckBox.IsChecked == true,
LogLevel.Error => ShowErrorCheckBox.IsChecked == true,
LogLevel.Debug => ShowDebugCheckBox.IsChecked == true,
_ => true
};
}
private void RefreshLogs()
{
_filteredLogs.Clear();
foreach (var log in _loggingService.Logs)
{
if (ShouldShowLogItem(log))
{
_filteredLogs.Add(log);
}
}
if (AutoScrollCheckBox.IsChecked == true)
{
LogScrollViewer.ScrollToVerticalOffset(LogScrollViewer.ScrollableHeight);
}
}
private void ClearButton_Click(object sender, RoutedEventArgs e)
{
_loggingService.Clear();
}
private void ShowStackTraceCheckBox_Checked(object sender, RoutedEventArgs e)
{
_loggingService.CaptureStackTrace = true;
}
private void ShowStackTraceCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
_loggingService.CaptureStackTrace = false;
}
}
// Converter for log level to color
public class LogLevelToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is LogLevel level)
{
return level switch
{
LogLevel.Info => new SolidColorBrush(Colors.DodgerBlue),
LogLevel.Warning => new SolidColorBrush(Colors.Orange),
LogLevel.Error => new SolidColorBrush(Colors.Red),
LogLevel.Debug => new SolidColorBrush(Colors.Gray),
_ => new SolidColorBrush(Colors.Black)
};
}
return new SolidColorBrush(Colors.Black);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
// Converter for log level to symbol
public class LogLevelToSymbolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is LogLevel level)
{
return level switch
{
LogLevel.Info => "",
LogLevel.Warning => "⚠",
LogLevel.Error => "✖",
LogLevel.Debug => "🐛",
_ => "•"
};
}
return "•";
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}