Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Canvas

A widget that can contain other widgets at fixed coordinates. A Canvas has no size of its own, so you need to explicitly set the widget size in the UIElement and set UIElement.useWidgetSize to false when using it. Widget coordinates are in pixels, at default scale one pixel corresponds to 1 mm in the game world.
Usually you'll use a Canvas as the top widget in a UIElement or ScreenUIElement, but you can also use it as a child of other widgets. In particular, using a Canvas inside of a LayoutBox with an override size inside of a layout where widget size is automatic (for example in a VerticalBox) can be useful.

Hierarchy

Index

Methods

addChild

  • addChild(child: Widget, x: number, y: number, width: number, height: number): Canvas
  • Add a child widget to the canvas.

    Parameters

    • child: Widget

      The widget to add

    • x: number

      The X coordinate in pixels

    • y: number

      The Y coordinate in pixels

    • width: number

      Width of the widget on the canvas in pixels

    • height: number

      Height of the widget on the canvas in pixels

    Returns Canvas

getChildren

getOwningObject

getParent

  • getParent(): Widget | undefined
  • Return the widget that contains this widget, for example a border that wraps a check box. Returns undefined if this object has no parent.

    Returns Widget | undefined

isEnabled

  • isEnabled(): boolean

isVisible

  • isVisible(): boolean

removeChild

  • removeChild(child: Widget): void
  • Remove the given child from the canvas

    Parameters

    • child: Widget

      The widget to remove

    Returns void

setEnabled

  • setEnabled(enabled: boolean): this
  • Set whether the widget is enabled. When a widget is disabled, users can't interact with it and it is greyed out. When a widget that contains other widgets (like VerticalBox) is disabled, all its children behave as if disabled, too. By default, widgets are enabled.

    Parameters

    • enabled: boolean

      Whether to enable the widget.

    Returns this

setVisible

  • setVisible(visible: boolean): Widget
  • Set whether the widget is visible. When a widget that contains other widgets (like VerticalBox) is invisible, all its children are invisible, too. The layout of widgets is updated when visibility changes, and invisible widgets are treated as if they don't exist.

    Parameters

    • visible: boolean

      Whether the widget is visible.

    Returns Widget

updateChild

  • updateChild(child: Widget, x: number, y: number, width: number, height: number): void
  • Update coordinates of a child widget of the canvas. Will not do anything if called with a widget that is not a child of the canvas.

    Parameters

    • child: Widget

      The widget to add

    • x: number

      The X coordinate in pixels. Can be undefined to keep the current X coordinate.

    • y: number

      The Y coordinate in pixels. Can be undefined to keep the current Y coordinate.

    • width: number

      Width of the widget on the canvas in pixels. Can be undefined to keep the current width.

    • height: number

      Height of the widget on the canvas in pixels. Can be undefined to keep the current height.

    Returns void