Demos/RadialWheel/Components/Center.cs
using System;
using Goo;
using Sandbox;
using Sandbox.UI;
using static Sandbox.DemoTokens;
namespace Sandbox.RadialWheel;
// Center disc: idle = styled X dismiss button; hover = slot icon + title.
public static class Center
{
public readonly record struct SlotContent( string Title, string IconSrc, bool IsSelected );
const float XButtonSize = 64f;
const float XButtonBlur = 6f;
const float XButtonBgAlpha = 0.85f;
const float XButtonBorderAlpha = 0.08f;
public static Container Build( SlotContent? hovered, float innerDiameterPx )
{
var iconColor = (hovered is SlotContent s1 && s1.IsSelected) ? Hex( AccentYellow ) : Hex( FgPrimary );
var titleColor = (hovered is SlotContent s2 && s2.IsSelected) ? AccentYellow : FgPrimary;
var root = new Container
{
Key = "center",
Position = PositionMode.Absolute,
Top = Length.Percent( 50 ),
Left = Length.Percent( 50 ),
Width = innerDiameterPx,
Height = innerDiameterPx,
Transform = Goo.PanelTransform.Translate( -innerDiameterPx * 0.5f, -innerDiameterPx * 0.5f ),
FlexDirection = FlexDirection.Column,
JustifyContent = Justify.Center,
AlignItems = Align.Center,
PointerEvents = PointerEvents.None,
};
if ( hovered is SlotContent slot )
{
root.Children.Add( new Goo.SvgPanel
{
Key = "icon",
Path = slot.IconSrc,
Color = iconColor,
Width = 48f,
Height = 48f,
} );
root.Children.Add( new Text( slot.Title )
{
Key = "title",
FontSize = 18f,
FontColor = titleColor,
} );
}
else
{
var xButton = new Container
{
Key = "x-button",
Width = XButtonSize,
Height = XButtonSize,
BackgroundColor = Ink2.WithAlpha( XButtonBgAlpha ),
BackdropFilterBlur = XButtonBlur,
BorderColor = FgPrimary.WithAlpha( XButtonBorderAlpha ),
BorderWidth = 1,
BorderTopLeftRadius = Length.Percent( 50 ),
BorderTopRightRadius = Length.Percent( 50 ),
BorderBottomLeftRadius = Length.Percent( 50 ),
BorderBottomRightRadius = Length.Percent( 50 ),
JustifyContent = Justify.Center,
AlignItems = Align.Center,
PointerEvents = PointerEvents.None,
};
xButton.Children.Add( new Text( "×" ) // U+00D7 multiplication sign, heavier than lowercase x
{
Key = "dismiss",
FontSize = 28f,
FontColor = FgSecondary,
} );
root.Children.Add( xButton );
}
return root;
}
static string Hex( Color c )
{
int r = Math.Clamp( (int)( c.r * 255 ), 0, 255 );
int g = Math.Clamp( (int)( c.g * 255 ), 0, 255 );
int b = Math.Clamp( (int)( c.b * 255 ), 0, 255 );
return $"#{r:X2}{g:X2}{b:X2}";
}
}