Files
NebulaLauncher/Nebula.Launcher/Converters/TypeConverters.cs

32 lines
1.2 KiB
C#
Raw Normal View History

2025-07-14 10:06:38 +03:00
using System;
2024-12-21 13:11:30 +03:00
using Avalonia.Data.Converters;
using Avalonia.Media;
2025-07-14 10:06:38 +03:00
using Avalonia.Platform;
2025-12-11 21:47:54 +03:00
using Nebula.Launcher.Utils;
2025-08-06 21:29:00 +03:00
using Nebula.Launcher.ViewModels.Pages;
using Color = System.Drawing.Color;
2024-12-21 13:11:30 +03:00
namespace Nebula.Launcher.Converters;
2025-07-14 10:06:38 +03:00
public static class TypeConverters
2024-12-21 13:11:30 +03:00
{
2025-01-18 18:20:11 +03:00
public static FuncValueConverter<string, string?> IconConverter { get; } =
2024-12-21 13:11:30 +03:00
new(iconKey =>
{
2025-01-18 18:20:11 +03:00
if (iconKey == null) return null;
return $"/Assets/svg/{iconKey}.svg";
2024-12-21 13:11:30 +03:00
});
2025-07-14 10:06:38 +03:00
public static FuncValueConverter<string, IImage?> ImageConverter { get; } =
new(iconKey =>
{
if (iconKey == null) return null;
return new Avalonia.Media.Imaging.Bitmap(AssetLoader.Open(new Uri($"avares://Nebula.Launcher/Assets/error_presentation/{iconKey}.png")));
});
2025-08-06 21:29:00 +03:00
public static FuncValueConverter<string, Avalonia.Media.Color> NameColorRepresentation { get; } =
2025-09-08 21:26:12 +03:00
new((str)=>ColorUtils.GetColorFromString(str ?? throw new ArgumentNullException(nameof(str),"Name of color is null!")));
2025-11-08 13:42:11 +03:00
public static FuncValueConverter<string, bool> StringIsNotEmpty { get; } =
new(iconKey => !string.IsNullOrEmpty(iconKey));
2024-12-21 13:11:30 +03:00
}