Struggling to make UI toolkit work with kbm and gamepad. Especially when it gets more complicated. A sample might help
This stuff is tough, especially mixing mouse and gamepad: one has no notion of focus, the other relies 100% on the notion of focus (cursor).
With UGUI the go-to method is to override the InputModule and make your own that blends it how you want. I’m not familiar enough with how complete UI Toolkit might be at this stage to judge if that would help or not.
+1 for good example of mouse + gamepad input. Right now I’m using :focused pseudo state everywhere, when hovering with mouse I instantly focus element under pointer like this
RegisterCallback<MouseMoveEvent>(evt =>
{
VisualElement element = panel.Pick(evt.mousePosition);
if (element.focusable)
{
element.Focus();
}
});
To disable defocusing when clicking on something:
RegisterCallback<MouseDownEvent>(evt =>
{
evt.StopPropagation();
(evt.currentTarget as VisualElement)?.panel.focusController.IgnoreEvent(evt);
});
This work pretty well with gamepad but right now I’m strugling to understand how I should combine this with :checked pseudo state which is used by ListView for example when selecting items.
Also we need better navigation support like in UGUI