ui - Windower/packages GitHub Wiki

The user interface library renders widgets over the game window using an immediate-mode GUI.

local ui = require('core.ui')

✔️ Dependency Not Required

This library does not require an explicit dependency in the manifest.xml file for your package.

Tables

The ui table has the following entries:

General Functions

  • ui.display : Registers a function with the immediate-mode GUI
  • ui.window : Renders a window widget that contains other widgets
  • ui.location : Sets the position of the next widget
  • ui.size : Sets the size of the next widget
  • ui.space : Inserts a blank space before the next widget
  • ui.indent : Indents the next widget
  • ui.unindent : Unindents the next widget

Widget Functions

Tables

  • ui.color : A collection of color-related helper functions and named color constants.
  • ui.draw : A collection of functions for drawing basic graphical primitives.

General Functions

ui.display

Registers a function containing user interface widgets and logic with the immediate-mode GUI handler.

Definition

function ui.display(fn : function)

Parameters

fn function

A function that contains UI widget calls and other supporting logic.

Note: Performance Considerations
All code included in this function is called every time a frame is rendered. Consider the performance impact and move logic that does not really need to run that frequently outside the ui.display function.

Return

This function does not return any values.



ui.window

Renders a graphical window that contains other widgets and is configured based on optional configuration parameters defined in the state table.

Definition

function ui.window(id : string, state : window_state, fn : function) : window_state, boolean

Parameters

id string

Unique string identifier for the window.

state window_state

A table containing the configuration state of the window.

fn function

The function that defines the UI widgets drawn within the window.

Note: Relative Positioning
Widgets created inside a window are positioned relative to the extents of the window, rather than relative to the entire game screen as with widgets created directly inside the ui.display function.

Return

state window_state

A table containing the configuration state of the window.

closed boolean

Specifies whether the window is closed.



ui.location

Explicitly specifies the position of the next widget to be rendered.

Note: Relative Positioning
For widgets defined inside the main ui.display function, the position set by this function is relative to the full game window. For widgets inside a window, the position is relative to the extents of the window.

Definition

function ui.location(x : number, y : number)

Parameters

x number

The x-coordinate position for the next widget.

y number

The y-coordinate position for the next widget.

Return

This function does not return any values.



ui.size

Specifies the dimensions of the next widget to be rendered.

Definition

function ui.size(width : number, height : number)

Parameters

width number

The width of the next widget, in pixels.

height number

The height of the next widget, in pixels.

Return

This function does not return any values.



ui.space

Inserts a blank space before the next widget to be rendered.

Definition

function ui.space()

Parameters

This function has no parameters.

Return

This function does not return any values.



ui.indent

Indents the next widget to be rendered.

Definition

function ui.indent()

Parameters

This function has no parameters.

Return

This function does not return any values.



ui.unindent

Unindents the next widget to be rendered.

Definition

function ui.unindent()

Parameters

This function has no parameters.

Return

This function does not return any values.



Widget Functions

ui.button

Renders a clickable button widget.

Definition

function ui.button(id : string, text : string, options : table = nil) : boolean

Parameters

id string

Unique identifier for the widget.

text string

Text label to write on the button.

options table [default: nil]

A table containing optional widget parameters:

checked boolean [default: false]
Specifies whether the button is pressed; used to create a toggle button.

enabled boolean [default: true]
Specifies whether the button is enabled and can be clicked.

Return

pressed boolean

Returns the state of the button: true for pressed, false for not pressed.



ui.check

Renders a three-state checkbox widget.

Definition

function ui.check(id : string, text : string, checked : boolean?, options : table = nil) : boolean

Parameters

id string

Unique identifier for the widget.

text string

The text label attached to the checkbox.

checked boolean

Specifies the current state of the checkbox:

  • true : The box is checked.
  • false : The box is unchecked.
  • nil : The box is indeterminate.

options table [default: nil]

A table containing optional widget parameters:

enabled boolean [default: true]
Specifies whether the checkbox is enabled and can be toggled.

Return

clicked boolean

Returns whether or not the checkbox has been clicked.



ui.color_picker

Renders a graphical color picker widget.

Definition

function ui.color_picker(id : string, color : color_value, options : table = nil) : color_value

Parameters

id string

Unique identifier for the widget.

color color_value

The integer value of the color currently selected in the color picker.

options table [default: nil]

A table containing optional widget parameters:

enabled boolean [default: true]
Specifies whether the color picker is enabled and can be manipulated.

Return

color color_value

The integer value of the color currently selected in the color picker.



ui.edit

Renders an interactive edit box widget.

Definition

function ui.edit(id : string, text : string, options : table = nil) : string

Parameters

id string

Unique identifier for the widget.

text string

The text currently entered in the edit box.

options table [default: nil]

A table containing optional widget parameters:

need to add missing edit params

enabled boolean [default: true]
Specifies whether the edit box is enabled and can be interacted with.

Return

text string

The text currently entered in the edit box.



ui.image

Renders an image from a source file.

Definition

function ui.image(path : string, options : table = nil)

Parameters

path string

The absolute path to the source image file.

options table [default: nil]

A table containing optional widget parameters:

color color_value [default: ui.color.white]
The color to overlay on the rendered image.

Return

This function does not return any values.



ui.progress

Renders a progress bar widget.

Definition

function ui.progress(value : number, options : table = nil)

Parameters

value number

Fractional number representing the percentage of the progress bar that is filled.

options table [default: nil]

A table containing optional widget parameters:

color color_value [default: ui.color.accent]
The color used to fill the progress bar.

Return

This function does not return any values.



ui.radio

Renders a radio button widget.

Definition

function ui.radio(id : string, text : string, checked : boolean, options : table = nil) : boolean

Parameters

id string

Unique identifier for the widget.

text string

The text label attached to the radio button.

checked boolean

Specifies the current state of the radio button:

  • true : The radio button is selected.
  • false : The radio button is not selected.

options table [default: nil]

A table containing optional widget parameters:

enabled boolean [default: true]
Specifies whether the radio button is enabled and can be toggled.

Return

checked boolean

The current state of the radio button:

  • true : The radio button is selected.
  • false : The radio button is not selected.



ui.slider

Renders an interactive slider widget.

Definition

function ui.slider(id : string, value : number, options : table = nil) : number

Parameters

id string

Unique identifier for the widget.

value number

The current value specified by the position of the slider.

options table [default: nil]

A table containing optional widget parameters:

min number [default: 0]
The minimum value for the slider.

max number [default: 1]
The maximum value for the slider.

color color_value [default: ui.color.accent]
The integer value of the color used to fill the slider.

enabled boolean [default: true]
Specifies whether the radio button is enabled and can be toggled.

Return

value number

The current value specified by the position of the slider.



ui.text

Renders a widget containing optionally-formatted text.

Definition

function ui.text(text : string, options : table = nil)

Parameters

text string

The string of text to render in the widget. The string may include basic Markdown formatting and formatting strings.

options table [default: nil]

A table containing optional widget parameters:

color color_value [default: ui.color.white]
The integer value of the color for the text.

Return

This function does not return any values.

⚠️ **GitHub.com Fallback** ⚠️