Code/Demos/RadialWheel/Components/SlotLabel.cs
using Goo;
using Sandbox.UI;
using static Sandbox.DemoTokens;
namespace Sandbox.RadialWheel;
// per-slot label absolutely positioned at (cx, cy); font color/weight from hover/select state, scale/font-size/flip-angle and badge string supplied by the host.
public static class SlotLabel
{
public static Container Build(
int slot,
float cx,
float cy,
float box,
string label,
string badge,
float bounce,
float fontSize,
float flipDeg,
float flipPerspective,
bool isHovered,
bool isSelected )
{
var transform = Goo.PanelTransform.Scale( bounce );
if ( flipDeg != 0f )
transform = transform.Perspective( flipPerspective ).RotateY( flipDeg );
var container = new Container
{
Key = $"label-{slot}",
Position = PositionMode.Absolute,
Left = cx - box * 0.5f,
Top = cy - box * 0.5f,
Width = box,
Height = box,
PointerEvents = PointerEvents.None,
Transform = transform,
FlexDirection = FlexDirection.Column,
JustifyContent = Justify.Center,
AlignItems = Align.Center,
FontFamily = FontUILabel,
FontSize = fontSize,
FontWeight = (isHovered || isSelected) ? WeightSemibold : WeightRegular,
FontColor = isSelected ? AccentYellow
: isHovered ? TextOnAccent
: FgPrimary,
};
container.Children.Add( new Text( label ) { Key = "main" } );
if ( badge.Length > 0 )
container.Children.Add( new Text( badge ) { Key = "badge", FontSize = 11f, FontColor = FgTertiary } );
return container;
}
}