A lazy-widgets Root which automatically manages a mesh and input. For an example on how to use this in a component, see example-components/test-ui-root.js

Note that the properties object can also contain optional parameters for the lazy-widgets Root constructor, and will be passed to it.

If texture bleeding prevention is not specified, then it will be enabled by default. Same applies for texture atlas bleeding prevention.

If a pointer style handler is not specified, then a default pointer style handler that changes the cursor style of the Wonderland Engine canvas will be be used.

Hierarchy

Constructors

Properties

Accessors

Methods

Constructors

  • Parameters

    • wlObject: Object3D

      The object where the mesh will be added.

    • material: Material

      The material to use for this root's mesh. The material will be cloned.

    • child: Widget

      The root's child widget.

    • Optional properties: WLRootProperties

    Returns WLRoot

Properties

_enabled: boolean

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

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

boundTo: HTMLElement
collision: null | CollisionComponent = null
collisionOverextensionPixels: number
curCollisionOverextension: number = 0
cursorStyleManager: null | ICursorStyleManager
cursorTarget: null | CursorTarget = null
destroyTextureWhenDisabled: boolean
downFunction: null | ((object, cursor, ev?) => void) = null

Type declaration

    • (object, cursor, ev?): void
    • Parameters

      • object: Object3D
      • cursor: Cursor
      • Optional ev: EventTypes

      Returns void

drivers: Set<Driver>

The list of drivers registered to this root

hasPasteEvents: boolean = false
keydownEventListener: null | ((event) => void) = null

Type declaration

    • (event): void
    • Parameters

      • event: KeyboardEvent

      Returns void

keyupEventListener: null | ((event) => void) = null

Type declaration

    • (event): void
    • Parameters

      • event: KeyboardEvent

      Returns void

lastUnitsPerPixel: number
lastWorldScale: Float32Array = ...
materialClone: Material
mesh: null | Mesh = null
meshComponent: null | MeshComponent
meshObject: null | Object3D
moveFunction: null | ((object, cursor, ev?) => void) = null

Type declaration

    • (object, cursor, ev?): void
    • Parameters

      • object: Object3D
      • cursor: Cursor
      • Optional ev: EventTypes

      Returns void

oldTexSize: [number, number] = ...
overextendCollisionOnCursorCapture: boolean
paintedOnce: boolean = false
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) => TextInputHandler)

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

Type declaration

texture: null | Texture = null
textureUniformName?: string
unHoverFunction: null | ((object, cursor, ev?) => void) = null

Type declaration

    • (object, cursor, ev?): void
    • Parameters

      • object: Object3D
      • cursor: Cursor
      • Optional ev: EventTypes

      Returns void

unitsPerPixel: number
upFunction: null | ((object, cursor, ev?) => void) = null

Type declaration

    • (object, cursor, ev?): void
    • Parameters

      • object: Object3D
      • cursor: Cursor
      • Optional ev: EventTypes

      Returns void

valid: boolean = false
viewport: CanvasViewport

The internal viewport. Manages drawing

wlObject: Object3D

The object where the mesh will be added.

defaultCloneMaterial: true = true

Are materials cloned by default?

defaultCollisionGroupsMask: 2 = 2

Default collision groups, as a bitmask

defaultCollisionOverextensionPixels: 16 = 16

How many pixels to over-extend the collision extents by default.

defaultDestroyTextureWhenDisabled: false = false

Should the UI texture be destroyed by default when the root is disabled?

defaultMaxCanvasHeight: 2048 = 2048

Default maximum canvas (texture) height. Smaller than lazy-widget's default value because Wonderland engine has much stricter texture limits due to the texture atlas system.

defaultMaxCanvasWidth: 2048 = 2048

Default maximum canvas (texture) width. Smaller than lazy-widget's default value because Wonderland engine has much stricter texture limits due to the texture atlas system.

defaultOverextendCollisionOnCursorCapture: true = true

Should the collision extents only be over-extended when the cursor is being captured by default?

defaultPreventAtlasBleeding: true = true

Is texture bleeding from the texture atlas prevented by default?

defaultPreventBleeding: true = true

Is texture bleeding from old content prevented by default?

defaultRegisterKeyboardDriver: true = true

Are keyboard drivers auto-registered by default?

defaultRegisterPointerDriver: true = true

Are pointer drivers auto-registered by default?

defaultResolution: 1 = 1

The resolution of the canvas. For example, if 2, then the resolution of the canvas will be doubled. If 0.5, then the resolution of the canvas will be halved.

defaultUnitsPerPixel: 0.02 = 0.02

Default units-per-pixel

