A UI Razor component that displays an input glyph for a given action. It queries Sandbox.Input.GetGlyph with an action name, size and style, then sets the panel background to that glyph image.
@using System
@using Sandbox
@using Sandbox.UI
@namespace BrickJam.UI
@inherits Panel
<root />
@code {
public string Action { get; set; }
public InputGlyphSize GlyphSize { get; set; } = InputGlyphSize.Small;
public GlyphStyle GlyphStyle { get; set; } = GlyphStyle.Knockout;
protected override void OnAfterTreeRender( bool firstTime )
{
base.OnAfterTreeRender( firstTime );
Update();
}
public void Update()
{
if ( string.IsNullOrEmpty( Action ) )
return;
// Pass an explicit GlyphStyle to disambiguate the GetGlyph overloads.
var glyph = Input.GetGlyph( Action, GlyphSize, GlyphStyle );
if ( glyph is not null )
Style.BackgroundImage = glyph;
}
public override void SetProperty( string name, string value )
{
base.SetProperty( name, value );
if ( name is "action" or "Action" )
{
Action = value;
Update();
}
}
protected override int BuildHash() => HashCode.Combine( Action );
}
<style>
InputGlyph {
background-size: contain;
background-position: center;
background-repeat: no-repeat;
filter: drop-shadow(3px 3px 1px black);
}
</style>