Retained mode and DOM-style API to render interactive user-interfaces, with a Solid.js-inspired UI framework built on top.
It's recommended to either use the out-of-the-box UI framework (or build your own) instead of working with the retained mode API directly.
Retained mode has been chosen to significantly reduce the overhead of communicating between Lua and the engine for mostly static UIs.
Constants UI.SCREEN Root DOM element rendered to the screen in 2D. Shared by all screenspace UI, so you'll want to further restrict/abstract this if exposed to addons in your game.
Functions UI.createElement Creates a new containing element.
UI.createElement (): Element Returns Name Type Description element ElementNo description
UI.createTextElement Creates a new text element.
UI.createTextElement (textContent: string): TextElement Parameters Name Type Description textContent stringInitial text content of the element.
Returns Name Type Description element TextElementNo description
UI.createRichTextElement Creates a new rich text element designed for user input.
UI.createRichTextElement (): RichTextElement Returns Name Type Description element RichTextElementNo description
UI.getId Gets the unique ID for this element (can be used for equality).
UI.getId (element: Element | TextElement | RichTextElement): number Parameters Name Type Description element Element | TextElement | RichTextElementNo description
Returns Name Type Description id numberUnique ID for this element.
UI.isTextElement Returns whether the given parameter is a text UI element.
UI.isTextElement (value: any): boolean Parameters Name Type Description value anyThe value to check.
Returns Name Type Description isTextElement booleanWhether the value is a text element.
UI.isRichTextElement Returns whether the given parameter is a rich text UI element.
UI.isRichTextElement (value: any): boolean Parameters Name Type Description value anyThe value to check.
Returns Name Type Description isRichTextElement booleanWhether the value is a rich text element.
UI.removeElement Removes the element from its parent. No-op if the element has no parent.
UI.removeElement (child: Element | TextElement | RichTextElement) Parameters Name Type Description child Element | TextElement | RichTextElementNo description
UI.appendElement Appends an element to the end of another element's children.
Removes the child element from its current parent if it has one.
UI.appendElement (parent: Element, child: Element | TextElement | RichTextElement) Parameters Name Type Description parent ElementElement to append to. child Element | TextElement | RichTextElementElement to be appended.
UI.getChildren Returns a list of the element's children.
This is a copy, so will not update if the children of the element change
(nor will the element's children change if this list is modified).
UI.getChildren (element: Element): (Element | TextElement | RichTextElement)[] Parameters Name Type Description element ElementNo description
Returns Name Type Description children (Element | TextElement | RichTextElement)[]No description
UI.getElementName Returns the debug name of the element.
UI.getElementName (element: Element | RichTextElement): string Parameters Name Type Description element Element | RichTextElementNo description
Returns Name Type Description name stringNo description
UI.setElementName Sets the debug name of the element.
UI.setElementName (element: Element | RichTextElement, name: string) Parameters Name Type Description element Element | RichTextElementNo description name stringNo description
UI.getTextContent Returns the contents of a text element.
UI.getTextContent (element: TextElement | RichTextElement): string Parameters Name Type Description element TextElement | RichTextElementNo description
Returns Name Type Description textContent stringNo description
UI.setTextContent Updates the contents of a text element.
UI.setTextContent (element: TextElement, textContent: string) Parameters Name Type Description element TextElementNo description textContent stringNo description
UI.setStyle Sets a style on the element when in the specified state.
Styles are used in the order Clicked -> Hovered -> Always -> Engine Defaults.
The first state as per the order above which has a style set will be used.
UI.setStyle (element: Element | RichTextElement, style: UI.Style , value: boolean | number | string | Colour | UI.SizeMode | UI.ChildAlignment | UI.Direction | UI.TextWrapping | UI.TextAlignment | UI.Display | UI.Overflow , when: UI.StyleMode ) Parameters Name Type Description element Element | RichTextElementNo description style UI.StyleNo description value boolean | number | string | Colour | UI.SizeMode | UI.ChildAlignment | UI.Direction | UI.TextWrapping | UI.TextAlignment | UI.Display | UI.OverflowAccepted type depends on the style being set. when UI.StyleModeIn which state the style will be used.
UI.removeStyle Removes the style from the element when in the specified state.
Styles are used in the order Clicked -> Hovered -> Always -> Engine Defaults.
Removing a style from one of the layers means the first set style in a lower state (as above) will be used instead.
UI.removeStyle (element: Element, style: UI.Style , when: UI.StyleMode ) Parameters Name Type Description element ElementNo description style UI.StyleNo description when UI.StyleModeIn which state the style will be removed.
UI.createComponent Creates a component from the given function.
This sets up the component function as stateful and normalises its parameters.
UI.createComponent (componentFn: fun (props: table, children: fun (): (Element | TextElement)[]): function): fun (props?: table, children?: fun (): array): fun (): (Element | TextElement)[] Parameters Name Type Description componentFn fun(props: table, children: fun(): (Element | TextElement)[]): functionNo description
Returns Name Type Description component fun(props?: table, children?: fun(): array): fun(): (Element | TextElement)[]The normalised component function.
UI.render Resolves the component tree and appends all root nodes to the given element.
Should be called only once when initialising the UI.
UI.render (component: fun (props?: table, children?: ( fun (): (Element | TextElement)[])[]): fun (): (Element | TextElement)[], element: Element) Parameters Name Type Description component fun(props?: table, children?: (fun(): (Element | TextElement)[])[]): fun(): (Element | TextElement)[]Root component of the application. element ElementUI element to mount the components to.
UI.toString Stringifies the element and its children into a format resembling HTML/XML
Useful for debugging and snapshot testing.
UI.toString (element: Element | TextElement | RichTextElement, indent?: integer): string Parameters Name Type Description element Element | TextElement | RichTextElementNo description indent integer?Number of spaces to indent all lines by. Defaults to 0.
Returns Name Type Description elementMarkup stringNo description
UI.addEventListener Adds an event listener. A list of events can be found here .
UI.addEventListener (eventType: string, callback: function): function Parameters Name Type Description eventType stringThe event to listen for. callback functionThe callback to use.
Returns Name Type Description callback functionThe callback that was registered.
UI.removeEventListener Removes an event listener.
UI.removeEventListener (eventType: string, callback: function) Parameters Name Type Description eventType stringThe event to remove the listener from. callback functionThe callback to remove.
Functions - Debugging UI.enableDebugger Enables the Clay debugger.
UI.disableDebugger Disables the Clay debugger.
UI.isDebuggerEnabled Returns whether the Clay debugger is enabled.
UI.isDebuggerEnabled (): boolean Returns Name Type Description debuggerEnabled booleanNo description
Functions - Rich Text