ui: show icon preview next to name during icon selection

merge-requests/128/head
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
{
public class ApplicationIcon
@ -8,5 +11,13 @@ namespace Ryujinx.Ava.Common.Models
{
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);
if (activeIconStream != null)
{
// SVG files need to be converted to an image first
if (selectedIcon.FullPath.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
Bitmap logoBitmap = GetBitmapForLogo(selectedIcon);
if (logoBitmap != null)
{
Stream pngStream = ConvertSvgToPng(activeIconStream);
CurrentLogoBitmap.Value = new Bitmap(pngStream);
}
else
{
CurrentLogoBitmap.Value = new Bitmap(activeIconStream);
CurrentLogoBitmap.Value = logoBitmap;
}
}
}
@ -82,6 +77,24 @@ namespace Ryujinx.Ava.UI.Controls
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)
{
int width = 256;

View File

@ -173,7 +173,10 @@
SelectedIndex="{Binding AppIconSelectedIndex}">
<ComboBox.ItemTemplate>
<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>
</ComboBox.ItemTemplate>
</ComboBox>