Class UILayout

Base class for UI layout implementations. UI layouts serve as containers for UI elements that position and resize the elements automatically with respect to layout rules set on the elements.

Hierarchy (view full)

Constructors

Properties

Accessors

Methods

Events

Constructors

Accessors

  • get bounds(): Immutable<Rect2>
  • Sets the bounds of the UI element. Relative to a parent UI panel. Equivalent to calling setPosition(), setWidth() and setHeight().

    If scalable is set to true, the size will be scaled linearly with the DPI scaling factor of the surface the elements gets attached. It false, the element will have this exact size no matter the DPI scaling factor.

    Returns Immutable<Rect2>

  • set bounds(value): void
  • Parameters

    Returns void

  • get boundsInPixels(): Immutable<Rect2>
  • Gets or sets non-clipped bounds of the UI element in pixels. Relative to a parent UI panel.

    Returns Immutable<Rect2>

  • set boundsInPixels(value): void
  • Parameters

    Returns void

  • get childCount(): number
  • Returns number of child elements in the layout.

    Returns number

  • get clippedVisibleBounds(): Immutable<Rect2>
  • Returns the clipped bounds of the UI element including the margins. Relative to a parent UI panel.

    Returns Immutable<Rect2>

  • get clippedVisibleBoundsInPixels(): Immutable<Rect2>
  • Returns the clipped bounds of the UI element including the margins. Relative to a parent UI panel.

    Returns Immutable<Rect2>

  • get clippedVisibleScreenBounds(): Immutable<Rect2>
  • Returns the clipped bounds of the UI element including the margins. In Screenspace.

    Returns Immutable<Rect2>

  • get clippedVisibleScreenBoundsInPixels(): Immutable<Rect2>
  • Returns the clipped bounds of the UI element including the margins. In Screenspace.

    Returns Immutable<Rect2>

  • get debugName(): string
  • Sets the debug name for the UI element.

    Returns string

  • set debugName(value): void
  • Parameters

    • value: string

    Returns void

  • get disabled(): boolean
  • Disables or enables the element. Disabled elements cannot be interacted with and have a faded out appearance.

    Returns boolean

  • set disabled(value): void
  • Parameters

    • value: boolean

    Returns void

  • get displayType(): EnumValue<UIDisplayType, number>
  • Hides or shows this element and recursively applies the same state to all the child elements. This will not remove the element from the layout, the room for it will still be reserved but it just won't be visible.

    Returns EnumValue<UIDisplayType, number>

  • set displayType(value): void
  • Parameters

    Returns void

  • get dpiScale(): number
  • Gets the scaling factor for the element's parent surface. This element must be attached to a valid surface in order to retrieve the scale factor. If the element is not attached to a surface, 1.0 is returned.

    Returns number

    The scale factor for the element's parent surface.

  • get fixedHeight(): number
  • Sets the element size to be fixed using the specified value.

    Returns number

  • set fixedHeight(value): void
  • Parameters

    • value: number

    Returns void

  • set fixedHeightInPixels(value): void
  • Sets the element size to be fixed using the specified value in pixels.

    Parameters

    • value: number

    Returns void

  • get fixedWidth(): number
  • Sets the element size to be fixed using the specified value.

    Returns number

  • set fixedWidth(value): void
  • Parameters

    • value: number

    Returns void

  • set fixedWidthInPixels(value): void
  • Sets the element size to be fixed using the specified value in pixels.

    Parameters

    • value: number

    Returns void

  • get isDestroyed(): boolean
  • Checks if the underlying native UIElement has been destroyed.

    Returns boolean

  • get isLayoutBarrier(): boolean
  • Specifies that layout passes of children elements should start from this element.

    Returns boolean

  • set isLayoutBarrier(value): void
  • Parameters

    • value: boolean

    Returns void

  • get isUpdating(): boolean
  • Specifies that per-frame updates are enabled. If enabled, the element's onUpdate method will be called every frame.

    Returns boolean

    Per-frame updates are expensive and most UI elements should be built using a fully event-driven approach. Do not enable per-frame updates unless there is no event available that can be used to drive the required behavior.

  • set isUpdating(value): void
  • Parameters

    • value: boolean

    Returns void

  • get isVisible(): boolean
  • Activates or deactivates this element and recursively applies the same state to all the child elements. This has the same effect as SetDisplayType(UIDisplayType::Hidden), but when disabled it will also remove the element from the layout, essentially having the same effect is if you destroyed the element.

    Returns boolean

  • set isVisible(value): void
  • Parameters

    • value: boolean

    Returns void

  • get minimumHeight(): number
  • Sets the minimum height in points of the element when used in a layout.

    Returns number

  • set minimumHeight(value): void
  • Parameters

    • value: number

    Returns void

  • get minimumWidth(): number
  • Sets the minimum width in points of the element when used in a layout.

    Returns number

  • set minimumWidth(value): void
  • Parameters

    • value: number

    Returns void

  • get parent(): UIElementBase
  • Returns the layout this element belongs to, if any.

    Returns UIElementBase

  • get position(): Immutable<Vector2>
  • Sets element position relative to parent UI panel in points.

    Returns Immutable<Vector2>

    Be aware that this value will be ignored if UI element is part of a layout since then the layout controls its placement.

  • set position(value): void
  • Parameters

    Returns void

  • set positionInteger(value): void
  • Sets element position relative to parent UI panel in pixels.

    Parameters

    Returns void

    Be aware that this value will be ignored if UI element is part of a layout since then the layout controls its placement.

  • get readOnly(): boolean
  • Disables or enables the element. Disabled elements cannot be interacted with and have a faded out appearance.

    Returns boolean

  • set readOnly(value): void
  • Parameters

    • value: boolean

    Returns void

  • get screen(): Screen
  • Returns the screen on which the element is displayed, if any.

    Returns Screen

  • get screenBounds(): Immutable<Rect2>
  • Returns non-clipped bounds of the UI element in screenspace.

    Returns Immutable<Rect2>

    This call can be potentially expensive if the UI state is dirty.

  • get screenBoundsInPixels(): Immutable<Rect2>
  • Returns non-clipped bounds of the UI element in screenspace.

    Returns Immutable<Rect2>

    This call can be potentially expensive if the UI state is dirty.

  • get sizeHint(): Immutable<Size2>
  • Gets the size hint for this element.

    Returns Immutable<Size2>

    The size hint represents an approximation of the size. The actual size depends on the layouting that is done by the parent element. Layouts typically use the size hint to calculate the intial size of the element when distributing the available layout space.

  • get sizeHintInPixels(): Immutable<Vector2>
  • Gets the size hint for this element.

    Returns Immutable<Vector2>

    The size hint represents an approximation of the size. The actual size depends on the layouting that is done by the parent element. Layouts typically use the size hint to calculate the intial size of the element when distributing the available layout space.

  • get visibleBounds(): Immutable<Rect2>
  • Returns non-clipped visible bounds of the UI element (bounds exclude the margins). Relative to the parent UI panel.

    Returns Immutable<Rect2>

    This call can be potentially expensive as the bounds need to be calculated based on current UI state.

  • get visibleBoundsInPixels(): Immutable<Rect2>
  • Returns non-clipped visible bounds of the UI element (bounds exclude the margins). Relative to the parent UI panel.

    Returns Immutable<Rect2>

    This call can be potentially expensive as the bounds need to be calculated based on current UI state.

  • get window(): RenderWindow
  • Get the window in which the element is positioned.

    Returns RenderWindow

