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.

All UI objects in LWXGL — text labels, buttons, input fields, image canvases, and more — are called elements. Every element is stored in a flat std::vector and addressed by an integer ID that you supply at creation time. Understanding how IDs and the element vector work is the foundation of building any LWXGL interface.

Element IDs

You choose the ID when calling any GCreate* function. IDs are zero-based integers. There are no string names or opaque handles — a plain int is all you need to reference, modify, hide, or delete any element. The element vector resizes automatically: if you create an element with ID 10 in a fresh application, the vector grows to 11 slots, with NULL in positions 0–9. Reusing an ID destroys the element previously at that slot before creating the new one, so you can safely reassign IDs without calling GDeleteElement first.
Element IDs do not need to be contiguous. You can create elements at IDs 0, 5, and 10 and the vector will simply have NULL slots at indices 1–4 and 6–9. The renderer skips NULL slots automatically, so sparse ID spaces have no correctness impact — only a small amount of unused vector memory.

Element Types

TypeInternal CodeCreate Function
Text label0GCreateText
Button1GCreateButton
Input field2GCreateInput
Rectangle3GCreateRect
Image canvas4GCreateImage
Checkbox5GCreateCheckbox
Console6GCreateConsole
The internal type code is stored in the Element struct and determines which renderer function is dispatched during GRenderWindow. You do not need to track the type code yourself — the API functions accept only the integer ID.

Visibility

void GElemSetVisible(int id, int visible);
  • GElemSetVisible(id, 1) — shows the element (default state at creation)
  • GElemSetVisible(id, 0) — hides the element
Hidden elements are not rendered and do not receive mouse events. The renderer checks the v (visible) flag on every element before calling its draw function, and hit-testing via _inside_elem also checks v, so a hidden button cannot be accidentally clicked.

Bounds Modification

void GElemModifyBounds(int id, int x, int y, int w, int h);
Repositions and resizes an element at runtime by updating its stored x, y, w, and h fields. The change takes effect on the next call to GRenderWindow. This is useful for:
  • Animations — move an element a few pixels per tick inside your on_every callback
  • Responsive layouts — reposition elements when a panel expands or collapses
  • Deferred placement — create elements off-screen (x = -9999) and slide them into view later

Hit-Testing

int GElemInside(int id);
Returns 1 if the current mouse cursor position falls within the element’s bounding rectangle, 0 otherwise. For checkboxes, the hit area is extended to include the label text (the label width in pixels is added to the right edge), matching the visual click target the user sees. GElemInside only returns 1 for visible elements; hidden elements always return 0.

Deleting Elements

void GDeleteElement(int id);
Frees all memory associated with the element at id and sets the vector slot to NULL. For image elements this also destroys the XImage and releases the pixel data buffers. GTerminateWindow calls GDeleteElement for every non-NULL slot in the vector during teardown, so you do not need to manually delete every element before exiting — but you can delete individual elements mid-session to free memory or recycle an ID.

Example: Creating, Hiding, and Deleting Elements

// Create a text label (ID 0) and a button (ID 1)
GCreateText(0, 10, 10, 15, "Status: OK");
GCreateButton(1, 10, 40, 100, 28, 0x70, 0x80, 0x90, "Hide", on_hide);

// Hide the text element — it disappears from screen and ignores mouse events
GElemSetVisible(0, 0);

// Later: permanently remove it and free its memory
GDeleteElement(0);

Build docs developers (and LLMs) love