LWXGL widgets are identified by a caller-assigned integerDocumentation 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.
id. Every element function either creates, queries, or modifies the element stored at that slot. IDs are zero-based and the element vector grows automatically to accommodate the largest ID you use. Creating a new element at an ID that is already occupied automatically frees the old one first.
Element types are encoded internally as integers: 0 = text, 1 = button, 2 = input, 3 = rect, 4 = image, 5 = checkbox, 6 = console.
Element Management
GDeleteElement
index and sets that slot to NULL. If index is out of bounds or the slot is already NULL, the call is a safe no-op.
For image elements, this also calls XDestroyImage and releases the pixel and font buffers. For all other types the typed sub-struct is deleted and the base Element struct is freed.
The element slot to delete. Must be a previously allocated ID; out-of-range or already-
NULL slots are silently ignored.GElemModifyBounds
id in place. The element is not recreated — only its x, y, w, and h fields are overwritten. The change takes effect on the next GRenderWindow call.
Target element ID.
New X position (pixels from the left edge of the window).
New Y position (pixels from the top edge of the window).
New width in pixels.
New height in pixels.
GElemSetVisible
id. Hidden elements (visible = 0) are skipped entirely during rendering and do not receive mouse or keyboard events. The element’s data is preserved; call GElemSetVisible(id, 1) to make it visible again without recreating it.
Target element ID.
Pass
1 to show the element or 0 to hide it.GElemInside
1 if the mouse cursor is currently inside the element’s bounding box, the element is visible (v = 1), and the element belongs to the active screen (or is screen-independent, i.e., screen == -1). Returns 0 otherwise.
For checkbox elements the bounding box is extended to the right to include the label text: the effective right edge is x + size + 6 + strlen(label) * 9.
The element to test.
int: 1 if the cursor is inside, 0 if not.
Example
Text Label
GCreateText
x, y). Rendering uses the window’s built-in X11 font (9×15 pixels per character). The string pointer is stored directly — do not free or modify the buffer while the element is alive.
Multi-line text is supported: the renderer splits on \n and advances the Y baseline by 15 pixels per line, so lines are rendered with no additional leading beyond the built-in line height.
Element slot to create the text label at.
X position of the leftmost character (pixels from window left).
Y position of the text baseline (pixels from window top). The first line is drawn with the X11 baseline at
y + 11.Palette index
0–15 for the text foreground color.Null-terminated string to display. Use
\n for line breaks. The pointer must remain valid for the lifetime of the element.Button
GCreateButton
onclick callback is invoked when the user releases mouse button 1 (left-click) while the cursor is inside the button.
The label is rendered centered both horizontally and vertically inside the button bounds using the 9×15 X11 font.
Element slot to create the button at.
X position of the top-left corner in pixels.
Y position of the top-left corner in pixels.
Width of the button in pixels.
Height of the button in pixels.
Packed color byte for the normal (unpressed) state. Upper nibble = border palette index; lower nibble = fill palette index.
Packed color byte for the hover state (cursor is over the button but not clicking).
Packed color byte for the pressed state (mouse button held down over the button).
Centered text label. The pointer must remain valid for the lifetime of the element.
Callback function invoked on left-click. Pass
NULL to create a button with no action.Input Field
GCreateInput
_ cursor character. When inactive the cursor is replaced by a space.
The internal input buffer is 128 bytes, so the effective maximum value for max is 127 (leaving room for the null terminator).
Element slot to create the input field at.
X position of the top-left corner in pixels.
Y position of the top-left corner in pixels.
Width in pixels. Pass
-1 to auto-size: the width is computed as (max + 1) * 9 + 10, which is just wide enough to display max characters plus the _ cursor with a small inset.Height in pixels.
Packed color byte for the inactive state (upper nibble = border, lower = fill).
Packed color byte for the hover/active state.
Maximum number of characters the user may type. Hard limit:
127 due to the 128-byte internal buffer.GGetInput
InputElement struct and is valid until the element is deleted or recreated.
The input element to read.
char*: pointer to the current text (null-terminated, up to 127 printable characters).
Example
Checkbox
GCreateCheckbox
size × size pixels with a border and fill drawn from cb_col. When checked, a filled inner rectangle (inset by 4 pixels on each side) is drawn using the border color. Clicking anywhere inside the checkbox bounding box (including the label area) toggles the checked state.
Element slot to create the checkbox at.
X position of the top-left corner of the checkbox square.
Y position of the top-left corner of the checkbox square.
Width and height of the checkbox square in pixels.
Packed color byte for the checkbox square (upper nibble = border, lower nibble = fill). The border color is also used for the inner check mark fill.
Palette index
0–15 for the label text color.Text displayed 3 pixels to the right of the checkbox square. Pass
NULL to render no label.GGetCheckbox
id.
The checkbox element to query.
int: 1 if the checkbox is currently checked, 0 if unchecked.
Example
Rectangle
GCreateRect
-1 for either to skip that part.
Elements are drawn in ascending ID order, so assign lower IDs to background rectangles so they appear behind other widgets.
Element slot to create the rectangle at.
X position of the top-left corner in pixels.
Y position of the top-left corner in pixels.
Width in pixels.
Height in pixels.
Palette index
0–15 for the 1-pixel outline border. Pass -1 to draw no border.Palette index
0–15 for the solid fill. Pass -1 to draw no fill (border only).Packed Color Reference
Many LWXGL widget functions accept a packed color byte (int u, int hvr, int p, etc.) that encodes two palette indices into a single integer using nibble packing:
0–15.
Common Packed Color Values
| Packed Byte | Border (upper) | Fill (lower) | Typical Use |
|---|---|---|---|
0xFF | 15 — white | 15 — white | Bright white button |
0x00 | 0 — black | 0 — black | Invisible / black-on-black |
0x07 | 0 — black | 7 — light gray | Default inactive input |
0x0F | 0 — black | 15 — white | High-contrast input (active) |
0x78 | 7 — light gray | 8 — dark gray | Subtle raised panel |
0x87 | 8 — dark gray | 7 — light gray | Normal button state |
0x8A | 8 — dark gray | 10 — green | Hover accent button |
0x8F | 8 — dark gray | 15 — white | Pressed/active button |
0xF0 | 15 — white | 0 — black | Dark checkbox with white border |
0x80 | 8 — dark gray | 0 — black | Dark console background |
GPaletteQuery and GPaletteModify to inspect or change them.