Code/Demos/KeystrokeVisualizer/Components/EntryChip.cs
using Goo;
using Goo.Animation;
using Sandbox;
using Sandbox.UI;
using static Sandbox.DemoTokens;
namespace Sandbox.KeystrokeViz;
public readonly record struct ChipAnim(
AgePhase Phase,
float ChipHeight,
float SlideRiseFraction,
float FontSize,
float BaseOpacity,
bool SlideFromBelow );
public static class EntryChip
{
public static Container Build( int key, string label, float age, float idleAge, ChipAnim a )
{
var p = a.Phase.Project( age, idleAge );
float yOff = (a.SlideFromBelow ? 1f : -1f) * a.ChipHeight * a.SlideRiseFraction * (1f - p.Slide);
float opacity = p.Opacity * a.BaseOpacity;
return new Container
{
Key = key.ToString(),
Height = a.ChipHeight,
PaddingLeft = 14,
PaddingRight = 14,
PaddingTop = 6,
PaddingBottom = 6,
BackgroundColor = Ink2,
BorderRadius = 6f,
Opacity = opacity,
Transform = Goo.PanelTransform.Translate( 0, yOff ),
JustifyContent = Justify.Center,
AlignItems = Align.Center,
Children = { new Text( label ) { FontSize = a.FontSize, FontColor = FgPrimary } },
};
}
}