Methods

  • Adds a new element to the layout after all existing elements. param element The new element to add.

    Parameters

    Returns boolean

  • Adds a new flexible space as a child of this layout. Flexible space expands to fill all available space in the layout. Space is inserted after all existing elements.

    Returns UIFlexibleSpace

    Newly created flexible space.

  • Adds a new UIGridLayout as a child of this layout. Layout is inserted after all existing elements.

    Parameters

    • tileSize: Immutable<Size2>

      The size of the grid tiles.

    • isAutoResizing: boolean

      Determines if the grid layout resizes to fit the full width.

    • Rest...options: UIOption[]

      Options that allow you to control how is the layout positioned and sized.

    Returns UIGridLayout

    Newly created vertical layout.

  • Adds a new horizontal layout as a child of this layout. Layout is inserted after all existing elements.

    Parameters

    • Rest...options: UIOption[]

      Options that allow you to control how is the layout positioned and sized.

    Returns UIHorizontalLayout

    Newly created horizontal layout.

  • Add a new vertical separator. The horizontal separator is a line that can be used to visually separate elements in a layout.

    Returns UISeparator

    Newly created separator.

  • Adds a new UI panel as a child of this layout. Panel is inserted after all existing elements.

    Parameters

    • Rest...options: UIOption[]

      Options that allow you to control how is the panel positioned and sized.

    Returns UIPanel

    Newly created UI panel.

  • Adds a colored background panel to the layout.

    Parameters

    • color: Immutable<Color>

      The color.

    • Optionaldepth: number

      The panel depth, should be greater than 0 to be in the background. (Default: 10)

    • OptionalcornerRadius: number

      The optional corner radius.

    • OptionalborderColor: Immutable<Color>
    • OptionalborderWidth: number

    Returns UIPanel

  • Adds a new UI panel as a child of this layout. Panel is inserted after all existing elements.

    Parameters

    • depth: number

      Depth at which to position the panel. Panels with lower depth will be displayed in front of panels with higher depth. Provided depth is relative to the depth of the parent UI panel. The depth value will be clamped if outside of the depth range of the parent UI panel.

    • Rest...options: UIOption[]

      Options that allow you to control how is the panel positioned and sized.

    Returns UIPanel

    Newly created UI panel.

  • Adds a new UI panel as a child of this layout. Panel is inserted after all existing elements.

    Parameters

    • depth: number

      Depth at which to position the panel. Panels with lower depth will be displayed in front of panels with higher depth. Provided depth is relative to the depth of the parent UI panel. The depth value will be clamped if outside of the depth range of the parent UI panel.

    • depthRangeMin: number

      Smallest depth offset allowed by any child UI panels. If a child panel has a depth offset lower than this value it will be clamped.

    • depthRangeMax: number

      Largest depth offset allowed by any child UI panels. If a child panel has a depth offset higher than this value it will be clamped.

    • Rest...options: UIOption[]

      Options that allow you to control how is the panel positioned and sized.

    Returns UIPanel

    Newly created UI panel.

  • Adds a new fixed space object. Fixed space inserts a blank space with specific width or height (depending on layout type) in the layout. Space is inserted after all existing elements.

    Parameters

    • size: number

      Size of the space in pixels. This will represent either width or height depending whether the layout is vertical or horizontal.

    • Optionalscalable: boolean

      If this is true, this value will be scaled by the widget scaling factor.

    Returns UIFixedSpace

    Newly created fixed space.

  • Adds a new vertical layout as a child of this layout. Layout is inserted after all existing elements.

    Parameters

    • Rest...options: UIOption[]

      Options that allow you to control how is the layout positioned and sized.

    Returns UIVerticalLayout

    Newly created vertical layout.

  • Add a new vertical separator. The vertical separator is a line that can be used to visually separate elements in a layout.

    Returns UISeparator

    Newly created separator.

  • Creates an animation that executes an action lambda once the delay elapsed.

    Parameters

    • action: (() => void)

      The action to execute.

        • (): void
        • Returns void

    • Optionaldelay: number

      The delay until the action is executed. Defaults to no delay.

    • Optionalrepeating: number | boolean

      Whether the animation should repeat or not. Defaults to false. Set to true, to repeat forever. Set to false, to never repeat. Set to a number, to indicate the repeat count.

    Returns EditorAnimation

    The created animation.

  • Animates a property of the UIElement. The animation is automatically started.

    Type Parameters

    • T

      The type of property to be animated.

    Parameters

    • propertyName: string

      The name of the property to be animated on the UIElement.

    • starting: T

      The starting value of the property.

    • ending: T

      The ending value of the property.

    • Optionalduration: number

      The animation duration in seconds. Defaults to 1 seconds.

    • OptionaleasingCurve: Const<EasingCurve>

      The easing curve to be used. Defaults to

    • Optionalrepeating: number | boolean

      Whether the animation should repeat or not. Defaults to false. Set to true, to repeat forever. Set to false, to never repeat. Set to a number, to indicate the repeat count.

    Returns EditorAnimation

    The created animation.

    EasingCurve.inOutQuadratic.

  • Animates a property of the UIElement using a generic lambda function. The animation is automatically started.

    Type Parameters

    • T

    Parameters

    • setter: ((value: T) => void)

      The lambda that is called when the value is updated. The lambda should be used to assign the value on the u

        • (value): void
        • Parameters

          • value: T

          Returns void

    • starting: T

      The starting value of the property.

    • ending: T

      The ending value of the property.

    • Optionalduration: number

      The animation duration in seconds. Defaults to 1 seconds.

    • OptionaleasingCurve: Const<EasingCurve>

      The easing curve to be used. Defaults to

    • Optionalrepeating: number | boolean

      Whether the animation should repeat or not. Defaults to false. Set to true, to repeat forever. Set to false, to never repeat. Set to a number, to indicate the repeat count.

    Returns EditorAnimation

    The created animation.

    EasingCurve.inOutQuadratic.

  • Creates an animation that takes delay seconds to execute.

    Parameters

    • delay: number

      The delay in seconds.

    Returns EditorAnimation

    The created animation.

    This animation is usedful when creating compound animations that are chained together by calls to then. This is helpful to create an animation that performs an action, waits and performs another action.

  • Calculates the actual size of the layout, when it would be placed in the specified area.

    Parameters

    Returns Size2

    The actual size of the layout when placed in the area.

    This is an expensive method to call, and it's best to avoid it unless it's required. To respond to layout changes from the parent, use the OnLayoutSizeChanged event instead.

  • Calculates the actual size of the layout, when it would be placed in the specified area.

    Parameters

    Returns Size2

    The actual size of the layout when placed in the area.

    This is an expensive method to call, and it's best to avoid it unless it's required. To respond to layout changes from the parent, use the OnLayoutSizeChanged event instead.

  • Removes all child elements and destroys them.

    Returns void

  • Virtual

    Destroys this element and all its children. Removes the element from parent layout/panel.

    Returns void

    Calling methods on a destroyed element is a no-operation. Destroyed elements aren't allowed to be assigned as children of other elements, or be parents of other elements.

  • Updates the layout of the UI element. Updates child elements positions, sizes, clip rectangles and depths so they fit into the provided bounds, while respecting their layout options.

    Returns void

    This may trigger the layout of more than this element and it's children! It can potentially update the layout of the whole UI tree.

  • Returns non-clipped bounds of the UI element. Relative to a parent UI panel.

    Parameters

    • OptionalrelativeTo: UIElementBase

      Parent panel of the provided element relative to which to return the bounds. If null the bounds relative to the first parent panel are returned. Behavior is undefined if provided panel is not a parent of the element.

    Returns Rect2

    This call can be potentially expensive if the UI state is dirty.

  • Return the child element at the specified index.

    Parameters

    • index: number

      The index of the child element.

    Returns UIElementBase

  • Return the child element's index.

    Parameters

    Returns number

  • Inserts a UI element before the element at the specified index.

    Parameters

    • index: number

      The index where to insert the element.

    • element: UIElementBase

      The new element to insert.

    Returns boolean

  • Adds a new flexible space as a child of this layout. Flexible space expands to fill all available space in the layout. is inserted before the element at the specified index.

    Parameters

    • index: number

    Returns UIFlexibleSpace

    Newly created flexible space.

  • Adds a new horizontal layout as a child of this layout. Layout is inserted before the element at the specified index.

    Parameters

    • index: number

      Index to insert the layout at. This must be in range [0, GetNumChildren()).

    • Rest...options: UIOption[]

      Options that allow you to control how is the layout positioned and sized.

    Returns UIHorizontalLayout

    Newly created horizontal layout.

  • Adds a new UI panel as a child of this layout. Panel is inserted before the element at the specified index.

    Parameters

    • index: number

      Index to insert the panel at. This must be in range [0, GetNumChildren()).

    • Rest...options: UIOption[]

      Options that allow you to control how is the panel positioned and sized.

    Returns UIPanel

    Newly created UI panel.

  • Adds a new UI panel as a child of this layout. Panel is inserted before the element at the specified index.

    Parameters

    • index: number

      Index at which to insert the panel.

    • Optionaldepth: number

      Depth at which to position the panel. Panels with lower depth will be displayed in front of panels with higher depth. Provided depth is relative to the depth of the parent UI panel. The depth value will be clamped if outside of the depth range of the parent UI panel.

    • OptionaldepthRangeMin: number

      Smallest depth offset allowed by any child UI panels. If a child panel has a depth offset lower than this value it will be clamped.

    • OptionaldepthRangeMax: number

      Largest depth offset allowed by any child UI panels. If a child panel has a depth offset higher than this value it will be clamped.

    • Rest...options: UIOption[]

      Options that allow you to control how is the panel positioned and sized.

    Returns UIPanel

    Newly created UI panel.

  • Adds a new fixed space object. Fixed space inserts a blank space with specific width or height (depending on layout type) in the layout. Space is inserted after all existing elements.

    Parameters

    • index: number

      Index at which to insert the space.

    • size: number

      Size of the space in pixels. This will represent either width or height depending whether the layout is vertical or horizontal.

    Returns UIFixedSpace

    Newly created fixed space.

  • Adds a new vertical layout as a child of this layout. Layout is inserted before the element at the specified index.

    Parameters

    • index: number

      Index to insert the layout at. This must be in range [0, GetNumChildren()).

    • Rest...options: UIOption[]

      Options that allow you to control how is the layout positioned and sized.

    Returns UIVerticalLayout

    Newly created vertical layout.

  • Determines if the specified element is a child of this. If recursive is set, the method searches through the hierarchy to see if element is a nested child.

    Parameters

    Returns boolean

  • Virtual

    Called when the element has been added to a surface or window.

    Returns void

    This event allows to immediately access the layout data and bounds of the element and it's immediate parents and children. The event is helpful to perform initialization and registration to events. Implementing classes must call super.

  • Virtual

    Called when the element has been removed from a surface or window.

    Returns void

    Layout data and bounds will no longer be available at this point. The event is helpful to perform cleanup and unregistration from events. Implementing classes must call super.

  • Virtual

    Called when the element has been registered with its parent.

    Returns void

  • Virtual

    Called when the element is about to be unregistered from its parent.

    Returns void

  • Virtual

    Called when the element is updating.

    Returns void

    This is method is only called if the element has been marked as requiring updates.

    Per-frame updates are expensive and most UI elements should be built using a fully event-driven approach. Do not enable per-frame updates unless there is no event available that can be used to drive the required behavior.

  • Removes the specified element from the layout.

    Parameters

    Returns boolean

  • Removes a child element at the specified index.

    Parameters

    • idx: number

    Returns boolean

  • Virtual

    Resets element dimensions to their initial values dictated by the element's style.

    Returns void

  • Sets the bounds of the UI element. Relative to a parent UI panel. Equivalent to calling setPosition(), setWidth() and setHeight().

    If scalable is set to true, the size will be scaled linearly with the DPI scaling factor of the surface the elements gets attached. It false, the element will have this exact size no matter the DPI scaling factor.

    Parameters

    Returns void

  • Sets element height in pixels. Element will be resized according to its contents and parent layout but will always stay within the provided range. If maximum height is zero, the element is allowed to expand as much as it needs.

    If scalable is set to true, the minimum and maximum heights will be scaled linearly with the DPI scaling factor of the surface the elements gets attached. It false, the element will have this exact size no matter the DPI scaling factor.

    Parameters

    • OptionalminHeight: number
    • OptionalmaxHeight: number
    • Optionalscalable: boolean

    Returns void

  • Sets element width in pixels. Element will be resized according to its contents and parent layout but will always stay within the provided range. If maximum width is zero, the element is allowed to expand as much as it needs.

    If scalable is set to true, the minimum and maximum widths will be scaled linearly with the DPI scaling factor of the surface the elements gets attached. It false, the element will have this exact size no matter the DPI scaling factor.

    Parameters

    • OptionalminWidth: number
    • OptionalmaxWidth: number
    • Optionalscalable: boolean

    Returns void

  • Unregisters all running animations for the UIElement.

    Returns number

    The number of animations that were unregistered.

  • Scales a point value by using the element's DPI scale to the current pixel value.

    Parameters

    • valueInPoints: number

      The element to scale a value for. This element must be attached to a valid widget in order to retrieve the scale factor. If the element is not attached to a widget, no scaling is performed.

    Returns number

    The value in pixels.

  • Scales a point value by using the element's DPI scale to the current pixel value.

    Parameters

    • valueInPoints: Immutable<Vector2>

      The element used to get the DPI scaling factor.

    Returns Vector2

    Result value in pixels.

  • Converts a pixel value to points by using the element's DPI scale.

    Parameters

    • valueInPixels: number

      The element to scale a value for. This element must be attached to a valid widget in order to retrieve the scale factor. If the element is not attached to a widget, no scaling is performed.

    Returns number

    The value in points.

  • Scales a point value by using the element's DPI scale to the current point value.

    Parameters

    • valueInPixels: Immutable<Vector2>

      The element used to get the DPI scaling factor.

    Returns Vector2

    Result value in points.

  • Renders a UI element into a texture.

    Parameters

    • element: UIElementBase

      The UI element to be drawn to a texture.

    • skin: UISkin | ResourceHandle<UISkin>

      The UI skin to be used to render the element.

    • sizeInPixels: Immutable<Size2>

      The size of the UI texture to draw.

    • OptionalscalingFactor: number

      The DPI scaling factor of the RenderTarget. Can be used to linearly scale the entire UI, including text.

    • OptionalclearColor: Immutable<SRGBColor>

      The clear color. (Default: [0, 0, 0, 0])

    Returns AsyncOp<ResourceHandle<Texture>, void>

    An async operation that returns the rendered texture once rendering has been completed by the GPU.

    Calling this method will detach the given element from it's current parent.

Events

onLayoutSizeChanged: Event<[Immutable<Size2>, Immutable<Size2>], void>

Event fired whenever the UI element size changes from a layout update.

The old size of the UI element, in points.

The new size of the UI element, in points.

onRegistrationChanged: Event<[boolean], void>

Event fired whenever the UI element is registered with or unregistered from a parent element.

This does not mean that the element is currently visible on screen or that it is part of a layout. Use onActiveSurfaceChanged to determine if the element is part of a layout that is currently rendered.

True if the new state is registered in a parent element.

onActiveSurfaceChanged: Event<[boolean], void>

Event fired whenever the UI element is registered with or unregistered from a surface.

True if the new state is registered in a surface.