BGE/UI

Alias: BGE.UI


Static Methods

loadBackgroundImage(path: string): dynamic

static

Loads an image at path for use as Theme.backgroundImage, picking between a stretchable BGE.UI.NinePatchImage and a plain BGE.UI.ImageBackground automatically: a path ending in ".9.png" (case-insensitive), Android's own naming convention for this asset format, loads as a 9-patch (see loadNinePatchImage()); any other path loads as a plain image, stretched to fill entirely with no unstretched corners. Returns invalid if the image at path could not be loaded.

Parameters

  • path (string) — a pkg:/ path to a background image, ".9.png"-suffixed for a 9-patch

Returns

  • dynamic

isNinePatchPath(path: string): boolean

static

Parameters

  • path (string)

Returns

  • boolean

createKeyboardCharRow( chars: string, indent?: float, ): BGE.UI.KeyboardRow

static

A row of 1-unit char keys, one per character of chars.

Parameters

  • chars (string)
  • indent (float, optional, default: "0.0") — in grid units

Returns

  • BGE.UI.KeyboardRow

createKeyboardPageKey( label: string, targetPage: integer, width: float, ): BGE.UI.KeyboardKey

static

A key that switches to another page.

Parameters

  • label (string)
  • targetPage (integer) — page index
  • width (float) — in grid units

Returns

  • BGE.UI.KeyboardKey

createKeyboardSpecialRow( pageKeys: Array.<BGE.UI.KeyboardKey>, spaceWidth: float, editKeyWidth: float, ): BGE.UI.KeyboardRow

static

A row of page keys, then Space, Del and Done.

Parameters

  • pageKeys (Array.<BGE.UI.KeyboardKey>)
  • spaceWidth (float) — in grid units
  • editKeyWidth (float) — width of Del and of Done, in grid units

Returns

  • BGE.UI.KeyboardRow

createKeyboardPage( charRows: Array.<string>, indents: Array.<float>, specialRow: BGE.UI.KeyboardRow, ): BGE.UI.KeyboardPage

static

A page of char rows followed by a special row.

Parameters

  • charRows (Array.<string>) — one string per row
  • indents (Array.<float>) — one indent per char row, in grid units
  • specialRow (BGE.UI.KeyboardRow)

Returns

  • BGE.UI.KeyboardPage

createAlphabeticalKeyboardLayout(): BGE.UI.KeyboardLayout

static

a-z in rows of 7, with an upper case page and a symbols page.

Returns

  • BGE.UI.KeyboardLayout

createQwertyKeyboardLayout(): BGE.UI.KeyboardLayout

static

QWERTY with staggered rows, an upper case page and a symbols page.

Returns

  • BGE.UI.KeyboardLayout

createCompactKeyboardLayout(): BGE.UI.KeyboardLayout

static

A-Z and 0-9 in rows of 9, then Del and Done - for short arcade-style entry.

Returns

  • BGE.UI.KeyboardLayout

loadNinePatchImage(path: string): BGE.UI.NinePatchImage

static

Loads a PNG authored in Android's .9.png convention (a 1px transparent border with black-opaque pixel runs marking the stretch region on the top row and left column) and returns a ready-to-use NinePatchImage with insets read from the image itself - see BGE.UI.NinePatchImage for the full format. If a border has no marker pixels at all, that axis defaults to a 0 inset (the whole image stretches on that axis) rather than throwing - a game developer authoring their own asset should notice this visually (unstretched corners look wrong), but a missing marker is not otherwise treated as an error. Returns invalid if the image at path could not be loaded.

Parameters

  • path (string) — a pkg:/ path to a .9.png-style PNG

Returns

  • BGE.UI.NinePatchImage

loadBitmapOrLog(path: string, description: string): roBitmap

static

Loads a roBitmap from a pkg:/ path, logging and returning invalid instead of throwing if it can't be loaded - shared by loadNinePatchImage() and BGE.UI.loadBackgroundImage() instead of each duplicating this guard.

Parameters

  • path (string) — a pkg:/ path to an image
  • description (string) — what kind of image this is, for the log message (e.g. "9-patch bitmap")

Returns

  • roBitmap

getNinePatchFallbackPath(path: string): string

static

Where loadBitmapOrLog() copies a .9.png image to load it on a device, which won't load a file with that suffix.

Parameters

  • path (string) — an image path

Returns

  • string — a tmp:/ path without the .9.png suffix, or "" if path doesn't end in .9.png

parseNinePatchBitmap(bitmap: roBitmap): BGE.UI.NinePatchImage

static

Same as loadNinePatchImage(), but takes an already-loaded roBitmap - split out specifically so this parsing logic is testable against a synthetic in-memory bitmap without needing a packaged asset file.

