All UI objects in LWXGL — text labels, buttons, input fields, image canvases, and more — are called elements. Every element is stored in a flatDocumentation 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.
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 anyGCreate* 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
| Type | Internal Code | Create Function |
|---|---|---|
| Text label | 0 | GCreateText |
| Button | 1 | GCreateButton |
| Input field | 2 | GCreateInput |
| Rectangle | 3 | GCreateRect |
| Image canvas | 4 | GCreateImage |
| Checkbox | 5 | GCreateCheckbox |
| Console | 6 | GCreateConsole |
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
GElemSetVisible(id, 1)— shows the element (default state at creation)GElemSetVisible(id, 0)— hides the element
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
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_everycallback - 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
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
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.