LWXGL organizes every visible object in a window as an element stored in a flat integer-indexed slot array. You create elements by calling the appropriateDocumentation 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.
GCreate* function with a unique integer ID. Elements are rendered in slot order each time GRenderWindow is called, and they can be destroyed individually with GDeleteElement. This page covers every widget type in the library: text labels, buttons, input fields, rectangles, and image canvases.
GDeleteElement
NULL. For Image elements (type 4), the function additionally calls XDestroyImage on the backing XImage and releases both the current-frame pixel buffer (data) and the previous-frame diff buffer (prev). For all other element types, only the element struct itself is freed.
The function is a no-op when the slot is already NULL or when index is out of range, so it is safe to call defensively without checking first.
The integer ID of the element to delete. Must be a previously-registered slot index. Out-of-range values and already-
NULL slots are silently ignored.GCreateText
GRenderWindow is called. Multi-line text is supported: the renderer splits on \n characters and advances the baseline by 16 pixels per line. The text pointer is stored directly inside the element struct — it is not copied — so the string must remain valid for the entire lifetime of the element.
Because the text pointer is stored by reference, passing a pointer to a local stack buffer that goes out of scope will result in undefined behaviour. Use string literals or heap-allocated strings that outlive the window.
Unique element ID. If a slot at this ID already exists it is deleted and replaced.
Left edge of the text in pixels, measured from the window’s left edge.
Top edge of the text in pixels, measured from the window’s top edge. Internally the renderer adds 11 px to
y to align the font baseline correctly, so y=0 places the top of the glyph at the very top of the window.Palette index (0–15) used to draw the text. The palette is the standard 16-color CGA-style palette shared across all LWXGL rendering.
Null-terminated string to display. Use
\n to break the label across multiple lines. The pointer is stored directly — do not free or reuse the buffer while the element is alive.GCreateButton
onclick callback is fired when the left mouse button is released while the cursor is inside the button’s bounds.
Packed color format: each color parameter encodes two palette indices in a single byte. The high nibble (bits 7–4) is the foreground (border + text) color; the low nibble (bits 3–0) is the background (fill) color. For example,
0x7F gives foreground index 7 (Light Gray) and background index 15 (White). Use the expression (fg << 4) | bg to build the value at runtime.Unique element ID.
X coordinate of the button’s top-left corner in pixels.
Y coordinate of the button’s top-left corner in pixels.
Width of the button in pixels.
Height of the button in pixels.
Packed color byte for the normal (unhovered, unpressed) state. High nibble = foreground, low nibble = background.
Packed color byte for the hover state, applied when the mouse cursor is inside the button bounds and no mouse button is held.
Packed color byte for the pressed state, applied while the left mouse button is held down inside the button bounds.
Null-terminated string rendered centered inside the button. The pointer is stored by reference — do not free the string while the element is alive.
Callback invoked when the user releases the left mouse button while the cursor is within the button’s bounding rectangle. Pass
NULL for no action.GCreateInput
max limits how many characters the user can enter. When the cursor is inside the field, a blinking _ caret is appended to the displayed text.
The input field only captures keystrokes when the mouse cursor is within the element’s bounds at the time the key event fires. There is no explicit focus mechanism — move the cursor over the field to type into it.
Unique element ID.
X coordinate of the field’s top-left corner in pixels.
Y coordinate of the field’s top-left corner in pixels.
Width of the field in pixels. Pass
-1 to use automatic sizing: the width is computed as (max + 1) * 9 + 10 pixels, which provides exactly enough room for max characters at the 9-pixel font pitch plus 5 px of left/right padding.Height of the field in pixels.
Packed color byte (high nibble = foreground, low nibble = background) for the normal (cursor-outside) state.
Packed color byte for the active (cursor-inside) state.
Maximum number of characters the user may type. The internal buffer is always 128 bytes regardless of this value;
max must therefore be ≤ 127 to leave room for the null terminator.GGetInput
InputElement at the given id. The buffer is always null-terminated. You can read the current contents at any time — typically inside a button’s onclick callback to act on what the user typed.
The element ID of an existing input field created with
GCreateInput.GCreateRect
fg and bg are direct palette indices (0–15), not packed bytes. The fill and border are drawn independently — pass -1 for either to skip that part of the rendering. This makes GCreateRect suitable for backgrounds, separators, and decorative borders.
Unique element ID.
X coordinate of the rectangle’s top-left corner in pixels.
Y coordinate of the rectangle’s top-left corner in pixels.
Width of the rectangle in pixels.
Height of the rectangle in pixels.
Palette index (0–15) for the border drawn with
XDrawRectangle. Pass -1 to omit the border entirely.Palette index (0–15) for the fill drawn with
XFillRectangle. Pass -1 to omit the fill (transparent background).GCreateImage
XImage allocated with XCreateImage. LWXGL allocates two pixel buffers at creation time:
data— the writable current-frame buffer (w * hbytes). Write palette indices here to paint the canvas.prev— the previous-frame snapshot buffer (w * hbytes) used byGUpdateImagefor diff-based rendering.
imgdata) holds the raw pixel data that XPutImage reads from, sized h * bytes_per_line bytes as required by Xlib.
Unique element ID.
X coordinate of the canvas’s top-left corner within the window, in pixels.
Y coordinate of the canvas’s top-left corner within the window, in pixels.
Canvas width in pixels. Determines the stride:
index = px + py * w.Canvas height in pixels.
GGetImageData
data) for the image canvas at the given id. The buffer is width * height bytes, laid out in row-major order: the byte at coordinates (x, y) is located at index x + y * width. Each byte encodes a palette index in the range 0–15.
Write palette indices into this buffer to paint the canvas, then call GUpdateImage to propagate the changes to the underlying XImage before the next GRenderWindow call.
The element ID of an existing image canvas created with
GCreateImage.GUpdateImage
XImage via the Xlib put_pixel function, and updates the snapshot. Pixels that have not changed are skipped entirely.
Call GUpdateImage after writing new pixel data and before calling GRenderWindow. Because only changed pixels are processed, the function is efficient enough to call every frame even for large canvases where most pixels are static.
The element ID of an existing image canvas created with
GCreateImage.GUpdateImage only updates the internal XImage buffer. The canvas is not visible on screen until GRenderWindow is called, which blits the XImage to the window via XPutImage.