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.

Input elements provide single-line text entry boxes. When the mouse pointer is inside an input field it becomes “active” — a blinking cursor underscore (_) is appended to the displayed text, and key events are directed to that field. Pressing printable keys appends characters to an internal 128-byte buffer; Backspace removes the last character. Like buttons, the normal and hover visual states are encoded as packed color integers (low nibble = fill color, high nibble = border color).

Keyboard Behavior

KeyAction
Printable ASCII (codes 32–126)Append to the buffer (up to max characters).
Backspace (code 8)Remove the last character from the buffer.
All other keysIgnored by the input field.
The buffer is always null-terminated. The active input is determined by which element the mouse pointer is currently inside.

Functions

CreateInput

Creates a single-line text input field.
void CreateInput(int id, int x, int y, int w, int h,
                 int u, int hvr, int max);
id
int
required
Unique integer identifier for this element.
x
int
required
Left edge of the input field in pixels.
y
int
required
Top edge of the input field in pixels.
w
int
required
Width of the field in pixels. Pass -1 to auto-size: LWXGL computes (max + 1) * 9 + 10, which fits all max characters plus the cursor indicator with padding.
h
int
required
Height of the field in pixels. A value of 2428 typically provides comfortable padding around the 9x15 font.
u
int
required
Packed color for the inactive state (pointer outside the field). Low nibble = fill, high nibble = border.
hvr
int
required
Packed color for the active/hover state (pointer inside the field). Same packing as u.
max
int
required
Maximum number of characters the field will accept. Values greater than 127 are silently clamped to 127 by std::min(max, 127).
The internal buffer is always 128 bytes. Even if you pass max = 127 the 128th byte is reserved for the null terminator. You can never store more than 127 printable characters in a single input field.

GetInput

Returns a pointer to the input field’s internal 128-byte character buffer. The returned pointer is valid until DeleteElement(id) is called.
char* GetInput(int id);
id
int
required
The identifier of an input element previously created with CreateInput.
Returns a char* pointing directly into the InputElement struct. The buffer is always null-terminated. Do not free() the returned pointer.
The pointer returned by GetInput becomes invalid as soon as DeleteElement(id) or TerminateWindow() is called. Copy the contents with strncpy before destroying the element if you need the data to outlive it.

Code Example

#include "libLWXGL.h"
#include <stdio.h>
#include <string.h>

static void on_submit(void) {
    /* Read username and password on button click */
    char* user = GetInput(1);
    char* pass = GetInput(2);
    printf("Login: user='%s' pass='%s'\n", user, pass);
}

static void on_frame(int tick, float dt) {
    (void)tick; (void)dt;
    ImmediateText(20, 20,  "Username:", CLR_WHITE);
    ImmediateText(20, 70,  "Password:", CLR_WHITE);
}

int main(void) {
    CreateWindow(360, 200, "Login Form", CLR_BLACK, FLAG_NONE);

    /* Color packs: white fill, gray border for inactive; light-cyan fill, white border for hover */
    int u_style   = CLR_WHITE  | (CLR_GRAY  << 4);
    int hvr_style = CLR_LCYAN  | (CLR_WHITE << 4);

    /* Username field — auto-sized for up to 20 characters */
    CreateInput(1, 120, 14, -1, 24, u_style, hvr_style, 20);

    /* Password field — fixed width, up to 32 characters */
    CreateInput(2, 120, 64, 200, 24, u_style, hvr_style, 32);

    /* Submit button */
    int btn_u   = CLR_GREEN  | (CLR_LGREEN << 4);
    int btn_hvr = CLR_LGREEN | (CLR_WHITE  << 4);
    int btn_p   = CLR_BLACK  | (CLR_GREEN  << 4);
    CreateButton(3, 120, 110, 100, 30, btn_u, btn_hvr, btn_p, "Login", on_submit);

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

Build docs developers (and LLMs) love