ui/Panels/InputHint.razor

A UI Panel Razor component that renders a single input glyph image. It requests an input glyph texture from the engine based on the Button string, a GlyphStyle, and InputGlyphSize.Medium, and assigns it to the Image when the tree renders or when the component hash changes.

Native Interop
@using Sandbox;
@using Sandbox.UI;
@namespace SS1
@inherits Panel
@attribute [StyleSheet("InputHint.razor.scss")]

<root>
	<img @ref=Glyph />
</root>

@code
{
	// @ref
	public Image Glyph { get; set; }
	public GlyphStyle GlyphStyle { get; set; } = GlyphStyle.Knockout.WithNeutralColorABXY().WithSolidABXY();
	public string Button { get; set; }

	void UpdateTexture()
	{
		var texture = Input.GetGlyph( Button, InputGlyphSize.Medium, GlyphStyle );
		if ( texture is null ) return;
		Glyph.Texture = texture;
	}

	protected override void OnAfterTreeRender( bool firstTime )
	{
		UpdateTexture();
	}

	protected override int BuildHash()
	{
		// If we switch input device, rebuild the tree.
		return HashCode.Combine( Button, Input.UsingController );
	}
}