Elements are the building blocks of an LWXGL scene. Every visible widget — text, buttons, input fields, rectangles, image canvases, and checkboxes — is stored internally as anDocumentation 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 struct keyed by an integer ID. IDs are chosen by the caller and must be unique integers ≥ 0. Creating an element at an ID that already holds another element automatically deletes the old one first. The internal element list is a std::vector that grows on demand, so IDs do not need to be contiguous.
| Type Index | Element Kind | Created By |
|---|---|---|
| 0 | Text label | GCreateText |
| 1 | Button | GCreateButton |
| 2 | Text input | GCreateInput |
| 3 | Rectangle | GCreateRect |
| 4 | Image canvas | GCreateImage |
| 5 | Checkbox | GCreateCheckbox |
GCreateText
9x15 bitmap font. The text pointer is stored directly — do not free or mutate the string while the element is alive.
Unique element ID. If an element already occupies this ID it is deleted first.
Left edge of the text in window coordinates (pixels from left).
Top edge of the text baseline in window coordinates. The first character baseline is drawn at
y + 11; subsequent lines are 16 pixels apart.Palette index (0–15) for the text foreground color.
Null-terminated string to display. Newlines (
\n) are supported; each line is drawn on a separate baseline. Font metrics are 9 pixels wide × 15 pixels tall per character.GCreateButton
int where the high nibble is the border color palette index and the low nibble is the fill color palette index.
Unique element ID.
Left edge of the button in window coordinates.
Top edge of the button in window coordinates.
Width of the button in pixels.
Height of the button in pixels.
Packed color byte for the unpressed state. High nibble = border palette index, low nibble = fill palette index. Example:
0x7F → border index 7 (Light Gray), fill index 15 (White).Packed color byte for the hover state (cursor inside bounds). Same encoding as
u.Packed color byte for the pressed state (left mouse button held inside bounds). Same encoding as
u.Text drawn centered inside the button using the border color of the current state.
Called when the left mouse button is released inside the button bounds. Only fires for button
1 (left click); right/middle clicks are ignored. Not called when a modal is open. May be NULL.GCreateInput
max characters.
Unique element ID.
Left edge in window coordinates.
Top edge in window coordinates.
Width in pixels. Pass
-1 to auto-size to (max + 1) * 9 + 10 pixels, which gives enough room to display max characters in the 9-pixel-wide font plus a small margin.Height in pixels.
Packed color byte for the inactive state. High nibble = border palette index, low nibble = fill palette index.
Packed color byte for the active/hovered state. Same encoding as
u. A blinking underscore cursor is appended to the text when the field is hovered.Maximum number of characters the user may type. Capped internally at 127 due to the fixed 128-byte buffer (one byte reserved for the null terminator).
GGetInput
ID of an existing input element.
GCreateRect
Unique element ID.
Left edge in window coordinates.
Top edge in window coordinates.
Width in pixels.
Height in pixels.
Palette index for the outline (border). Pass
-1 to skip drawing the outline entirely.Palette index for the fill. Pass
-1 to skip filling (transparent interior).GCreateImage
XImage and a palette-indexed pixel buffer. Each pixel is one byte (palette index 0–15). A second shadow buffer of the same size is allocated for diffing so that GUpdateImage only writes pixels that have actually changed.
Unique element ID.
Left edge of the canvas in window coordinates.
Top edge of the canvas in window coordinates.
Canvas width in pixels.
Canvas height in pixels.
GGetImageData
w × h bytes stored in row-major order. Each byte is a palette index (0–15). You write palette indices directly into this buffer, then call GUpdateImage to propagate changes to the XImage.
ID of an existing image element.
(x, y) is at offset y * w + x.
GUpdateImage
XImage::put_pixel for every byte that differs. After writing, the shadow is updated to match. This diff avoids redundant pixel writes and keeps updates fast when only a small portion of the canvas changes.
ID of an existing image element.
GUpdateImage updates the XImage in memory. The image is composited onto the back buffer during the next GRenderWindow call. You do not need to call GRenderWindow yourself if you are inside GSimpleWindowLoop — it is called automatically each frame.GClearImage
c using memset. Does not call GUpdateImage — you must call it yourself after clearing if you want the change to appear.
ID of an existing image element.
Palette index to fill every pixel with.
GCreateCheckbox
Unique element ID.
Left edge of the checkbox square in window coordinates.
Top edge of the checkbox square in window coordinates.
Side length of the checkbox square in pixels. The same value is used for both width and height.
Packed color byte for the checkbox square. High nibble = border palette index, low nibble = fill palette index.
Palette index for the label text drawn to the right of the box.
Optional label string. Pass
NULL to render the checkbox with no label. The label is drawn 3 pixels to the right of the box, vertically centered.GGetCheckbox
1 if the checkbox is currently checked, 0 if it is unchecked.
ID of an existing checkbox element.
GDeleteElement
index. For image elements (type 4), this also destroys the XImage and frees both the pixel data buffer and the shadow buffer. The element slot is set to NULL; the slot may be reused by any subsequent GCreate* call with the same ID. No-ops if index is out of range or the slot is already NULL.
ID of the element to delete.
GElemModifyBounds
XImage dimensions are not reallocated — only the draw position and the dimensions used for hit-testing and rendering are updated.
ID of the element to modify.
New left edge in window coordinates.
New top edge in window coordinates.
New width.
New height.