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.

LWXGL provides seven built-in widget types identified by integer IDs. Each widget is created by a GCreate* function and rendered automatically each frame. Elements are stored in a global flat array indexed by the integer ID you supply — creating a new element at an already-occupied ID silently frees the old one first.

Text

void GCreateText(int id, int x, int y, int color, const char* text);
Renders a string at (x, y). color is a palette index in the range 0–15. text supports newlines (\n); each line is drawn 15 pixels below the previous one.
GCreateText(0, 10, 20, 15, "Score: 100");

Button

void GCreateButton(int id, int x, int y, int w, int h, int u, int hvr, int p, const char* label, void (*onclick)(void));
Renders a labeled, clickable button. The u, hvr, and p parameters are packed-nibble color values — the high nibble sets the border color and the low nibble sets the fill color — for the unpressed, hover, and pressed states respectively. onclick is invoked on left-button release while the cursor is inside the button.
void on_submit(void) { printf("Submitted\n"); }

GCreateButton(1, 100, 50, 120, 28, 0x70, 0x72, 0x07, "Submit", on_submit);
In the example above, 0x70 means palette color 7 (light gray) border and palette color 0 (black) fill in the normal state; 0x07 inverts them for the pressed state.

Input

void GCreateInput(int id, int x, int y, int w, int h, int u, int hvr, int max);
char* GGetInput(int id);
Creates a single-line text input box. Keyboard input is captured whenever the mouse cursor is inside the input box boundary. max is the maximum number of characters the user can type; the internal buffer is always 128 bytes. Pass w = -1 to have LWXGL automatically size the box to fit max characters. GGetInput returns a pointer to the internal character buffer — read it directly.
GCreateInput(2, 10, 80, 200, 24, 0x78, 0x70, 20);

// Later, read the typed text:
char* text = GGetInput(2);
printf("User typed: %s\n", text);

Checkbox

void GCreateCheckbox(int id, int x, int y, int size, int cb_col, int txt_col, const char* label);
int GGetCheckbox(int id);
Renders a square checkbox with an optional text label to its right. size controls the side length of the box in pixels. cb_col is a packed nibble (high = border color, low = fill color). txt_col is a plain palette index for the label text. GGetCheckbox returns 1 if the checkbox is currently checked, 0 otherwise.
GCreateCheckbox(3, 10, 110, 14, 0x77, 15, "Enable sound");

if (GGetCheckbox(3)) enable_sound();

Rect

void GCreateRect(int id, int x, int y, int w, int h, int fg, int bg);
Draws a filled rectangle. fg is the border color and bg is the fill color (both plain palette indices). Pass -1 for fg to omit the border, or -1 for bg to draw a border-only (hollow) rectangle.
GCreateRect(4, 0, 0, 640, 30, -1, 8); // Header bar — filled, no border

Console

void GCreateConsole(int id, int x, int y, int cols, int rows, int con_clr, int txt_clr);
void GConsolePrint(int id, const char* format, ...);
void GConsoleClear(int id);
Creates a scrollable text console. cols and rows are the console’s dimensions in characters — each character cell is 9 pixels wide and 15 pixels tall, so the resulting widget is (cols * 9 + 17) × (rows * 15 + 10) pixels in size. con_clr is a packed-nibble color for the console box (high = border, low = background). txt_clr is also packed; the high nibble sets the text foreground color, and the low nibble sets the background color of the scroll-position overlay that appears when the cursor is inside the console. GConsolePrint accepts printf-style format strings and appends the result to the console’s internal buffer. The view auto-scrolls to show the latest output when the scroll position was already at the bottom. Users can scroll with the mouse wheel, and pressing Space while the console is focused jumps back to the bottom.
GCreateConsole(5, 10, 150, 60, 10, 0x87, 15);
GConsolePrint(5, "Connected to server %s:%d\n", host, port);
To erase all content and reset the scroll position:
GConsoleClear(5);

Managing Elements

These utility functions apply to any element type regardless of which GCreate* call was used to create it.

Deleting an element

void GDeleteElement(int id);
Frees all memory associated with the element at id and sets the slot to NULL. Creating a new element at the same ID later is safe.

Showing and hiding

void GElemSetVisible(int id, int visible);
Pass 1 to show an element or 0 to hide it. Hidden elements are not rendered and do not receive input, but they remain allocated and their state is preserved.

Moving and resizing

void GElemModifyBounds(int id, int x, int y, int w, int h);
Updates the position and dimensions of an existing element without recreating it. For image canvas elements, the underlying pixel buffer is not resized — only the render position and clipping change.

Mouse hit test

int GElemInside(int id);
Returns 1 if the mouse cursor is currently inside the element’s bounding box and the element is visible on the active screen, 0 otherwise. For checkboxes, the hit area extends to include the label text.

Build docs developers (and LLMs) love