BabylonJS / Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
http://www.babylonjs.com
Apache License 2.0
22.75k stars 3.39k forks source link

[GUI] allow any element to be focused #15232

Closed RaananW closed 6 days ago

RaananW commented 1 week ago

This PR adds a few parameters to control (the base class of all GUI elements):

  1. tabIndex - works similar to tabIndex in HTML. Defaults to -1, meaning - not focusable
  2. focusedColor - the (border) color of the element if it is focussed using tab
  3. onEnterPressedObservable - works similat to onPointerClicked - what happens when enter is pressed on a focused element.

Any control has onBlur and onFocus callbacks, and observables to catch these events.

The ADT has a flag that can turn off the entire behavior (disableTabNavigation). It is on per default, but since tabIndex is -1 per default, it shouldn't change anything.

There is a slight typing change, but it shouldn't be a breaking change, as we moved from an interface to a class that holds the entire interface (and actually implements it). The only real breaking change is the onFocusObservable in virtual keyboard, which is not often used.

Test with this playground - #KKA6L4#16

bjsplat commented 1 week ago

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). To prevent this PR from going to the changelog marked it with the "skip changelog" label.

bjsplat commented 1 week ago

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). To prevent this PR from going to the changelog marked it with the "skip changelog" label.

bjsplat commented 1 week ago

Snapshot stored with reference name: refs/pull/15232/merge

Test environment: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/15232/merge/index.html

To test a playground add it to the URL, for example:

https://babylonsnapshots.z22.web.core.windows.net/refs/pull/15232/merge/index.html#WGZLGJ#4600

Links to test babylon tools with this snapshot:

https://playground.babylonjs.com/?snapshot=refs/pull/15232/merge https://sandbox.babylonjs.com/?snapshot=refs/pull/15232/merge https://gui.babylonjs.com/?snapshot=refs/pull/15232/merge https://nme.babylonjs.com/?snapshot=refs/pull/15232/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/15232/merge#BCU1XR#0

bjsplat commented 1 week ago

WebGL2 visualization test reporter:

https://babylonsnapshots.z22.web.core.windows.net/refs/pull/15232/merge/testResults/webgl2playwright/index.html

bjsplat commented 1 week ago

Visualization tests for WebGPU (Experimental)

https://babylonsnapshots.z22.web.core.windows.net/refs/pull/15232/merge/testResults/webgpuplaywright/index.html