Skip to main content

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.

The UI element functions create and manage visible widgets rendered to the window. Each widget is assigned an integer ID by the caller — IDs are indices into a flat global element array. If an element already exists at a given ID, it is deleted and replaced before the new element is created.
Packed-nibble color encoding Many element creation functions accept packed-nibble color parameters. The high nibble (bits 7–4) is the border/outline color; the low nibble (bits 3–0) is the fill color. Example: 0x72 = border color 7 (Light Gray), fill color 2 (Dark Green).

Text

GCreateText

void GCreateText(int id, int x, int y, int color, const char* text);
Creates a text label element. Text is rendered using the X11 default font. Line height is 15 px; the baseline of the first line is placed at y + 11.
id
int
required
Element ID. If an element already exists at this ID it is deleted and replaced.
x
int
required
Left edge of the text in window pixels.
y
int
required
Top edge of the text in window pixels.
color
int
required
Palette index (0–15) for the text foreground color.
text
const char*
required
Null-terminated string to display. Embed \n to insert line breaks; each subsequent line is drawn 15 px below the previous one.
Example
GCreateText(0, 10, 10, 15, "Hello, world!\nSecond line.");

Button

GCreateButton

void GCreateButton(int id, int x, int y, int w, int h,
                   int u, int hvr, int p,
                   const char* label, void (*onclick)(void));
Creates a clickable button. The button has three visual states — unpressed, hovered, and pressed — each with its own packed-nibble color. The label is centered horizontally and vertically inside the button bounds. The onclick callback fires on a left-mouse-button release while the cursor is inside the button.
id
int
required
Element ID.
x
int
required
Left edge of the button.
y
int
required
Top edge of the button.
w
int
required
Width of the button in pixels.
h
int
required
Height of the button in pixels.
u
int
required
Packed-nibble color for the unpressed state. High nibble = border color, low nibble = fill color.
hvr
int
required
Packed-nibble color for the hover state (cursor inside, mouse button up).
p
int
required
Packed-nibble color for the pressed state (cursor inside, mouse button held).
label
const char*
required
Null-terminated string displayed centered on the button face.
onclick
void (*)(void)
required
Callback invoked on left-button release inside the button. Pass NULL for no callback.
Example
void on_click(void) { /* handle click */ }

// Dark border / light fill when idle; brighter on hover; inverted on press
GCreateButton(1, 100, 50, 120, 30, 0x87, 0x78, 0x70, "Click Me", on_click);

Input

GCreateInput

void GCreateInput(int id, int x, int y, int w, int h, int u, int hvr, int max);
Creates a single-line text input field. When the cursor is inside the element the field is considered active (focused) and a _ cursor character is appended to the displayed text. Key events are routed to the active input automatically. The internal buffer is 128 bytes.
id
int
required
Element ID.
x
int
required
Left edge of the input box.
y
int
required
Top edge of the input box.
w
int
required
Width in pixels. Pass -1 to auto-size: width is computed as (max + 1) * 9 + 10.
h
int
required
Height in pixels.
u
int
required
Packed-nibble color for the inactive state.
hvr
int
required
Packed-nibble color for the active (focused) state.
max
int
required
Maximum number of characters the user can type. The internal buffer is always 128 bytes regardless of this value.
Example
// Auto-sized input, max 20 characters
GCreateInput(2, 10, 60, -1, 24, 0x17, 0x1F, 20);

GGetInput

char* GGetInput(int id);
Returns a pointer to the input element’s internal 128-byte character buffer containing the current text. The buffer is null-terminated.
id
int
required
ID of an existing input element.
Returns: char* — pointer into the element’s internal buffer. Do not free this pointer. Example
char* value = GGetInput(2);
printf("User typed: %s\n", value);

Rect

GCreateRect

void GCreateRect(int id, int x, int y, int w, int h, int fg, int bg);
Creates a filled and/or bordered rectangle. Unlike the packed-nibble widgets, fg and bg here are plain palette indices. Either can be omitted by passing -1.
id
int
required
Element ID.
x
int
required
Left edge of the rectangle.
y
int
required
Top edge of the rectangle.
w
int
required
Width in pixels.
h
int
required
Height in pixels.
fg
int
required
Border color as a palette index. Pass -1 to draw no border.
bg
int
required
Fill color as a palette index. Pass -1 to draw no fill (transparent interior).
Example
// Solid white fill, no border
GCreateRect(3, 0, 0, 200, 100, -1, 15);

// Border only (color 4), transparent interior
GCreateRect(4, 10, 10, 80, 40, 4, -1);

Checkbox

GCreateCheckbox

void GCreateCheckbox(int id, int x, int y, int size,
                     int cb_col, int txt_col, const char* label);
