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.

Buttons, input fields, and checkboxes are LWXGL’s interactive widget elements. They respond to mouse hover and click automatically — no event-attachment code is required for their built-in visual states and value changes.

Packed color bytes

Buttons, inputs, and checkboxes accept packed color bytes for their color parameters. A packed byte encodes two palette indices in one int:
  • High nibble (H, bits 7–4) — border / outline color (palette index 0–15)
  • Low nibble (L, bits 3–0) — fill / background color (palette index 0–15)
For example, 0x7F means border = palette 7 (gray), fill = palette 15 (white).

GCreateButton

void GCreateButton(int id, int x, int y, int w, int h,
                   int u, int hvr, int p,
                   const char* label, void (*onclick)(void))
Creates a clickable button with three visual states: unpressed, hovered, and pressed. The label is centered horizontally using 9-px-wide characters.
id
int
required
Element slot index.
x
int
required
Left edge in window pixels.
y
int
required
Top edge in window pixels.
w
int
required
Width in pixels.
h
int
required
Height in pixels.
u
int
required
Packed color byte for the unpressed (normal) state. High nibble = border, low nibble = fill.
hvr
int
required
Packed color byte for the hover state (cursor inside, mouse button up).
p
int
required
Packed color byte for the pressed state (cursor inside, left mouse button held).
label
const char*
required
Button text, centered within the button bounds. Each character is 9 px wide.
onclick
void (*)(void)
required
Callback invoked when the left mouse button is released over the button. May be NULL for a button with no action.
When a button’s onclick fires, the global GEventAttachClick callback is suppressed for that event — the click is consumed by the button.

GCreateInput

void GCreateInput(int id, int x, int y, int w, int h, int u, int hvr, int max)
Creates a single-line text input field. When the mouse cursor is inside the field, printable characters and Backspace are routed to it. An underscore cursor (_) is appended to the visible text while the field is active.
id
int
required
Element slot index.
x
int
required
Left edge in window pixels.
y
int
required
Top edge in window pixels.
w
int
required
Width in pixels. Pass -1 to auto-size to (max + 1) * 9 + 10 pixels, which fits the maximum character count plus the cursor character.
h
int
required
Height in pixels. 24 is a typical value for single-line inputs.
u
int
required
Packed color byte for the inactive (cursor outside) state.
hvr
int
required
Packed color byte for the active/hover (cursor inside) state.
max
int
required
Maximum number of characters the field accepts. The internal buffer is fixed at 128 bytes; max should be ≤ 127 to leave room for the null terminator.

GGetInput

char* GGetInput(int id)
Returns a pointer to the internal null-terminated input buffer for element id.
id
int
required
Element slot index of an existing input element.
Return value: char* — pointer to the internal 128-byte buffer. This is the live buffer — its contents change as the user types. Treat it as read-only: do not write to, free, or retain it past the element’s lifetime.

GCreateCheckbox

void GCreateCheckbox(int id, int x, int y, int size, int cb_col, int txt_col, const char* label)
Creates a toggleable checkbox square with an optional text label to its right. Clicking anywhere within the checkbox box or the label text toggles the checked state. When checked, a filled square is drawn inside the box, inset by 4 px on each side (i.e., size - 8 px filled square).
id
int
required
Element slot index.
x
int
required
Left edge of the checkbox square in window pixels.
y
int
required
Top edge of the checkbox square in window pixels.
size
int
required
Side length in pixels of the checkbox square. Also determines the element’s bounding box height. Typical value: 16.
cb_col
int
required
Packed color byte for the checkbox square. High nibble = border color, low nibble = fill color.
txt_col
int
required
Palette index (0–15) for the label text color.
label
const char*
required
Text displayed to the right of the box, offset by 3 px. Pass NULL for no label. The label pointer is stored by reference — do not free or move it while the element exists.

GGetCheckbox

int GGetCheckbox(int id)
Returns the current checked state of checkbox element id.
id
int
required
Element slot index of an existing checkbox element.
Return value: int1 if checked, 0 if unchecked.

Example

void on_submit(void) {
    char *name = GGetInput(1);
    int agreed = GGetCheckbox(2);
    printf("Name: %s, Agreed: %d\n", name, agreed);
}

GCreateText(0, 20, 20, 15, "Name:");
GCreateInput(1, 20, 40, 200, 24, 0x80, 0x90, 20);
GCreateCheckbox(2, 20, 80, 16, 0x70, 15, "I agree");
GCreateButton(3, 20, 110, 100, 28, 0x70, 0x80, 0x90, "Submit", on_submit);
This builds a simple form with a labeled text input, a checkbox, and a submit button that reads both values when clicked.

Build docs developers (and LLMs) love