UI/SignPanel.razor
@using Sandbox
@using Sandbox.UI
@inherits PanelComponent
@namespace Sandbox
<root>
<label class="title" @ref=textPanel style="color: @Color.Hex;">
@Text
</label>
</root>
@code {
[Property] public string Text { get; set; }
[Property] public Color Color { get; set; } = Color.White;
Panel textPanel;
float marquee = 0.0f;
const float Speed = 400;
protected override void OnUpdate()
{
base.OnUpdate();
if ( textPanel is null || Panel is null )
return;
if ( Panel.Box.Rect.Width < 1 || textPanel.Box.Rect.Width < 1 )
return;
marquee += Time.Delta * Speed;
float width = textPanel.Box.RectOuter.Width;
if ( marquee > (width + Panel.Box.Rect.Width) )
marquee = 0;
textPanel.Style.Right = Length.Pixels( (marquee - width) * Panel.ScaleFromScreen );
}
protected override int BuildHash() => System.HashCode.Combine( Text, Color );
}