Skip to main content

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.

These utility functions operate on the shared element list — the central array that holds every text, button, image, input, checkbox, console, and rectangle element. Each element is identified by its integer slot index id. Functions that accept id are valid for elements of any type unless otherwise noted.

DeleteElement

void DeleteElement(int index);
Frees all resources associated with the element at slot index and sets the slot to NULL. The slot can be reused for a new element immediately after deletion. Type-specific cleanup performed:
  • Text (type 0): frees the string if it was copied (created with CreateCopiedText)
  • Image (type 4): destroys the XImage, frees data, prev, and font buffer, frees the off-screen Pixmap
  • All other types: deletes the type-specific struct
Calling DeleteElement on a NULL slot or an out-of-bounds index is safe (no-op).
index
int
required
Element slot index to delete.

ElemModifyBounds

void ElemModifyBounds(int id, int x, int y, int w, int h);
Updates the position and optionally the size of element id. The element is moved to (x, y). If w is -1, the existing width is preserved; similarly for h. This affects rendering position and hit-testing immediately — no explicit refresh is needed.
id
int
required
Element slot index.
x
int
required
New X position (window coordinates).
y
int
required
New Y position (window coordinates).
w
int
required
New width in pixels, or -1 to leave the current width unchanged.
h
int
required
New height in pixels, or -1 to leave the current height unchanged.

ElemSetVisible

void ElemSetVisible(int id, int visible);
Controls whether element id is rendered and participates in hit-testing.
visibleEffect
1Visible and interactive (default)
0Hidden and not hit-tested
Hiding an element is cheaper than deleting and recreating it when you need to toggle its presence frequently.
id
int
required
Element slot index.
visible
int
required
1 to show the element, 0 to hide it.

ElemInside

int ElemInside(int id);
Returns 1 if the mouse cursor is currently inside the bounds of element id, 0 otherwise. Returns 0 unconditionally when a modal dialog is open. For checkbox elements, the hit area is extended to include the label text in addition to the checkbox square.
id
int
required
Element slot index.

ElemAnchor

void ElemAnchor(int anchor, int ids[], int count);
Attaches or detaches a scroll anchor for each element in the ids array. When anchor != 0, each element’s current Y position is saved as its anchor offset (e->anchor = e->y). When scroll is active, ResolveAnchors will set the element’s Y to scroll_offset + anchor_offset, keeping it at a fixed visual position relative to the viewport. When anchor == 0, the anchor is cleared: each element’s Y position is first restored to the previously saved anchor value (e->y = e->anchor), and then the anchor field is set to INT_MIN to mark it as un-anchored. The element reverts to a static position and will no longer be repositioned by ResolveAnchors.
anchor
int
required
Non-zero to set anchors (using current Y positions), 0 to clear anchors.
ids
int[]
required
Array of element slot indices to anchor or un-anchor.
count
int
required
Number of elements in the ids array.

ResolveAnchors

void ResolveAnchors(void);
Updates the Y position of every anchored element to scroll_offset + anchor_offset. Must be called once per frame in the on_every callback when scroll is enabled and you have anchored elements (e.g. a fixed header toolbar). Elements without an anchor (anchor == INT_MIN) are skipped.
Call ResolveAnchors at the top of your frame callback, before drawing, so that anchored elements are always rendered at the correct position for the current scroll offset.

SetGlobalBold

int SetGlobalBold(int bold);
Switches the global Xlib font between 9x15 (normal) and 9x15bold (bold). Affects all text elements, button labels, console output, and any other text rendered through the GC. Returns 1 on success, 0 if the font could not be loaded.
bold
int
required
1 to switch to bold, 0 to switch to normal weight.

Code Example

The following example creates a scrollable window with a header toolbar that stays fixed at the top using anchors, and a list of content items that scroll normally.
#include "libLWXGL.h"

#define ID_HEADER_BG   1
#define ID_HEADER_TEXT 2
#define ID_CONTENT_IMG 3

static int anchored_ids[] = {ID_HEADER_BG, ID_HEADER_TEXT};

void on_scroll(int offset) {
    // ResolveAnchors is called in the frame callback; nothing to do here
}

void on_frame(int tick, float dt) {
    // 1. Keep header elements glued to the top of the viewport
    ResolveAnchors();

    // 2. Draw scrollable content into image element
    ClearImage(ID_CONTENT_IMG, CLR_BLACK);
    for (int i = 0; i < 20; i++) {
        PrimitiveRect(ID_CONTENT_IMG, 10, 50 + i * 30, 300, 24,
                      CLR_GRAY, CLR_BLUE);
    }
    UpdateImage(ID_CONTENT_IMG);
}

int main(void) {
    // Virtual canvas is 600px tall; window is 200px
    ReserveScroll(600, CLR_LGRAY, on_scroll);

    CreateWindow(320, 200, "Anchor Demo", CLR_BLACK, FLAG_NONE);

    // Header bar (always visible at top)
    CreateRect(ID_HEADER_BG, 0, 0, 320, 30, CLR_NONE, CLR_GRAY);
    CreateText(ID_HEADER_TEXT, 10, 8, "Header Toolbar", CLR_WHITE);

    // Scrollable content image (starts below header)
    CreateImage(ID_CONTENT_IMG, 0, 30, 310, 570);

    // Anchor the header elements at their current Y positions
    ElemAnchor(1, anchored_ids, 2);

    // Hide the content image after a delay as a demo of visibility toggle
    // ElemSetVisible(ID_CONTENT_IMG, 0);

    MainWindowLoop(60, on_frame);
    TerminateWindow();
    return 0;
}

Build docs developers (and LLMs) love