LWXGL provides a set of retained-mode UI widgets that are each identified by an integer ID. You create a widget once, and the renderer draws it every frame until you delete it. All widget IDs are global — use unique integers across your entire application to avoid collisions. Widgets are rendered in the order they appear in the element list, and their positions are in back-buffer coordinates. This guide walks through every built-in widget type with real usage examples.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DRESsedAlarm184/LWXGL/llms.txt
Use this file to discover all available pages before exploring further.
Color Packing
Several widgets accept packed color integers where the low nibble (bits 0–3) is the fill color and the high nibble (bits 4–7) is the border or outline color. LWXGL defines 16 named palette constants you can combine:CLR_NONE (-1) wherever a fill or border should be skipped entirely (transparent).
The full palette:
| Constant | Index | Constant | Index |
|---|---|---|---|
CLR_BLACK | 0x0 | CLR_GRAY | 0x8 |
CLR_BLUE | 0x1 | CLR_LBLUE | 0x9 |
CLR_GREEN | 0x2 | CLR_LGREEN | 0xA |
CLR_CYAN | 0x3 | CLR_LCYAN | 0xB |
CLR_RED | 0x4 | CLR_LRED | 0xC |
CLR_MAGENTA | 0x5 | CLR_LMAGENTA | 0xD |
CLR_ORANGE | 0x6 | CLR_YELLOW | 0xE |
CLR_LGRAY | 0x7 | CLR_WHITE | 0xF |
Widget Types
Text — CreateText / CreateCopiedText
Text — CreateText / CreateCopiedText
Text elements render a single string at a fixed position. LWXGL offers two variants depending on who owns the string memory.
Signature
id— unique element IDx,y— top-left position in back-buffer coordinatestext— pointer to the string to displaycolor— palette index (0–15) for the text foreground
CreateText vs CreateCopiedText
CreateText stores the pointer you pass — it does not copy the string. The string must remain valid for the lifetime of the element. This is ideal for string literals or long-lived buffers.CreateCopiedText calls strdup internally and stores a heap copy. When DeleteElement is called the copied string is freed automatically (because the element’s copied flag is true). Use this when the source string is ephemeral (e.g. a local char[], a sprintf buffer, or a string you plan to free).Deleting text elements
Button — CreateButton
Button — CreateButton
Input Field — CreateInput / GetInput
Input Field — CreateInput / GetInput
Input elements are single-line text fields. They capture keyboard input when the mouse cursor is inside them and display a blinking cursor (
_) while focused.Signature
id— unique element IDx,y— top-left positionw— width in pixels; pass-1to auto-size:(max + 1) * 9 + 10h— height in pixelsu— packed color for the inactive state (low nibble = fill, high nibble = border)hvr— packed color for the hovered/active statemax— maximum number of characters; capped internally atmin(max, 127)GetInput(id)— returns a pointer to the 128-byte internalchar input[128]buffer; valid until the element is deleted
Auto-sizing width
Passingw = -1 sizes the field to hold exactly max characters in LWXGL’s 9px-wide font:Form example
GetInput returns the live internal buffer. Copy it with strncpy if you need to preserve the value after the user edits the field.Checkbox — CreateCheckbox / GetCheckbox
Checkbox — CreateCheckbox / GetCheckbox
Checkboxes render a square box next to an optional text label. Clicking the box (left-click) toggles the checked state.
Signature
id— unique element IDx,y— top-left position of the boxsize— pixel width and height of the box (always square;wandhare both set tosize)cb_col— packed color for the box: low nibble = fill, high nibble = bordertxt_col— palette index for the label textlabel— text displayed to the right of the box; may beNULLfor no labelGetCheckbox(id)— returns1if checked,0if unchecked
Hit area
The clickable region extends beyond the box itself. When a label is present the hit area includes the label text: the right edge isx + size + 10 + strlen(label) * 9. This means clicking on the label text also toggles the checkbox.Example
Rectangle — CreateRect
Rectangle — CreateRect
Rectangles are static colored boxes. They are useful as backgrounds, dividers, and decorative borders.
Signature
id— unique element IDx,y— top-left positionw,h— dimensionsfg— border color (palette index), orCLR_NONEto skip the borderbg— fill color (palette index), orCLR_NONEfor a transparent fill
Example
Ellipse — CreateEllipse
Ellipse — CreateEllipse
Ellipses (including circles) are rendered as filled and/or outlined arc shapes.
Signature
id— unique element IDx,y— top-left of the bounding boxw,h— width and height of the bounding box (equal values produce a circle)fg— outline color, orCLR_NONEbg— fill color, orCLR_NONE
ImmediateEllipse which uses XFillArc for the fill and XDrawArc for the outline.Example
Console — CreateConsole / ConsolePrint / ConsoleClear
Console — CreateConsole / ConsolePrint / ConsoleClear
The console widget is a scrollable, bordered text panel with a built-in scrollbar. It is ideal for log output, debug panels, and terminal-style displays. It auto-wraps text at
cols characters and scrolls vertically. Mouse-wheel scrolling is handled automatically when the cursor is inside the widget.Signature
id— unique element IDx,y— top-left positioncols— number of character columns (auto-sizes pixel width tocols * 9 + 17)rows— number of visible text rows (auto-sizes pixel height torows * 15 + 10)con_clr— packed background+border color: low nibble = console fill, high nibble = console border and scrollbar thumbtxt_clr— packed text color: high nibble = text color, low nibble = hover status overlay text colorConsolePrint— printf-style formatted output (usesvasprintfinternally) appended to the console buffer; auto-scrolls to the bottom if the view was already at the bottom when the print occurredConsoleClear— clears all text and resets scroll to zero
Live log panel example
Pressing Space while the cursor is inside a console element jumps instantly to the last line. Mouse-wheel scrolls 3 lines per tick.
Common Element Operations
These functions work on any element type and are identified by the same integer ID used at creation.ElemModifyBounds
Move or resize an element. Pass-1 for w or h to leave that dimension unchanged.
ElemSetVisible
Show or hide an element without deleting it.ElemInside
Returns1 if the mouse cursor is currently inside the element’s bounding box, 0 otherwise. Useful for hover effects in the frame callback.
DeleteElement
Frees all resources associated with an element. ForCreateCopiedText elements the heap string is freed. For image elements the pixmap and pixel buffers are freed.