Button

Extends: UiWidget

A focusable, clickable button: a label over a themed background. To handle clicks, either give it an actionId and a listener (its onUiAction(actionId, button) is called), set onActivate to a function(button as Button), or subclass and override onClick().

Properties

  • drawableText (BGE.DrawableText)
  • onActivate (function | dynamic) — Called from onClick() when set - function(button as Button) as void
  • actionId (string) — Passed to listener.onUiAction() on click, so one listener can tell its buttons apart.
  • value (dynamic) — Any extra data for the listener (e.g. a choice index).
  • listener (BGE.UI.UiActionListener) — Told about clicks: listener.onUiAction(actionId, button). Called after onActivate.
  • disabled (boolean) — A disabled button is drawn dimmed and can't be focused or clicked. Read-only: change it
  • focusSoundKey (string) — Optional Game.loadSound() key played via Game.playSound() when this button gains
  • clickSoundKey (string) — Optional Game.loadSound() key played via Game.playSound() when this button is

Constructor

new Button(game: BGE.Game): Button

Parameters


Instance Methods

setFont(font: roFont): void

Draws the text in this font, ignoring the theme's font.

Parameters

  • font (roFont)

Returns

  • void

setLabel(text: string): void

Sets this button's label text.

Parameters

  • text (string)

Returns

  • void

getLabel(): string

The label text.

Returns

  • string

labelFont(theme: BGE.UI.Theme): roFont

The font the label is drawn in: one set with setFont(), else theme's, else the default.

Parameters

  • theme (BGE.UI.Theme)

Returns

  • roFont

setDisabled(disabled: boolean): void

Enables or disables this button. If it's already in a container it's (un)registered for focus too; a re-enabled button goes back to its place among its siblings.

Parameters

  • disabled (boolean)

Returns

  • void

onFocus(): void

Returns

  • void

onClick(): void

Returns

  • void

draw(parent?: UiWidget): void

Parameters

  • parent (UiWidget, optional, default: "invalid")

Returns

  • void