Parameters

  • bitmap (roBitmap)

Returns

  • BGE.UI.NinePatchImage

findMarkerRun(pixels: roByteArray, lengthPx: integer): object

static

Internal helper for parseNinePatchBitmap() - not part of the public API surface (BrighterScript has no visibility modifier for a namespaced function), so deliberately not written as a JSDoc doc comment.

Scans a 1-pixel-wide/tall RGBA byte array (4 bytes/pixel, lengthPx being the top row's width or the left column's height) for the first and last near-black, near-opaque pixel, treating index 0 and index (length-1) as the border corners (never part of a marker run - Android's convention reserves the very first/last border pixel unconditionally). Returns {startIndex, endIndex, found} in full-bitmap pixel coordinates (both inclusive); if no marker pixel was found, found is false and the run spans the entire content region ({startIndex: 1, endIndex: lengthPx - 2}) so the caller's left/top = startIndex - 1 and right/bottom = contentLength - (endIndex - 1) - 1 formulas both resolve to 0 on that axis (the whole image stretches). (A sentinel of startIndex = lengthPx would NOT resolve to 0 under those formulas - verified by hand against a synthetic no-marker test case - so this is deliberately not "no run found" encoded as an empty/inverted range.)

Parameters

  • pixels (roByteArray)
  • lengthPx (integer)

Returns

  • object

wrapText( text: string, font: roFont, maxWidth: float, ): Array.<string>

static

Splits text into lines no wider than maxWidth when drawn in font. Existing newlines are kept, words are split on spaces, and a single word wider than maxWidth is broken between characters. When wrapping, runs of spaces collapse to one and leading/trailing spaces are dropped.

Parameters

  • text (string)
  • font (roFont)
  • maxWidth (float) — in pixels. 0 or less means no wrapping (only split on newlines).

Returns

  • Array.<string> — the lines, without trailing spaces

wrapParagraph( paragraph: string, font: roFont, maxWidth: float, lines: Array.<string>, ): void

static

Wraps one newline-free paragraph and appends its lines to lines. Used by wrapText().

Parameters

  • paragraph (string) — text with no newlines
  • font (roFont)
  • maxWidth (float) — in pixels, greater than 0
  • lines (Array.<string>) — the wrapped lines are pushed onto the end of this array

Returns

  • void

Enums

BGE.UI.HorizAlignment

enumstaticreadonly

Properties

  • left (default: "left")
  • center (default: "center")
  • right (default: "right")

BGE.UI.VertAlignment

enumstaticreadonly

Properties

  • top (default: "top")
  • center (default: "center")
  • bottom (default: "bottom")

BGE.UI.FocusNavigationMode

enumstaticreadonly

How BGE.UI.FocusManager moves focus on directional input.

Properties

  • list (default: "list") — Default: discrete list navigation, like a typical menu - Up/Down/Left/ Right step currentlyFocused to the next/previous registered widget, no spatial cursor or hit-testing involved.
  • pointer (default: "pointer") — Opt-in: a virtual pixel cursor (cursorPosition) moves by cursorStep and is hit-tested against widget bounds each frame - see FocusManager.

BGE.UI.KeyboardKeyKind

enumstaticreadonly

What pressing a BGE.UI.KeyboardKey does.

Properties

  • char (default: "char") — Types the key's char.
  • space (default: "space") — Types a space.
  • backspace (default: "backspace") — Deletes the character before the caret.
  • done (default: "done") — Finishes typing.
  • page (default: "page") — Switches to the key's targetPage (e.g. Shift, "&123").

BGE.UI.SelectStyle

enumstaticreadonly

Select's interaction style. inline (default): Left/Right cycle the current option in place, matching Slider's interaction pattern. popup: OK expands a list of every option; Up/Down move a highlight, OK commits, back cancels. horizontal: every option renders side-by-side in one row, with the current selection visually distinct; Left/Right move directly to the adjacent shown option (clamping at the ends, no wrap - there's nothing to wrap to once every option is already on screen). See Select.style.

Properties

  • inline (default: "inline")
  • popup (default: "popup")
  • horizontal (default: "horizontal")

Other

NINE_PATCH_FILENAME_SUFFIX

staticreadonly

Filename suffix marking a 9-patch source asset, matching Android's own .9.png naming convention (see NinePatchLoader's own doc comment for the pixel-format side of that convention). Checked case-insensitively.

Default: .9.png

static

Extends: BGE.UI.UiWidget

A line of text centered on a dark band across the screen that fades in, holds and fades out - for "Boss defeated", level names and the like. show() it; it hides itself.

Add it to gameUi (it draws across the whole UI canvas, centerY of the way down), or call update() and drawOn() yourself.

Parameters

Properties

  • textColor (integer)
  • bandColor (integer) — The band's color at full opacity.
  • fontName (string) — Font key ("heading", falling back to "default").
  • fadeInSeconds (float)
  • fadeOutSeconds (float)
  • centerY (float) — The band's middle, as a fraction of the canvas height.
  • bandLines (float) — The band's height in text lines.

Returns

  • BGE.UI.Banner

Example

CODE
banner = new BGE.UI.Banner(game)
game.gameUi.addChild(banner)
banner.show("The Crypt", 3)

DISABLED_TEXT_TINT

staticreadonly

Tint for a disabled button's label: white at half alpha.

Default: 4294967168

Button

static

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().

Parameters

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

Returns

  • BGE.UI.Button

Checkbox

static

Extends: UiWidget

A focusable checkbox: a small toggle box plus a label. Set onChanged to a function(checkbox as Checkbox) to react to toggles.

Parameters

Properties

  • checked (boolean)
  • drawableText (BGE.DrawableText)
  • lastChangedValue (dynamic)
  • onChanged (function | dynamic) — Called from onClick() after checked flips - function(checkbox as Checkbox) as void

Returns

  • BGE.UI.Checkbox

ControllerQrWidget

static

Extends: BGE.UI.UiWidget

A QR code for the phone/browser controller page, with a caption and the URL under it. The URL defaults to game.getControllerConnectionInfo() (call game.enableControllerInput() first). It's encoded once; setUrl() changes it.

The code is centered in the widget's width with the text below; height is worked out from the content. qrSize is rounded down to whole pixels per module, or the modules show gaps.

Parameters

  • game (BGE.Game)
  • url (string, optional, default: "\"\"") — "" uses game.getControllerConnectionInfo()
  • qrSize (float, optional, default: "240.0") — pixels across the code

Properties

  • caption (string)
  • showUrl (boolean)
  • textColor (integer)
  • fontName (string) — Font key ("body", falling back to "default").
  • backgroundRGBA (integer) — Fill drawn behind everything, 0 for none.
  • contentPadding (float)
  • gap (float) — Space between the code and the text.

Returns

  • BGE.UI.ControllerQrWidget

Example

CODE
qr = new BGE.UI.ControllerQrWidget(game)
qr.customPosition = true
qr.customX = 100
qr.customY = 80
scene.addUi(qr)

CreditsEntry

static

One credits entry: its text and a style name. An empty text is a half-line gap.

Properties

  • text (string)
  • style (string) — "title", "heading", "body" (the default) or your own - see CreditsView.styleColors.

CreditsRow

static

One wrapped line, ready to draw.

Properties

  • text (string)
  • color (integer)
  • font (roFont)
  • height (float)

CreditsView

static

Extends: BGE.UI.UiWidget

Credits text: entries of {text, style}, wrapped to the view's width and coloured by style, either scrolling up ("scroll", the default) or laid out from the top ("static"). setFast() speeds a scroll up and skip() jumps to the end; isFinished() says when it's done (a static view is finished once skipped). Lines only draw inside the view.

The view fills the UI canvas's title-safe area unless you set customX/customY/ width/height. Colors per style are in styleColors, fonts in styleFonts (font keys; "body"/"default" when missing).

Parameters

  • game (BGE.Game)
  • entries (Array.<BGE.UI.CreditsEntry>, optional, default: "[]")

Properties

  • mode (string) — "scroll" or "static".
  • scrollSpeed (float) — Pixels per second.
  • fastScale (float) — Speed multiplier while setFast(true).
  • styleColors (roAssociativeArray) — Style name -> RGBA.
  • styleFonts (roAssociativeArray) — Style name -> font key.
  • headingGap (float) — Static mode: extra space above each heading after the first.
  • textAlign (string) — Lines are centered ("center") or left-aligned ("left").
  • backgroundRGBA (integer) — Fill drawn behind the text, 0 for none.

Returns

  • BGE.UI.CreditsView

Example

CODE
credits = new BGE.UI.CreditsView(game, [
{text: "My Game", style: "title"},
{text: "Code", style: "heading"},
{text: "Me"}
])
scene.addUi(credits)

CURSOR_ANALOG_DEADZONE

staticreadonly

Minimum analog-stick magnitude before updateAnalogCursor() moves the cursor at all. Local to the UI cursor, not applied in ControlMap - other axis consumers get the raw stick value.

Default: 0.15

FocusManager

static

Owns the single, global focused-widget/cursor state shared by every UiContainer that opts in (UiContainer.focusEnabled) - one Game instance owns one FocusManager (Game.focusManager). Widget positions are already absolute UI-canvas coordinates (each level of UiContainer.draw() adds its own parent's position - see UiWidget.getWorldPosition()), so one shared cursor/hit-test naturally spans nested containers with no translation.

Parameters

Properties

  • game (BGE.Game)
  • navigationMode (BGE.UI.FocusNavigationMode) — How directional input moves focus - see BGE.UI.FocusNavigationMode.
  • wrapFocus (boolean) — list mode only: does moving past the last (or first) registered widget
  • focusOrder (Array.<UiWidget>) — Every focusable widget registered across every focusEnabled container
  • currentlyFocusedIndex (integer) — list mode only: index of currentlyFocused within focusOrder, or -1
  • cursorPosition (BGE.Math.Vector) — pointer mode only: virtual cursor position, in UI-canvas coordinate
  • cursorStep (float) — pointer mode only: pixels the cursor moves per press/held-frame.
  • analogAxisName (dynamic) — Opt-in: name of a BGE.Controller.ControlMap axis (bound via
  • cursorAnalogSpeed (float) — Pixels/second the cursor moves at full stick deflection (magnitude 1.0).
  • currentlyFocused (BGE.UI.UiWidget)
  • hasSeededFocus (boolean)
  • consumedThisFrame (boolean) — Latched true as soon as anything consumes during a frame, and reset
  • repeatThrottle (BGE.UI.RepeatThrottle) — Throttles repeat-while-held navigation to one step per
  • analogListDirectionActive (boolean) — list mode only, analog stick navigation (see updateAnalogList()): was
  • analogListRepeatTimer (BGE.CountdownTimer) — list mode only: counts down analogListRepeatDelay between repeat steps
  • analogListSuppressed (boolean) — list mode only: set by focusWidget() so a direction already held then is ignored until released.
  • analogListRepeatDelay (float) — Seconds to hold the stick deflected before updateAnalogList() repeats a

Returns

  • BGE.UI.FocusManager

ImageBackground

static

A plain (non-9-patch) image background: the whole source image is stretched to fill the widget's bounds, corners included - unlike BGE.UI.NinePatchImage, which keeps its corners unstretched. Assign to Theme.backgroundImage the same as a NinePatchImage; see BGE.UI.loadBackgroundImage(), which picks this or a NinePatchImage automatically from the asset's filename.

Parameters

  • sourceImage (roBitmap) — the full source image, stretched to fill on draw()

Properties

  • sourceImage (roBitmap)
  • sourceWidth (integer)
  • sourceHeight (integer)

Returns

  • BGE.UI.ImageBackground

Keyboard

static

Extends: UiWidget

An on-screen keyboard for roScreen games (Roku's own keyboards are SceneGraph-only): the d-pad moves a highlighted key and OK presses it, typing into a TextInput. Show it with show(), or set TextInput.keyboard so OK on the input opens it.

While it's open: Back cancels and restores the text, Play (or the Done key) finishes, Replay deletes and Fast-forward types a space. Characters from the Roku mobile app's keyboard still reach the target. In pointer focus mode, moving the cursor onto a key highlights it.

Parameters

  • game (BGE.Game)
  • layout (BGE.UI.KeyboardLayout, optional, default: "invalid") — defaults to createAlphabeticalKeyboardLayout()

Properties

  • layout (BGE.UI.KeyboardLayout) — Keys and highlight - see createAlphabeticalKeyboardLayout(), createQwertyKeyboardLayout()
  • target (BGE.UI.TextInput) — The TextInput being typed into, set by show().
  • onDone (function | dynamic) — Called after Done hides the keyboard - sub(keyboard as BGE.UI.Keyboard)
  • onCancel (function | dynamic) — Called after Cancel restores the text and hides the keyboard - sub(keyboard as BGE.UI.Keyboard)
  • backgroundRGBA (integer) — Panel colour behind the keys.
  • keyGap (float) — Pixels between keys.
  • gridBuildCount (integer) — Test accessor: how many times the key grid has been baked.

Returns

  • BGE.UI.Keyboard

KeyboardKey

static

One key on a BGE.UI.Keyboard.

Parameters

  • label (string) — text drawn on the key
  • kind (BGE.UI.KeyboardKeyKind)
  • width (float, optional, default: "1.0") — width in grid units

Properties

  • label (string)
  • kind (BGE.UI.KeyboardKeyKind)
  • char (integer) — Character code a char or space key types.
  • width (float) — Width in grid units (a letter is 1).
  • targetPage (integer) — Page index a page key switches to.

Returns

  • BGE.UI.KeyboardKey

KeyboardRow

static

A row of keys, optionally indented (in grid units).

Properties

  • keys (Array.<BGE.UI.KeyboardKey>)
  • indent (float)

KeyboardPage

static

One page of a keyboard layout, top row first.

Properties

  • rows (Array.<BGE.UI.KeyboardRow>)

KeyboardLayout

static

Pages of keys plus the highlighted-key cursor for a BGE.UI.Keyboard. Build one with createAlphabeticalKeyboardLayout(), createQwertyKeyboardLayout() or createCompactKeyboardLayout(), or fill pages yourself.

Properties

  • id (integer) — Unique per layout, so a Keyboard can tell when its layout was replaced.
  • pages (Array.<BGE.UI.KeyboardPage>)
  • pageIndex (integer)
  • row (integer) — Highlighted key's row on the current page.
  • column (integer) — Highlighted key's index in its row.

Returns

  • BGE.UI.KeyboardLayout

Label

static

Extends: UiWidget

With customPosition, horizAlign lines the text up on customX, as Renderer.drawText() does: "center" centres it there and "right" ends it there. Each line of wrapped text is aligned the same way within the widest.

Parameters

Properties

  • drawableText (BGE.DrawableText)
  • wrapWidth (float) — Width in pixels to wrap the text at. 0 (the default) means no wrapping.

Returns

  • BGE.UI.Label
static

One item in a BGE.UI.MenuList.

Parameters

  • id (string)
  • label (string)
  • enabled (boolean, optional, default: true)
  • value (dynamic, optional, default: "invalid")

Properties

  • id (string) — Passed to the listener as the button's actionId.
  • label (string)
  • enabled (boolean) — A disabled item is shown dimmed and can't be focused or picked.
  • value (dynamic) — Copied to the button's value.
  • onActivate (function | dynamic) — Copied to the button's onActivate.

Returns

  • BGE.UI.MenuItem
static

Extends: BGE.UI.UiContainer

A panel holding an optional title, an optional wrapped message and a column of buttons, one per item. Picking an item calls listener.onUiAction(item.id, button).

The panel's children are built by open() and removed by close(), so its buttons are only focusable while it's open. open() focuses the first enabled item.

Colors come from the theme (panelBackgroundColor/panelBackgroundImage, panelTitleColor, panelTextColor, and the usual button colors); fonts from the "heading" and "body" fonts, falling back to "default". Set width/height to fix the size, or leave them 0 to fit the content. Override createButton() to use your own button class, or buildChildren() for a different layout.

Parameters

Properties

  • title (string) — Heading drawn above the message. "" = none.
  • message (string) — Body text, wrapped to the panel's inner width. "" = none. Use setMessage() once open.
  • listener (BGE.UI.UiActionListener) — Told about picks - see BGE.UI.UiActionListener. Set before open().
  • panelPadding (float) — Space between the panel's edge and its content.
  • sectionGap (float) — Space below the title and below the message.
  • itemHeight (float)
  • itemGap (float)
  • itemWidth (float) — Button width. 0 = the panel's inner width.
  • contentAlign (string) — Horizontal alignment of the title, message and buttons: "left" or "center".
  • minWidth (float) — Fitted width never goes below this or above maxWidth (0 = 60% of the UI canvas width).
  • maxWidth (float)
  • contentHeight (float) — Extra space below the message for content a subclass draws itself; contentTop is its y.
  • centered (boolean) — Center on the parent (or the UI canvas when the parent is gameUi) when opened, instead
  • items (Array.<BGE.UI.MenuItem>) — The items added with addItem(), in order.
  • buttons (Array.<BGE.UI.Button>) — One button per item, in the same order. Only filled while open.
  • contentTop (float)
  • titleLabel (BGE.UI.Label)
  • messageLabel (BGE.UI.Label)
  • fixedWidth (float)
  • fixedHeight (float)
  • ownerScene (BGE.GameScene)

Returns

  • BGE.UI.MenuList

Example

CODE
menu = new BGE.UI.MenuList(game)
menu.title = "Adventure"
menu.listener = m ' a scene with onUiAction(actionId, button)
menu.addItem("continue", "Continue", hasSave)
menu.addItem("new", "New Game")
menu.centered = true
menu.open() ' owned by the current scene, closed when it changes

MessagePanelButton

static

One button spec for MessagePanel: a label plus the same onActivate callback shape BGE.UI.Button itself uses (function(button as BGE.UI.Button) as void). Give it an actionId to report the click to the panel's listener instead.

Parameters

  • label (string)
  • onActivate (function | dynamic, optional, default: "invalid")
  • actionId (string, optional, default: "\"\"")

Properties

  • label (string)
  • onActivate (function | dynamic)
  • actionId (string)

Returns

  • BGE.UI.MessagePanelButton

MessagePanel

static

Extends: BGE.UI.MenuList

A centered modal panel (heading, message, a column of buttons) for pause menus, win/game-over screens and similar: a BGE.UI.MenuList that centers itself on show().

show() builds the panel's children fresh and focuses the first button; hide() removes the panel, so its buttons aren't focusable while it's hidden. Pass 0 for the width or height to fit the content. Colors come from the theme (panelBackgroundColor, panelTitleColor, panelTextColor), unless backgroundRGBA is set.

Parameters

  • game (BGE.Game)
  • panelWidth (float) — 0 fits the content
  • panelHeight (float) — 0 fits the content
  • buttons (Array.<BGE.UI.MessagePanelButton>) — shown top to bottom
  • title (string, optional, default: "\"\"") — optional heading, drawn in the "heading" font
  • message (string, optional, default: "\"\"") — optional body text below the heading

Properties

  • buttonSpecs (Array.<BGE.UI.MessagePanelButton>) — The button specs given to the constructor, top to bottom.
  • buttonWidgets (Array.<BGE.UI.Button>) — The BGE.UI.Button widgets built from buttonSpecs, in the same order - only valid

Returns

  • BGE.UI.MessagePanel

Meter

static

Extends: BGE.UI.UiWidget

A screen-space bar for health, stamina, boss health and the like: fills drawn on a backing, with optional extras.

  • Lag chunk: when the value drops, the lost part stays in lagColor for lagHoldSeconds, then drains away (lagEnabled).
  • Blink: the fill flashes blinkColor while empty (blinkWhenEmpty) or for a moment after refuse(), e.g. when an action needs more stamina than there is.
  • Layers: setLayer() adds more fills under the main one (e.g. a shield).
  • Label: text above the bar (e.g. a boss's name).

Add it to gameUi like any widget, or call drawAt() yourself from a draw hook (call update() each frame then).

Parameters

Properties

  • fillColor (integer)
  • backColor (integer)
  • borderSize (float) — Pixels of backing showing around the fill.
  • lagEnabled (boolean) — Every drop restarts the hold, so a value that drops steadily (stamina draining) builds
  • lagColor (integer)
  • lagHoldSeconds (float)
  • lagDrainPerSecond (float) — How fast the lag chunk drains, in fractions of the bar per second.
  • blinkWhenEmpty (boolean)
  • blinkColor (integer)
  • refuseSeconds (float) — Seconds refuse() blinks for.
  • blinkRate (float) — Blinks per second.
  • label (string) — Text above the bar. "" = none.
  • labelColor (integer)
  • labelFontName (string) — Font key for the label ("body", falling back to "default").
  • labelAlign (string) — "left" or "center".

Returns

  • BGE.UI.Meter

Example

CODE
health = new BGE.UI.Meter(game)
health.width = 400
health.height = 14
health.lagEnabled = true
scene.addUi(health)
' every frame:
health.setValue(player.health, player.maxHealth)

NinePatchSliceSpec

static

Describes one of a NinePatchImage's 9 slices: which segment of the source/destination grid it occupies along each axis. 0 = the fixed leading segment (the left/top inset), 1 = the stretchable middle segment, 2 = the fixed trailing segment (the right/bottom inset). Both slicing (in new()) and drawing (in draw()) are driven generically from this list instead of writing out 9 near-identical blocks by hand.

Properties

  • name (string)
  • gridX (integer)
  • gridY (integer)

NinePatchImage

static

A 9-patch ("scale-9") stretchable background image: a source bitmap is sliced once (at construction) into 9 roRegions - 4 corners (drawn at fixed size), 4 edges (stretched along one axis), and a center (stretched both axes) - so a single small source texture can back a background of any width/height without visibly stretching its corners. Assign to Theme.backgroundImage to opt a widget's background fill into this instead of a flat color - see Theme.backgroundImage's own doc comment.

Takes a roBitmap, not a roRegion: CreateObject("roRegion", ...) only accepts a roBitmap as its source, not another roRegion (confirmed via Roku's own component type data and an actual runtime Type Mismatch when a roRegion was tried) - so slicing has to start from the real bitmap.

Parameters

  • sourceBitmap (roBitmap) — the full source image
  • left (integer) — px from the left edge that stay unstretched
  • top (integer) — px from the top edge that stay unstretched
  • right (integer) — px from the right edge that stay unstretched
  • bottom (integer) — px from the bottom edge that stay unstretched

Properties

  • slices (object) — Slice name (see specs) -> roRegion, invalid if that slice's inset
  • specs (object) — The 9 slice specs, computed once in new() and reused by draw() every
  • left (integer)
  • top (integer)
  • right (integer)
  • bottom (integer)
  • sourceWidth (integer)
  • sourceHeight (integer)

Returns

  • BGE.UI.NinePatchImage

NINE_PATCH_MARKER_THRESHOLD

staticreadonly

RGBA byte threshold below which a channel is considered "black" - PNG export/compression can introduce minor color drift in marker pixels, so this isn't an exact &h000000FF match.

Default: 40

NINE_PATCH_MARKER_MIN_ALPHA

staticreadonly

Default: 200

Select

static

Extends: UiWidget

A focusable option picker. Its interaction style is controlled by Select.style (see BGE.UI.SelectStyle): inline (the default) cycles through m.options in place with Left/Right, matching Slider's existing interaction pattern; popup expands a full option list on OK; horizontal shows every option side-by-side in one row, with Left/Right moving directly between them.

Parameters

Properties

  • options (Array.<dynamic>)
  • selectedIndex (integer)
  • drawableText (BGE.DrawableText)
  • onChanged (function | dynamic) — Called after selectedIndex changes - function(select as Select) as void
  • lastChangedValue (dynamic) — Test accessor: last value an onChanged callback stashed here. Not part
  • style (BGE.UI.SelectStyle) — Which interaction style this Select uses - see BGE.UI.SelectStyle.
  • expanded (boolean) — popup style only: is the option list currently expanded?
  • highlightedIndex (integer) — popup style only: index within m.options currently highlighted while expanded.
  • lastDrawnRowCount (integer) — Test accessor: how many option rows drawOverlay() drew last call. Not
  • optionTextDrawables (object) — popup and horizontal styles only: one BGE.DrawableText per unique
  • repeatThrottle (BGE.UI.RepeatThrottle) — Throttles repeat-while-held Left/Right to one step per

Returns

  • BGE.UI.Select

Slider

static

Extends: UiWidget

A horizontal value picker: a label, a filled bar, and a numeric readout. Adjust with increase()/decrease() (step-sized) or set an exact value with setValue().

Parameters

Properties

  • minValue (float)
  • maxValue (float)
  • step (float)
  • value (float)
  • repeatThrottle (BGE.UI.RepeatThrottle) — Throttles repeat-while-held Left/Right to one step per
  • barColor (dynamic)
  • backgroundColor (dynamic)
  • drawableText (BGE.DrawableText)

Returns

  • BGE.UI.Slider

DEFAULT_PADDING

staticreadonly

Default: 32

WIDGET_REPEAT_DELAY_MS

staticreadonly

Minimum time (ms) a direction must be held before a Slider/Select repeats its adjustment. Game.bs dispatches a press AND a synthesized held event (heldTimeMs ~0) in the same frame as every button press, so without this threshold a single tap would step twice - see RepeatThrottle below.

Default: 300

RepeatThrottle

static

Throttles repeat-while-held directional input to one action per WIDGET_REPEAT_DELAY_MS, while letting a single tap's press+synthesized- held pair act exactly once. Shared by Slider/Select.handleInput() and BGE.UI.FocusManager's list/pointer navigation - anywhere directional input should act at most once per tap, then repeat while held.

Properties

  • lastActionMs (float) — heldTimeMs of the last held event acted on, or -1 when no hold is in

OffsetSize

static

Parameters

  • tOffset (float, optional, default: 0)
  • rOffset (dynamic, optional, default: "invalid")
  • bOffset (dynamic, optional, default: "invalid")
  • lOffset (dynamic, optional, default: "invalid")

Properties

  • top (float)
  • right (float)
  • bottom (float)
  • left (float)

Returns

  • BGE.UI.OffsetSize

TextButton

static

Extends: BGE.UI.Button

A button drawn as a line of text, with no background: a marker in front of it while focused, and a color for focused, normal and disabled. Good for text-style menus and dialogue choices (BGE.Story.DialogueView's "list" layout). It's still a Button, so focus, clicks, listener and setDisabled() work as usual - subclass and override draw() for your own look.

Parameters

Properties

  • marker (string) — Drawn before the label while focused; the label is always indented by its width.
  • textColor (integer)
  • focusedColor (integer)
  • disabledColor (integer)
  • font (roFont) — invalid = the "body" font, else "default".

Returns

  • BGE.UI.TextButton

TextInput

static

Extends: UiWidget

A focusable single-line text entry widget. Characters arrive via onECPKeyboard() (Roku's mobile-app keyboard sends individual characters this way), or from a BGE.UI.Keyboard on-screen keyboard - set keyboard so OK opens one. Left/Right (while focused) move the caret, a keyboard's Backspace deletes before it, and OK or a keyboard's Enter fires onSubmit.

Parameters

Properties

  • text (string) — Current text content.
  • cursorIndex (integer) — Caret position, 0..Len(text). Moved by Left/Right while focused, and
  • maxLength (integer) — Maximum text length, 0 = unlimited. A character typed once text.Len()
  • placeholder (string) — Text shown (dimmed) when text is empty and this widget isn't focused.
  • keyboard (BGE.UI.Keyboard) — Optional on-screen keyboard: when set, OK opens it (in this input's container) instead of
  • editing (boolean) — True while an on-screen keyboard types into this - draws the caret even when unfocused.
  • onChanged (function | dynamic) — Called after any edit (insert/delete) - function(input as TextInput) as void
  • onSubmit (function | dynamic) — Called on OK-press while focused - function(input as TextInput) as void
  • lastChangedValue (dynamic) — Test accessor: last value an onChanged callback stashed here. Not part
  • drawableText (BGE.DrawableText)
  • repeatThrottle (BGE.UI.RepeatThrottle) — Throttles repeat-while-held Left/Right to one step per

Returns

  • BGE.UI.TextInput

Theme

static

Default colors/fonts/spacing for BGE.UI widgets. Game.defaultTheme is the engine-wide default (matching today's previously-hardcoded widget colors, so existing consumers see no visual change); a UiContainer.theme overrides it for that container's subtree.

Resolution happens on every draw() call, not once at add-time: a widget resolves the theme from its immediate parent's effectiveTheme() (which itself falls back to Game.defaultTheme when that parent has no theme set), and any per-widget color field left invalid picks up the theme's value. There is no multi-level walk up the tree - only the immediate parent is consulted, so a grandparent container's own override does not reach a grandchild through an intervening container that has no theme of its own.

font, when set, is applied once to a widget's rendered text - see UiWidget.applyThemeFont(), called from every widget that owns a BGE.DrawableText (Button, Label, Checkbox, Slider, Select, TextInput) right after resolveTheme() in its own draw(). This is a one-time application per widget (not dynamic font-swapping): re-applying on every theme change would mean detecting whether font changed, which can't be done by comparing roFont instances (= on native components is a runtime crash in BrightScript, confirmed for roFont specifically - even a cast as object doesn't avoid it). fontSize is still accepted and stored but not applied - a roFont from Game.loadFont()/GetFont() already has its size baked in at load time, so this field is effectively vestigial.

Properties

  • backgroundColor (integer)
  • foregroundColor (integer)
  • borderColor (integer)
  • focusedBorderColor (integer)
  • hoveredBackgroundColor (integer) — Dark enough that the white foreground text stays readable on a focused/hovered widget.
  • disabledColor (integer)
  • font (roFont)
  • fontSize (integer)
  • defaultPadding (OffsetSize)
  • defaultMargin (OffsetSize)
  • cursorColor (integer)
  • cursorSize (float)
  • backgroundImage (BGE.UI.NinePatchImage | BGE.UI.ImageBackground) — A background image, drawn instead of a flat backgroundColor fill when
  • panelBackgroundColor (integer) — Panels (BGE.UI.MenuList, MessagePanel): background fill, title and message text.
  • panelTitleColor (integer)
  • panelTextColor (integer)
  • panelBackgroundImage (BGE.UI.NinePatchImage | BGE.UI.ImageBackground) — Drawn instead of panelBackgroundColor when set - a NinePatchImage or ImageBackground,

Returns

  • BGE.UI.Theme

UiActionListener

static

Anything a Button or MenuList reports clicks to: a scene, an entity, or a plain object. Set Button.listener (or MenuList.listener) to it, and give each button an actionId.

UiContainer

static

Extends: BGE.UI.UiWidget

Parameters

Properties

  • backgroundRGBA (integer)
  • showBackground (boolean) — RGBA value for the background of the window/container
  • children (Array.<UiWidget>)
  • theme (BGE.UI.Theme) — This container's own theme override. When invalid, effectiveTheme()
  • focusEnabled (boolean) — Does this container register its focusable children with the shared

Returns

  • BGE.UI.UiContainer

UiWidget

static

Extends: BGE.GameEntity

Base Abstract class for all UI Elements

Parameters

Properties

  • customPosition (boolean) — If position = "custom", then m.customX is horizontal position of this element from the parent position
  • customX (float)
  • customY (float)
  • horizAlign (string) — If customPosition is false, this dictates where horizontally in the container this element should go. Can be: "left", "center" or "right"
  • vertAlign (string) — as HorizAlignment = HorizAlignment.left
  • width (integer) — Width of the element
  • height (integer) — Height of the element
  • focusable (boolean) — Can this widget receive focus/hover from its owning UiContainer's cursor?
  • focused (boolean) — Does this widget currently have focus? Set by the owning UiContainer - do not set directly.
  • hovered (boolean) — Is the owning UiContainer's cursor currently over this widget? Set by the owning UiContainer.
  • parentContainer (UiWidget) — The UiContainer this widget was added to via addChild() - set by
  • canvas (BGE.Canvas)
  • padding (OffsetSize)
  • margin (OffsetSize)
  • hasAppliedThemeFont (boolean) — Latches true the first time this widget applies a resolved theme's

Returns

  • BGE.UI.UiWidget