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.
LWXGL provides six types of UI widgets: text, button, input, checkbox, rect, and console. Each widget is created with an integer ID and rendered automatically every frame by GRenderWindow. IDs are stable — creating a new widget at an existing ID replaces the previous one.
Text Labels
void GCreateText(int id, int x, int y, int color, const char* text);
Renders a string at pixel position (x, y). color is a palette index (0–15). The text string supports \n for multi-line output; each line is spaced 16 pixels apart vertically.
// Single-line label
GCreateText(0, 20, 30, 15, "Hello, LWXGL!");
// Multi-line label
GCreateText(1, 20, 60, 10, "Line one\nLine two\nLine three");
void GCreateButton(int id, int x, int y, int w, int h,
int u, int hvr, int p,
const char* label, void (*onclick)(void));
| Parameter | Description |
|---|
id | Element ID |
x, y | Top-left position in pixels |
w, h | Width and height in pixels |
u | Packed color for the unpressed state |
hvr | Packed color for the hover state |
p | Packed color for the pressed (held) state |
label | Text drawn centered inside the button |
onclick | Callback invoked on left-click release; may be NULL |
Each color argument is a packed byte where the high nibble is the border color index and the low nibble is the fill color index. For example, 0xF0 = white border (index 15), black fill (index 0).
void on_save_click(void) {
printf("Save clicked!\n");
}
// White border + dark-gray fill when idle
// Light-gray border + dark-gray fill on hover
// Yellow border + dark-gray fill when pressed
GCreateButton(2, 100, 200, 120, 30,
0xF8, // unpressed: white border, dark-gray fill
0x78, // hover: light-gray border, dark-gray fill
0xE8, // pressed: yellow border, dark-gray fill
"Save",
on_save_click);
The packed color byte uses nibble encoding: the high nibble (color >> 4) & 0x0F is the border palette index, and the low nibble color & 0x0F is the fill palette index. For example, 0xF0 gives a white (15) border over a black (0) fill, and 0x2A gives a dark-green (2) border over a light-green (10) fill.
void GCreateInput(int id, int x, int y, int w, int h,
int u, int hvr, int max);
char* GGetInput(int id);
u and hvr are packed color bytes (same encoding as buttons). max is the maximum number of characters accepted. If w == -1, the width is automatically calculated as (max + 1) * 9 + 10 to fit all characters using the 9-pixel-wide font.
When the cursor is hovering over the input field, keystrokes are captured and appended to an internal 128-byte buffer. Backspace is handled automatically. GGetInput(id) returns a char* directly into that buffer — copy it if you need to keep the value.
// Auto-width input, up to 16 characters
GCreateInput(3, 20, 100, -1, 24,
0xF8, // inactive: white border, dark-gray fill
0xF0, // hover: white border, black fill
16);
// Elsewhere, read the current value:
const char* name = GGetInput(3);
printf("User entered: %s\n", name);
Checkboxes
void GCreateCheckbox(int id, int x, int y, int size,
int cb_col, int txt_col, const char* label);
int GGetCheckbox(int id);
| Parameter | Description |
|---|
size | Pixel side length of the checkbox square |
cb_col | Packed color byte for the box (high nibble = border, low nibble = fill) |
txt_col | Palette index for the label text |
label | Text drawn to the right of the box; may be NULL |
GGetCheckbox(id) returns 1 if checked, 0 if unchecked. Clicking anywhere on the box or its label toggles the state.
GCreateCheckbox(4, 20, 150, 14,
0xF8, // white border, dark-gray fill
15, // white label text
"Enable notifications");
// Check state in your frame loop:
if (GGetCheckbox(4)) {
printf("Notifications enabled\n");
}
Rectangles
void GCreateRect(int id, int x, int y, int w, int h, int fg, int bg);
Draws a solid rectangle at (x, y) with dimensions w × h. fg is the border color palette index; bg is the fill color palette index. Pass -1 for either to skip that layer — use fg=-1 for a borderless filled box, or bg=-1 for a hollow outline.
// Filled panel with a border
GCreateRect(5, 10, 10, 300, 200, 15, 8); // white border, dark-gray fill
// Outline only (no fill)
GCreateRect(6, 10, 10, 300, 200, 15, -1);
// Filled background, no border
GCreateRect(7, 10, 10, 300, 200, -1, 0); // black fill, no border
Comprehensive Example
The following snippet creates one of each widget type together in a single window:
#include "libLWXGL.h"
#include <stdio.h>
void on_submit(void) {
const char* name = GGetInput(2);
int agree = GGetCheckbox(3);
printf("Name: %s | Agreed: %d\n", name, agree);
}
int main(void) {
GCreateWindow(480, 320, "Widget Demo", 8); // dark-gray background
// Background panel
GCreateRect(0, 10, 10, 460, 300, 15, 0);
// Title label
GCreateText(1, 20, 30, 15, "Widget Demo\nFill in the form below:");
// Input field for a name (auto-width, max 20 chars)
GCreateInput(2, 20, 80, -1, 24,
0xF8, // inactive
0xF0, // hover
20);
// Checkbox for agreement
GCreateCheckbox(3, 20, 120, 14,
0xF8, // box colors
15, // white text
"I agree to the terms");
// Submit button
GCreateButton(4, 20, 155, 100, 28,
0xF8, // unpressed
0x78, // hover
0xE8, // pressed
"Submit",
on_submit);
// Horizontal divider rectangle
GCreateRect(5, 10, 195, 460, 2, -1, 15); // white line, no border
GSimpleWindowLoop(60, NULL);
GTerminateWindow();
return 0;
}