Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ImageButton

A UI button displaying an image.

Hierarchy

Index

Properties

onClicked

onClicked: MulticastDelegate<(button: this, player: Player) => void>

Called when the button is clicked.

param

The button that was clicked

param

The player who clicked the button

onImageLoaded

onImageLoaded: MulticastDelegate<(UImage: this, filename: string, packageId: string) => void>

Called when an image set by setImage or setImageURL is done loading. This will be within the call if the image is already cached, or some time later if the image has to be loaded first. Not called if the image can't be loaded. Note that if you call set the image before setting this callback, it might not get called because the image has been loaded instantly if it was cached.

Methods

getImageFileHeight

  • getImageFileHeight(): number
  • Get the height of the displayed image file. Does not have to be identical to the desired height of the image, use getImageHeight for that. Returns 0 if no image has been set or it hasn't been loaded yet. Wait for onImageLoaded before using this method to ensure that the size from the loaded file is available.

    Returns number

getImageFileWidth

  • getImageFileWidth(): number
  • Get the width of the displayed image file. Does not have to be identical to the desired width of the image, use getImageWidth for that. Returns 0 if no image has been set or it hasn't been loaded yet. Wait for onImageLoaded before using this method to ensure that the size from the loaded file is available.

    Returns number

getImageHeight

  • getImageHeight(): number

getImageWidth

  • getImageWidth(): number

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

getTintColor

isEnabled

  • isEnabled(): boolean

isVisible

  • isVisible(): boolean

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

setImage

  • setImage(textureName: string, packageId?: string): ImageButton
  • Set the displayed image file. When an image is used for the first time, it is loaded in the background and won't be visible immediately. onImageLoaded is called when the image is loaded.

    Parameters

    • textureName: string

      The filename of the image to load

    • Optional packageId: string

      The id of the package that contains the image file (in the Textures folder). Can usually be empty when used from scripts to use the same package that contains the script file, but you need to explicitly pass refPackageId for the current package or a package id when you use it in a callback. You can find package ids in the manifest.json file in package folders. Usually you won't use this parameter, unless you have a specific reason to load an image from a different package than where the script is located.

    Returns ImageButton

setImageSize

  • setImageSize(width?: number, height?: number): ImageButton
  • Set the desired size of the image. If both axes are set to 0, the size will be the actual size of the image file. If only one axis is set to 0, it will be set to a value that preserves the aspect ratio of the image, and the other value above 0 will be fixed. Desired size can get overridden by the widget size on a Canvas or the size of the UIElement when the image is the only widget and UIElement.useWidgetSize is false. The button has two pixels of padding around the image on all sides, so the total size of the button will be four pixels larger on each axis.

    Parameters

    • Optional width: number

      Desired width of the image. Default: 0

    • Optional height: number

      Desired height of the image. Default: 0

    Returns ImageButton

setImageURL

  • Set the displayed image file from a URL

    Parameters

    • url: string

      The filename of the image to load

    Returns ImageButton

setSourceCard

  • Set the displayed image based on a card. The image file width will always be 128, the file height is calculated based on the aspect ratio of the card. Note that if the card is deleted or becomes part of another stack, the image widget will become empty when it is reloaded, for example because the containing UI is changed or for a new player who joins.

    Parameters

    • sourceCard: Card

      The card that should be displayed on the widget.

    Returns ImageButton

setTintColor

  • setTintColor(color: Color | [r: number, g: number, b: number, a: number]): ImageButton
  • Set the tint color of the image. Default: White

    Parameters

    • color: Color | [r: number, g: number, b: number, a: number]

    Returns ImageButton

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