Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

1.0 KB
Raw Blame
#nullable enable
using UnityEngine.UIElements;

namespace Statecraft.Game.UI
{
    /// <summary>Keeps the focus look for the keyboard only. UI Toolkit focuses a Button on pointer-down and has no
    /// :focus-visible, so after a mouse click the button would keep the focus fill (Statecraft.uss Button:focus) until
    /// something else took focus. One ClickEvent callback at the UI root blurs the clicked Button: every Button, the ones
    /// made at runtime (event options, Cabinet seats, Budget rows) included. Enter and Space raise NavigationSubmitEvent,
    /// not ClickEvent, so keyboard focus stays.</summary>
    public sealed class PointerBlur : System.IDisposable
    {
        readonly VisualElement root;
        static readonly EventCallback<ClickEvent> OnClick = e => (e.target as VisualElement)?.GetFirstOfType<Button>()?.Blur();

        public PointerBlur(VisualElement root) { this.root = root; root.RegisterCallback(OnClick); }

        public void Dispose() => root.UnregisterCallback(OnClick);
    }
}