Every visual component in LWXGL — text labels, buttons, input fields, images, checkboxes, consoles, shapes, and OpenGL surfaces — is a retained element. You create an element once, assign it an integer ID of your choosing, and the library keeps it alive and redraws it automatically each frame until you explicitly delete it. There is no need to issue draw calls every frame for retained elements; simply update their state and the renderer handles the rest.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.
Element IDs
IDs are arbitrary non-negative integers that you supply at element creation time. Internally, the element system uses astd::vector indexed by ID, so the vector grows to accommodate the largest ID you use. A few practical notes:
- IDs do not need to be contiguous. You can use IDs 0, 5, and 100 without any penalty other than the vector capacity growing to 101 entries.
- Once you call
DeleteElement(id), that slot is set toNULLand can be reused by creating a new element with the same ID. - It is your responsibility to avoid creating two elements with the same ID before deleting the first — doing so will silently overwrite the slot, leaking the previous element’s memory.
Element Types
LWXGL supports nine element types, each with a dedicated creation function:| Type ID | Name | Creation Function |
|---|---|---|
| 0 | Text | CreateText(id, x, y, text, color) |
| 1 | Button | CreateButton(id, x, y, w, h, u, hvr, p, label, onclick) |
| 2 | Input | CreateInput(id, x, y, w, h, u, hvr, max) |
| 3 | Rect | CreateRect(id, x, y, w, h, fg, bg) |
| 4 | Image | CreateImage(id, x, y, w, h) |
| 5 | Checkbox | CreateCheckbox(id, x, y, size, cb_col, txt_col, label) |
| 6 | Console | CreateConsole(id, x, y, cols, rows, con_clr, txt_clr) |
| 7 | Ellipse | CreateEllipse(id, x, y, w, h, fg, bg) |
| 8 | OpenGL | CreateOpenGL(id, x, y, w, h, border) |
u, hvr, p, fg, bg, color, etc.) all take a palette index (0–15) or CLR_NONE (-1) for no color. See the Color Palette page for details.
Element Bounds
Every element stores an(x, y, w, h) bounding rectangle. You can read these at creation time and modify them at any point during the window’s lifetime using ElemModifyBounds:
-1 for w or h to leave that dimension unchanged. Passing -1 for x or y sets the position to -1 literally, so always supply valid coordinates for position.
Visibility
Elements can be hidden and shown without being destroyed. This is useful for toggling panels, dialogs, or indicators without paying the cost of re-creation:Hit-Testing
ElemInside returns 1 if the mouse cursor currently lies within the element’s bounding box, or 0 otherwise. Call it inside your on_every callback or event handlers to implement custom hover logic:
(x, y, w, h) bounds, so it respects any modifications made with ElemModifyBounds.
Anchoring (Scroll Mode)
When scroll mode is active (enabled viaReserveScroll before CreateWindow), the virtual canvas is taller than the physical window. Use ElemAnchor to pin a set of elements so they stay fixed relative to the current scroll position, rather than scrolling with the canvas.
ElemAnchor takes a flag as its first argument: pass any non-zero value to anchor the elements (storing their current y positions), or pass 0 to un-anchor them:
ResolveAnchors() each frame (inside on_every) to recalculate the screen position of all anchored elements based on the current scroll offset:
ElemAnchor(0, ids, count) — this restores their y position to the value that was stored when they were anchored, and clears the anchor.
Deletion
DeleteElement(id) frees all memory owned by the element and sets its slot to NULL:
XImage, frees pixel data buffers, and frees the element’s Pixmap. All elements are automatically deleted by TerminateWindow.
Rendering Order
By default, theon_every callback runs before elements are drawn (ORDER_ELEM_SECOND), meaning retained elements appear on top of anything drawn with immediate-mode calls inside on_every.
Call SetRenderingOrder to swap the order:
libLWXGL.h as ORDER_ELEM_FIRST = 1 and ORDER_ELEM_SECOND = 0.