Creates a checkbox widget consisting of a square box and an optional text label to its right. The box uses a packed-nibble color; the label uses a plain palette index. The checked state is toggled by clicking the element (detected via the element bounds, which extend to include the label width).
id
int
required
Element ID.
x
int
required
Left edge of the checkbox square.
y
int
required
Top edge of the checkbox square.
size
int
required
Width and height of the checkbox square in pixels.
cb_col
int
required
Packed-nibble color for the checkbox box. High nibble = border, low nibble = fill.
txt_col
int
required
Palette index for the label text color.
label
const char*
required
Null-terminated label string displayed 5 px to the right of the box. Pass NULL for no label.
Example
GCreateCheckbox(5, 20, 80, 14, 0x17, 15, "Enable feature");

GGetCheckbox

int GGetCheckbox(int id);
Returns the current checked state of a checkbox element.
id
int
required
ID of an existing checkbox element.
Returns: 1 if the checkbox is checked, 0 if unchecked. Example
if (GGetCheckbox(5)) {
    /* feature is enabled */
}

Console

GCreateConsole

void GCreateConsole(int id, int x, int y, int cols, int rows,
                    int con_clr, int txt_clr);
Creates a scrollable text console widget. The element’s pixel dimensions are derived from cols and rows: width = cols * 9 + 17, height = rows * 15 + 10. A scrollbar is drawn on the right edge; the thumb scales proportionally to the visible fraction of total content. When the mouse is inside the element, a hover overlay shows the current scroll position.
id
int
required
Element ID.
x
int
required
Left edge of the console box.
y
int
required
Top edge of the console box.
cols
int
required
Visible column count. Each column is 9 px wide. Lines longer than cols characters are soft-wrapped onto the next row.
rows
int
required
Visible row count. Each row is 15 px tall.
con_clr
int
required
Packed-nibble color for the console box. High nibble = border, low nibble = background fill.
txt_clr
int
required
Packed-nibble color for text rendering. The high nibble is the main text color. The low nibble is the text color used in the hover scroll overlay; it is also used as the scrollbar thumb color.
Example
// 60-column × 20-row console, dark background, light text
GCreateConsole(6, 10, 10, 60, 20, 0x10, 0xF0);

GConsolePrint

void GConsolePrint(int id, const char* format, ...);
Appends a formatted string to the console’s internal text buffer, printf-style. Tab characters (\t) are expanded to four spaces during rendering. Characters outside the printable range (ASCII 27–126) and outside \n are rendered as ?. If the console is already scrolled to the bottom before the print, the scroll position advances automatically to keep the new content in view.
id
int
required
ID of an existing console element.
format
const char*
required
printf-compatible format string.
...
variadic
Format arguments.
Example
GConsolePrint(6, "Frame %d: elapsed %.2f ms\n", frame, dt * 1000.0f);

GConsoleClear

void GConsoleClear(int id);
Clears all text content from the console buffer and resets the scroll position to the top.
id
int
required
ID of an existing console element.
Example
GConsoleClear(6);

Element Management

GDeleteElement

void GDeleteElement(int index);
Frees all memory associated with the element at index and sets the slot to NULL. For image elements this also destroys the underlying XImage. Calling this on a NULL slot or an out-of-range index is a no-op.
index
int
required
ID of the element to delete.
Example
GDeleteElement(3);

GElemModifyBounds

void GElemModifyBounds(int id, int x, int y, int w, int h);
Updates the position and size of an existing element in-place without recreating it or changing its type or data. Useful for repositioning or resizing elements dynamically.
id
int
required
ID of an existing element.
x
int
required
New left edge in window pixels.
y
int
required
New top edge in window pixels.
w
int
required
New width in pixels.
h
int
required
New height in pixels.
Example
// Move button to a new position after a layout change
GElemModifyBounds(1, 200, 100, 120, 30);

GElemSetVisible

void GElemSetVisible(int id, int visible);
Shows or hides an element. Hidden elements (visible = 0) are skipped during rendering and do not receive mouse or keyboard input. Visibility defaults to 1 on creation.
id
int
required
ID of an existing element.
visible
int
required
Pass 1 to show the element, 0 to hide it.
Example
GElemSetVisible(2, 0); // hide the input field
GElemSetVisible(2, 1); // show it again

GElemInside

int GElemInside(int id);
Returns whether the mouse cursor is currently within the element’s bounding rectangle. For checkbox elements the bounding rectangle is extended to encompass the label text. The function also checks that the element is visible and assigned to the currently active screen.
id
int
required
ID of an existing element.
Returns: 1 if the cursor is inside the element and the element is on the active screen, 0 otherwise. Example
if (GElemInside(3)) {
    /* show tooltip */
}

Build docs developers (and LLMs) love