monogame-ui-focus
MonoGame UI Focus — Keyboard & Gamepad Navigation
This skill covers how keyboard and gamepad input reaches the correct UI element. For mouse/pointer handling, see monogame-ui-interaction. For input polling fundamentals, see monogame-input. For complete code templates, read references/ui-focus.md.
Assumed Contract
UIElement.Bounds must be resolved (via
monogame-ui-layoutArrange pass) before gamepad navigation warps the visual cursor to the focused element's center. If Bounds is empty, navigation still works logically — only the visual cursor position will be wrong.This skill uses the prev/curr GamePadState pattern from
monogame-input. Do not callGamePad.GetState()inside individual element code.
UIElement.Focus.cs is the third partial file of UIElement, adding the neighbor-ID fields alongside the structural fields (Core) and layout fields (Layout).
The Focus Problem
Mouse input is positional — hit testing resolves the target automatically. Keyboard and gamepad input is not positional: you need a global reference that says "this element currently receives key presses."
Without a focus system, every element would poll every key every frame, and Tab navigation would be impossible.