A Razor UI component that displays an item icon. It holds a Texture property and an Image child; each Tick it assigns the Texture to the image and uses BuildHash for change detection.
@using Sandbox;
@using Sandbox.UI;
@namespace Machines.UI
@inherits Panel
<image @ref="IconImage" />
@code
{
/// <summary>
/// The texture to display (e.g. a pickup's icon).
/// </summary>
public Texture Icon { get; set; }
public Sandbox.UI.Image IconImage { get; set; }
public override void Tick()
{
base.Tick();
if ( IconImage.IsValid() )
IconImage.Texture = Icon;
}
protected override int BuildHash() => System.HashCode.Combine( Icon );
}