Demos/ComposableHud/HudElement.cs
using Goo;
using Sandbox;
using Sandbox.UI;

namespace Sandbox.ComposableHud;

// Composition contract for the composable HUD. Every element advertises where it anchors, ticks itself (returning whether it needs a rebuild), and emits its inner content; the host wraps that content in an anchored cell. Mirrors the shape CompassView/KeystrokeView/RadialView already expose so adapted elements compose without changing their code.
public abstract class HudElement
{
    public Layout.Anchor Anchor  { get; init; } = Layout.Anchor.Center;
    public float         Padding { get; init; }
    public string?       Key     { get; init; }

    // True when the element changed this frame and the host should rebuild.
    public abstract bool Tick( Scene? scene, float dt );

    // The element's inner content. The host anchors it; the element does not self-anchor.
    public abstract Container Build();
}