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.

Every visible widget in LWXGL — text labels, buttons, inputs, rectangles, image canvases, checkboxes, and consoles — is an “element” stored in a flat vector indexed by an integer ID that you supply at creation time. The renderer iterates this vector each frame and draws each visible element that belongs to the currently active screen.

Element types

TypeCreation functionType integer
TextGCreateText0
ButtonGCreateButton1
InputGCreateInput2
RectGCreateRect3
ImageGCreateImage4
CheckboxGCreateCheckbox5
ConsoleGCreateConsole6

IDs are integers you manage

Every creation function takes an int id as its first argument. LWXGL stores the element at that index in the internal vector. If an element already exists at that ID, it is deleted first before the new one is stored — so IDs are naturally reusable. IDs are completely local to your application; LWXGL assigns no meaning to specific numbers. Using named constants or an enum makes code far easier to read and maintain:
#define ELEM_TITLE   0
#define ELEM_BTN_OK  1
#define ELEM_INPUT   2

GCreateText(ELEM_TITLE, 20, 10, 15, "Enter your name:");
GCreateInput(ELEM_INPUT, 20, 30, 200, 24, 0x07, 0x0F, 32);
GCreateButton(ELEM_BTN_OK, 20, 64, 80, 28, 0x70, 0x72, 0x07, "OK", on_submit);

Position and size

All elements have an (x, y) top-left position and, for most types, a (w, h) size, all expressed in pixels. These can be changed at any time with:
void GElemModifyBounds(int id, int x, int y, int w, int h);
The new bounds take effect on the next GRenderWindow call. This is the correct way to animate or reposition elements at runtime.

Visibility

void GElemSetVisible(int id, int visible);
Pass 1 to show an element and 0 to hide it. Hidden elements are neither rendered nor tested for mouse hit detection, so they are effectively inert until made visible again.

Hit testing

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

Deletion

void GDeleteElement(int id);
Frees all memory associated with the element at the given ID (including any XImage data for image canvases) and sets the slot in the vector to NULL. The ID is free to be reused immediately. Passing an out-of-range or already-NULL ID is a no-op.

Screen assignment

Each element belongs to a screen — an integer used to group elements into logical pages or tabs. Elements only render and receive input events when their screen value matches *GScreenActive(). Assign elements to a screen with:
void GScreenApply(int screen, int ids[], int count);
Read or write the currently active screen through the pointer returned by GScreenActive():
int* GScreenActive();
Setting an element’s screen to -1 makes it visible on all screens, regardless of the active screen value. This is useful for persistent UI chrome such as a navigation bar or a status line. The following pattern implements a simple two-page tab interface:
// Assign elements to screens
int page1_ids[] = {0, 1, 2};
GScreenApply(0, page1_ids, 3);

int page2_ids[] = {3, 4};
GScreenApply(1, page2_ids, 2);

// Switch to page 2
*GScreenActive() = 1;
All elements default to screen 0 when created, so a single-screen application requires no screen management at all.
The element vector grows dynamically as you create elements with higher IDs. IDs do not need to be contiguous — but large sparse gaps (e.g., using IDs 0 and 10000) will allocate all intervening NULL slots, wasting memory proportional to the gap. Keep IDs reasonably dense.

Build docs developers (and LLMs) love