ui: show icon preview next to name during icon selection

This commit is contained in:
VewDev
2025-09-02 12:22:33 +02:00
parent 8e2f8f4413
commit 0bdd4ad091
3 changed files with 36 additions and 9 deletions

View File

@@ -1,3 +1,6 @@
using Avalonia.Media.Imaging;
using Ryujinx.Ava.UI.Controls;
namespace Ryujinx.Ava.Common.Models namespace Ryujinx.Ava.Common.Models
{ {
public class ApplicationIcon public class ApplicationIcon
@@ -8,5 +11,13 @@ namespace Ryujinx.Ava.Common.Models
{ {
get => $"Ryujinx/Assets/Icons/AppIcons/{Filename}"; get => $"Ryujinx/Assets/Icons/AppIcons/{Filename}";
} }
public Bitmap Icon
{
get
{
return RyujinxLogo.GetBitmapForLogo(this);
}
}
} }
} }

View File

@@ -60,15 +60,10 @@ namespace Ryujinx.Ava.UI.Controls
Stream activeIconStream = EmbeddedResources.GetStream(selectedIcon.FullPath); Stream activeIconStream = EmbeddedResources.GetStream(selectedIcon.FullPath);
if (activeIconStream != null) if (activeIconStream != null)
{ {
// SVG files need to be converted to an image first Bitmap logoBitmap = GetBitmapForLogo(selectedIcon);
if (selectedIcon.FullPath.EndsWith(".svg", StringComparison.OrdinalIgnoreCase)) if (logoBitmap != null)
{ {
Stream pngStream = ConvertSvgToPng(activeIconStream); CurrentLogoBitmap.Value = logoBitmap;
CurrentLogoBitmap.Value = new Bitmap(pngStream);
}
else
{
CurrentLogoBitmap.Value = new Bitmap(activeIconStream);
} }
} }
} }
@@ -82,6 +77,24 @@ namespace Ryujinx.Ava.UI.Controls
private void WindowIconChanged_Event(object _, ReactiveEventArgs<string> rArgs) => SetNewAppIcon(rArgs.NewValue); private void WindowIconChanged_Event(object _, ReactiveEventArgs<string> rArgs) => SetNewAppIcon(rArgs.NewValue);
public static Bitmap GetBitmapForLogo(ApplicationIcon icon)
{
Stream activeIconStream = EmbeddedResources.GetStream(icon.FullPath);
if (activeIconStream == null)
return null;
// SVG files need to be converted to an image first
if (icon.FullPath.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
{
Stream pngStream = ConvertSvgToPng(activeIconStream);
return new Bitmap(pngStream);
}
else
{
return new Bitmap(activeIconStream);
}
}
private static Stream ConvertSvgToPng(Stream svgStream) private static Stream ConvertSvgToPng(Stream svgStream)
{ {
int width = 256; int width = 256;

View File

@@ -173,7 +173,10 @@
SelectedIndex="{Binding AppIconSelectedIndex}"> SelectedIndex="{Binding AppIconSelectedIndex}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name}" /> <StackPanel Orientation="Horizontal" >
<Image Source="{Binding Icon}" Width="24" Height="24" Margin="0,0,8,0" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate> </DataTemplate>
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>