A clickable button. Variants: default (panel surface), accent (primary action) and danger (destructive). Hover lightens, press dips; the click fires on press-started release (see UIComponent).

A button may show a label, a UIIcon, or both: assign icon (or build an icon-only button with UIButton.icon(...)). The icon may be a built-in glyph (UIIcon.fromGlyph) or an asset — that is up to the caller. The button colours the icon to match its label (contrast against the fill). A toolbar-style toggle is just accent flipped at runtime.

Static methods

staticicon(icon:UIIcon, size:Float, ?onClick:() ‑> Void):UIButton

Builds a square, icon-only button hosting a UIIcon (glyph- or asset-backed — the caller decides). A toolbar toggle is just accent flipped at runtime.

Parameters:

icon

the icon to show

size

the square edge length

onClick

fired on a completed click

Returns:

the configured button

Constructor

@:value({ accent : false })new(label:String, width:Float, height:Float, ?onClick:() ‑> Void, accent:Bool = false)

Parameters:

label

the button text (raw; use localize for translated labels)

width

layout width

height

layout height

onClick

fired on a completed click

accent

true renders the primary-action variant

Variables

@:value(false)accent:Bool = false

@:value(false)danger:Bool = false

@:value("")fallback:String = ""

@:value(13)fontSize:Int = 13

Base (unscaled) font size.

@:value(null)gradient:UIGradient = null

Optional gradient fill; overrides the variant fill when set. Hover/press still show as a scrim over it, and the label takes contrast from the first stop (fixed colours — see UIGradient).

@:value(null)key:String = null

label:String

Methods

localize(key:String, fallback:String):Void

Switches the label to a localized string.

Parameters:

key

the translation key

fallback

the source-language text

setIcon(icon:UIIcon):UIButton

Sets (or clears) the hosted icon. The icon may be glyph- or asset-backed; the button drives its colour to match the label (contrast against the button fill).

Parameters:

v

the icon to show, or null to remove it

Returns:

this button (for chaining)

Inherited Variables

Defined by UIComponent

@:value(true)enabled:Bool = true

Disabled widgets ignore the pointer and typically render dimmed.

@:value(0)read onlyh:Float = 0

Layout height in UI units.

@:value(MouseCursor.BUTTON)hoverCursor:MouseCursor = MouseCursor.BUTTON

Native cursor while hovering (interactive widgets; null keeps the arrow).

@:value(false)read onlyhovered:Bool = false

true while the cursor is over this widget.

@:value(false)longPressable:Bool = false

Opts a subclass that overrides onRightPress (without setting onRightClick) into long-press-as-right-click on touch. Widgets with onRightClick set are included automatically.

@:value(null)onClick:() ‑> Void = null

Fired on a completed click (press + release on this widget). Requires an interactive widget.

@:value(null)onHover:() ‑> Void = null

Fired when the cursor first enters this widget (hover-driven descriptions/previews). Interactive widgets only.

@:value(null)onRightClick:() ‑> Void = null

Fired on a right mouse press over this widget (context menus). Only interactive widgets receive pointer events, so this never fires on passive widgets like UILabel/UIPanel — attach it to a UIButton (or another interactive widget) instead. On touch, a long-press fires the same path (see UIRoot.longPressMs).

@:value(false)read onlypressed:Bool = false

true while a press that started here is held.

@:value(null)tooltip:String = null

Optional tooltip text (already-localized or a fixed string).

@:value(null)tooltipShortcut:String = null

Optional right-aligned shortcut hint rendered in the tooltip.

@:value(0)read onlyw:Float = 0

Layout width in UI units (independent of DisplayObject's content-derived width).

Inherited Methods

Defined by UIComponent

dispose():Void

Tears the widget down: listeners, pointer references, children, parent link.

invalidate():Void

Schedules a repaint for the next frame (cheap; deduplicated).

resize(width:Float, height:Float):Void

Sets the layout size and repaints when it changed.

Parameters:

width

the new layout width in UI units

height

the new layout height in UI units