A canvas-ui 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

Alias

module:WLRoot

Hierarchy

Constructors

  • Create a new WLRoot. Note that the properties object can also contain optional parameters for the canvas-ui Root constructor, and will be passed to it.

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

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

    Parameters

    • wlObject: Object

      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

_currentPointerStyle: string

The actual current pointer style.

For internal use only.

See Root#pointerStyle

_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

_mobileTextInUse: boolean

Is the mobile-friendly text input in use?

For internal use only.

See Root#hasMobileTextInput, Root#usingMobileTextInput and Root#getTextInput

collision: any = null
cursorTarget: null | CursorTargetComponent = null
downFunction: null | ((object: Object, cursor: CursorComponent) => void) = null
drivers: Set<Driver>

The list of drivers registered to this root

keydownEventListener: null | ((event: KeyboardEvent) => void) = null
keyupEventListener: null | ((event: KeyboardEvent) => void) = null
materialClone: Material
mesh: any = null
meshComponent: any
meshObject: any
moveFunction: null | ((object: Object, cursor: CursorComponent) => void) = null
oldTexSize: [number, number] = ...
pointerStyle: string

The pointer style this root wants. Will be set on Root#postLayoutUpdate by Root#pointerStyleHandler

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

textInputHandler: null | TextInputHandler

Handler for mobile-friendly text input. If not null, widgets that need text may call this to get a string.

See Root#hasMobileTextInput, Root#usingMobileTextInput and Root#getTextInput

texture: any = null
unHoverFunction: null | ((object: Object, cursor: CursorComponent) => void) = null
unitsPerPixel: number
upFunction: null | ((object: Object, cursor: CursorComponent) => void) = null
valid: boolean = false
viewport: CanvasViewport

The internal viewport. Manages drawing

Accessors

  • get canvas(): HTMLCanvasElement
  • The Root#viewport's CanvasViewport#canvas | canvas

    Returns HTMLCanvasElement

  • get canvasDimensions(): [number, number]
  • The Root#viewport's CanvasViewport#canvasDimensions | canvasDimensions

    Returns [number, number]

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

    Returns Widget

  • get constraints(): LayoutConstraints
  • The Root#viewport's Viewport#constraints | constraints

    Returns LayoutConstraints

  • set constraints(constraints: LayoutConstraints): void
  • Parameters

    Returns void

  • get dimensions(): [number, number]
  • The Root#child's Widget#dimensions | dimensions

    Returns [number, number]

  • get effectiveScale(): [scaleX: number, scaleY: number]
  • Get the scale used for the Root#viewport. The horizontal and/or vertical scale may not be 1 if Root#maxCanvasWidth or Root#maxCanvasHeight are exceeded.

    Note that this is only valid after resolving Root#child's layout.

    Equivalent to getting Viewport#effectiveScale on Root#viewport.

    Returns [scaleX: number, scaleY: number]

  • get enabled(): boolean
  • Is this root enabled? If not enabled, painting, updating or resolving layout will do nothing. Root#drivers | Drivers will also be notified by calling Driver#onEnable or Driver#onDisable, pointer style will be reset (Root#updatePointerStyle called with 'default') and all Root#_foci | foci will be cleared (Root#clearFocus).

    See Root#_enabled

    Returns boolean

  • set enabled(newEnabled: boolean): void
  • Parameters

    • newEnabled: boolean

    Returns void

  • get hasMobileTextInput(): boolean
  • Can Root#getTextInput be called? True if Root#textInputHandler is not null and Root#usingMobileTextInput is false.

    Returns boolean

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

    Returns number

  • set maxCanvasHeight(maxCanvasHeight: number): void
  • Parameters

    • maxCanvasHeight: number

    Returns void

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

    Returns number

  • set maxCanvasWidth(maxCanvasWidth: number): void
  • Parameters

    • maxCanvasWidth: number

    Returns void

  • get preventBleeding(): boolean
  • Shortcut for Root#viewport's CanvasViewport#preventBleeding property.

    Returns boolean

  • set preventBleeding(preventBleeding: boolean): 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: number): void
  • Parameters

    • resolution: number

    Returns void

  • get usingMobileTextInput(): boolean
  • Is Root#getTextInput in use?

    See Root#_mobileTextInUse.

    Returns boolean

  • get pointerDriver(): PointerDriver
  • The shared PointerDriver instance. Getter only. The PointerDriver will only be created when needed. Used for pointer (mouse & XR controller) input.

    Returns PointerDriver

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

    Returns Map<object, number>

Methods

  • Parameters

    • u: number
    • v: number

    Returns void

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

    Returns void

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

    Parameters

    Returns void

  • Dispatches an Event to this root's Root#child by calling Widget#dispatchEvent. Updates Root#_fociCapturers | 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.

    Returns

    Returns true if the event was captured

    Parameters

    Returns boolean

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

    Parameters

    Returns void

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

    Parameters

    Returns void

  • Gets the current Root#_foci | focus of a given type.

    Parameters

    Returns null | Widget

  • Gets the last Root#_fociCapturers | focus capturer of a given type.

    Parameters

    Returns null | Widget

  • Get text input from the user. Used for mobile where keyboard events are hard to get.

    Returns

    If this is already in use (Root#usingMobileTextInput), returns null, else, returns a string typed by the user.

    Parameters

    • Optional initialInput: string

    Returns Promise<null | string>

  • 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

    Returns whether the child was dirty or not. Use this to tell an external 3D library whether to update a mesh's texture or not.

    Returns boolean

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

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

    Returns void

  • Do a pre-layout update; calls Root#drivers' Driver#update and Root#child's Widget#preLayoutUpdate. Does nothing if root is disabled.

    Call this before 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 Root#_foci | 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.

    Parameters

    Returns void

  • Resolve the layout of this root. Does nothing if root is disabled.

    Calls Root#viewport's Viewport#resolveLayout with Root#child

    Call this before calling Root#postLayoutUpdate and after calling Root#preLayoutUpdate

    Returns

    Returns true if the viewport was resized or re-scaled

    Returns boolean

  • 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

  • Calls Root#pointerStyleHandler if the Root#pointerStyle has changed (checked by comparing with Root#_currentPointerStyle). Also updates Root#_currentPointerStyle. Can also be optionally supplied a new pointer style.

    Parameters

    • Optional newStyle: null | string

    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: object

      The cursor component

    Returns number

Generated using TypeDoc