Demos/AnimationShowcase/Components/TabBar.cs
using System;
using Goo;
using Sandbox.UI;
using static Sandbox.DemoTokens;

namespace Sandbox.AnimationShowcase;

public static class TabBar
{
    public static Container Build( int active, Action<int> onSelect, params string[] labels )
    {
        var bar = new Container
        {
            // Stable key so the parent's top-level Children list can be all-keyed
            // (paired with a Key on the active-page slot) and avoid the
            // "Keyless child list changed length" warning when tabs swap.
            Key           = "tab-bar",
            FlexDirection = FlexDirection.Row,
            Gap           = Space2,
        };
        for ( int i = 0; i < labels.Length; i++ )
            bar.Children.Add( Tab( labels[i], i, active, onSelect ) );
        return bar;
    }

    static Container Tab( string label, int index, int active, Action<int> onSelect )
    {
        bool isActive = active == index;
        return new Container
        {
            Padding              = Space3,
            BackgroundColor      = isActive ? Accent : BgCard,
            HoverBackgroundColor = isActive ? Accent : BgCardHi,
            BorderRadius         = Radius2,
            PointerEvents        = PointerEvents.All,
            OnClick = _ => { if ( active != index ) onSelect( index ); },
            Children =
            {
                new Text( label )
                {
                    FontColor = isActive ? TextOnAccent : FgPrimary,
                    FontSize  = FontBodySm,
                },
            },
        };
    }
}