Accessors

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

    Returns HTMLCanvasElement

  • get child(): Widget
  • The root widget of this UI tree. Equivalent to getting Root#viewport.Viewport#child.

    Returns Widget

  • get currentTextInputHandler(): null | TextInputHandler
  • The text input handler that is currently in use. null if none in use.

    See Root#textInputHandler.

    Returns null | TextInputHandler

  • get maxCanvasHeight(): number
  • Returns number

  • set maxCanvasHeight(maxCanvasHeight): void
  • Parameters

    • maxCanvasHeight: number

    Returns void

  • get maxCanvasWidth(): number
  • Returns number

  • set maxCanvasWidth(maxCanvasWidth): void
  • Parameters

    • maxCanvasWidth: number

    Returns void

  • 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 preventBleeding(): boolean
  • Returns boolean

  • set preventBleeding(preventBleeding): void
  • Parameters

    • preventBleeding: boolean

    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

  • get pointerIDs(): Map<Cursor, number>
  • A Map mapping each cursor component to a PointerDriver's pointer ID.

    Returns Map<Cursor, number>

Methods

  • Parameters

    • uLeft: number
    • uRight: number
    • vTop: number
    • vBottom: number

    Returns void

  • Unregisters all Root#drivers from the root, by calling Root#unregisterDriver.

    Returns void

  • Clears the current focus of a given type. If there was a focus set, Root#drivers are notified by calling Driver#onFocusChanged.

    Parameters

    Returns void

  • Stop requesting a pointer style.

    Parameters

    • widget: Widget
    • Optional source: unknown

    Returns void

  • Stop requesting all pointer styles from a specific widget.

    Parameters

    Returns void

  • Destroy the texture used by this UI root, or do nothing if there is no texture created. The UI root will still be usable after calling this, as the texture is auto-created when needed.

    Use this if you want to save atlas space for a disabled UI root. If this is your use-case, and the UI root is not frequently toggled, consider using the WLRoot#destroyTextureWhenDisabled option.

    Returns void

  • Dispatches a WidgetEvent to this root's Root#child by calling Widget#dispatchEvent. Updates foci capturers and notifies Root#drivers by calling Driver#onFocusCapturerChanged if the capturer changes. Does nothing if root is disabled.

    Note that if an event with a focus is dispatched and no widget captures the event due to the widget not existing anymore or being disabled, the focus type of the event will be cleared in the root with Root#clearFocus.

    Dispatching a single event can result in a chain of dispatched events. These extra events will be returned.

    Parameters

    Returns CaptureList

    Returns a list of dispatched events and whether they were captured.

  • Clears all the foci that are set to a given Widget. Achieved by calling Root#dropFocus

    Parameters

    Returns void

  • Clears the current focus of a given type if it is currently set to a given widget. Achieved by calling Root#clearFocus.

    Parameters

    Returns void

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

    Parameters

    • id: string

      The ID to stop assigning

    Returns void

  • Gets the current focus of a given type.

    Parameters

    Returns null | Widget

  • Gets the last focus capturer of a given type.

    Parameters

    Returns null | Widget

  • Instantiate a text input handler. Used for mobile or WebXR where keyboard events are hard to get. Note that this will replace the current handler if there is any.

    Parameters

    Returns null | TextInputHandler

    If Root#textInputHandler is set, returns a new instance, otherwise, returns null.

  • Get the widget that an ID is assigned to. If no widget is assigned to a given ID, an error is thrown.

    Parameters

    • id: string

      The ID of the wanted Widget

    Returns Widget

  • 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

  • Remove an event listeners added with Root#on. Not chainable.

    Parameters

    Returns boolean

  • Remove an event listeners added with Root#onAny. Not chainable.

    Parameters

    Returns boolean

  • 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

    • Optional once: boolean

      Should the listener only be invoked once? False by default

    Returns WLRoot

  • 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 WLRoot

  • 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.

  • Do a post-layout update; calls Root#child's Widget#postLayoutUpdate. Does nothing if root is disabled.

    Call this before calling Root#paint and after calling Root#resolveLayout

    Returns void

  • Registers a Driver to the root, adding it to the Root#drivers list and calling Driver#onEnable. If the driver was already registered, nothing happens.

    Parameters

    Returns void

  • Sets the current focus of a given type to a given widget. If the focus changes, Root#clearFocus is called and Root#drivers are notified by calling Driver#onFocusChanged.

    If the target widget doesn't capture the dispatched FocusEvent, then the focus is not changed.

    Parameters

    Returns void

  • 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.

    Parameters

    • widget: Widget
    • pointerStyle: string
    • Optional source: unknown

    Returns void

  • Unregisters a Driver from the root, removing it from the Root#drivers list and calling Driver#onDisable. If the driver was not registered, nothing happens.

    Parameters

    Returns void

  • Do a full update of this root. Does a pre-layout update, resolves the layout, does a post-layout update and paints. Call this instead of the individual Root update methods.

    Returns void

  • Parameters

    • effOverextend: number
    • width: number
    • height: number

    Returns void

  • Get the pointer ID assigned to a given cursor component. If the cursor has no pointer ID assigned, a new pointer ID is registered to the PointerDriver.

    Parameters

    • cursor: Cursor

      The cursor component

    Returns number

  • 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

Generated using TypeDoc