IconifyPanel.razor.cs
using System;
using Sandbox;
using Sandbox.UI;

namespace Iconify;

[Alias( "iconify" )]
public partial class IconifyPanel : Panel
{
	public static readonly BaseFileSystem? DefaultCache;

	private Texture? _svgTexture;

	public string Icon { get; set; }
	public string? Color { get; set; } = "white";
	public int Size { get; set; } = 32;

	static IconifyPanel()
	{
		if ( FileSystem.Data is null )
			return;

		FileSystem.Data.CreateDirectory( "iconify" );
		DefaultCache = FileSystem.Data.CreateSubSystem( "iconify" );
	}

	protected override void OnAfterTreeRender( bool firstTime ) => SetIcon();

	protected override int BuildHash() => HashCode.Combine( _svgTexture, Icon, Color, Size );

	private void SetIcon()
	{
		_svgTexture = Texture.White;

		var icon = new IconifyIcon( Icon );
		var rect = Box.Rect;
		var tintColor = Color ?? (ComputedStyle ?? Style)?.FontColor;

		icon.LoadTextureAsync( rect, tintColor ).ContinueWith( ( task ) =>
		{
			Log.Trace( $"Loaded icon {task.Result?.ResourcePath}" );
			_svgTexture = task.Result;
		} );
	}
}