Class DOMRoot

Like Root, but for easy use in an HTML page.

Instead of calling each individual update method, simply call DOMRoot#update on every animation frame. Drivers still need to be manually registered.

Hierarchy (view full)

Constructors

Properties

_enabled: boolean = true

Is the Root enabled? For internal use only.

See Root#enabled

_foci: Map<FocusType, null | Widget> = ...

Current component foci (event targets for each focus type).

For internal use only.

See Root#requestFocus, Root#dropFocus, Root#clearFocus and Root#getFocus

_fociCapturers: Map<FocusType, null | Widget> = ...

Last capturer of each component focus (event targets for each focus type).

For internal use only.

See Root#getFocusCapturer

_pointerStyleHandler: null | PointerStyleHandler = null

For internal use only. Current value of Root#pointerStyleHandler.

domCanvasContext: CanvasRenderingContext2D

This root's canvas element's context. Used for painting

domElem: HTMLCanvasElement

This root's canvas element. Add this to the HTML body

domSizeController?: DOMSizeController

A function that controls the size of the DOM element of this UI root. Optional.

drivers: Set<Driver> = ...

The list of drivers registered to this root

tabFocusable: boolean

Can tab controls be used in this UI root? True by default. Can only be set once when the UI is created.

textInputHandler: null | (new (listener: TextInputHandlerListener) => TextInputHandler) = null

Text input handler constructor for environments where getting keyboard input is hard, such as mobile and WebXR. If not null, widgets that need text may call this to get strings and cursor positions as text is typed.

See Root#getTextInput

viewport: CanvasViewport

The internal viewport. Manages drawing

Accessors

  • get canvas(): HTMLCanvasElement
  • The Root#viewport's canvas. The canvas must not be modified directly; consider it output-only.

    Returns HTMLCanvasElement

  • get pointerStyleHandler(): null | PointerStyleHandler
  • Pointer style handler, decides how to show the given pointer style. Normally a function which sets the CSS cursor style of the Root's canvas

    Returns null | PointerStyleHandler

  • set pointerStyleHandler(pointerStyleHandler): void
  • Parameters

    Returns void

  • get resolution(): number
  • Shortcut for Root#viewport's CanvasViewport#resolution property.

    Note that, although the resolution is part of the CanvasViewport API, widgets will treat the resolution property as being per-Root, not per-Viewport (hence the lack of a Viewport.resolution property). The resolution property is part of the CanvasViewport class so that CanvasViewport is not circularly dependent on the Root class.

    Returns number

  • set resolution(resolution): void
  • Parameters

    • resolution: number

    Returns void

Methods

  • Destroy this Root. Disables the Root, clears all drivers, detaches the Root#child Widget and resets Root#textInputHandler.

    Root must not be used after calling this method. Doing so will cause exceptions to be thrown. There is no way to un-destroy a destroyed Root.

    Call this if you are no longer going to use this Root.

    Returns void

  • Stop assigning a specific widget ID. Must not be called manually.

    Parameters

    • id: string

      The ID to stop assigning

    Returns void

  • Dispose all resources associated with text input handler. You probably don't need to implement this method, unless you do something with the HTML elements returned by the input handler (such as listening to focus or blur events).

    Parameters

    Returns void

  • Handle initialization of a text input handler. You probably don't need to implement this method, unless you do something with the HTML elements returned by the input handler (such as listening to focus or blur events).

    Parameters

    Returns void

  • Mark a widget as hovered (received a pointer event since the last check). Widgets will call this method automatically, there is no need to manually call this.

    Parameters

    Returns void

  • Listen to a specific event with a user listener. Chainable.

    Only events that pass through the Root will be listened; all trickling events that start at the root will be listened, sticky events will only be listened if they are dispatched at the Root, and bubbling events will only be listened if none of the child widgets capture the event.

    Parameters

    • eventType: string

      The WidgetEvent#"type" to listen to

    • listener: WidgetEventListener

      The user-provided callback that will be invoked when the event is listened

    • once: boolean = false

      Should the listener only be invoked once? False by default

    Returns this

  • Similar to Root#on, but any event type invokes the user-provided callback, the listener can't be invoked only once, and the listener is called with a lower priority than specific event listeners. Chainable.

    Parameters

    • listener: WidgetEventListener

      The user-provided callback that will be invoked when a event is listened

    Returns this

  • Paint this root's next frame if needed. Does nothing if root is disabled.

    Calls Root#viewport's Viewport#paint with Root#child.

    Call this after calling Root#postLayoutUpdate.

    Returns null | Rect[]

    Returns a list of dirty rectangles in the texture's coordinates, or null if the child widget was not repainted. Use this to tell an external 3D library whether to update a mesh's texture or not, and where to update the mesh's texture.

  • Request that a specific ID is assigned to a specific Widget that is attached to this Root. Must not be called manually; Widget will automatically manage its ID when needed.

    Parameters

    • id: string

      The wanted ID

    • widget: Widget

      The widget that the ID will be assigned to

    Returns void

  • Request a pointer style. If the pointer style has a lower priority than the current pointer style, it won't be displayed, but will still be queued up in case the higher-priority style is cleared.

    Does nothing if the widget is inactive or doesn't belong to this UI root.

    Parameters

    • widget: Widget
    • pointerStyle: string
    • Optionalsource: unknown

    Returns void

  • Re-scale the DOM element of this UI root. You only need to manually call this if you use a DOMRoot#domSizeController and an external factor would affect the result of your custom size.

    Counters Root viewport scaling with an opposite CSS scale (via width and height, not CSS transforms), and applies size given by domSizeController, if any is supplied.

    Returns void

  • Internal

    Creates a new CanvasViewport instance for a new Root. Normally it wouldn't make sense to separate this from the constructor, but this makes viewport creation hookable, allowing for the creation of debug overlay viewports.

    Parameters

    Returns CanvasViewport

    Returns a new CanvasViewport (or child class instance) for the Root