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.

LWXGL uses a fixed 16-entry indexed color palette (indices 0–15). Every color argument in the API is an integer index into this palette — there are no raw RGB values in the public API. This keeps the interface simple and ensures consistent, theme-able colors across all elements.

Default Palette

The palette is initialised at startup with the following values. All 16 entries are allocated from the X11 default colormap inside GCreateWindow.
IndexNameRGB
0Black000
1Dark Blue33173
2Dark Green01700
3Dark Cyan0168168
4Dark Red18666
5Dark Magenta1680168
6Orange23012634
7Light Gray168168168
8Dark Gray858783
9Light Blue8787255
10Light Green8525585
11Light Cyan96240240
12Light Red2558585
13Light Magenta24084240
14Yellow24424254
15White255255255

Packed Color Bytes (Nibble Encoding)

Several widget creation functions — GCreateButton, GCreateInput, and GCreateCheckbox — accept packed color byte arguments rather than single palette indices. A packed byte encodes two palette indices in one value using nibble (4-bit half) encoding:
  • High nibble (H(b) — bits 7–4): border / outline color
  • Low nibble (L(b) — bits 3–0): fill / background color
For example, the packed byte 0x72 means:
  • High nibble 7 → border is index 7 (Light Gray)
  • Low nibble 2 → fill is index 2 (Dark Green)
You can express these inline as hex literals:
// GCreateButton(id, x, y, w, h, unpressed, hover, pressed, label, onclick)
GCreateButton(0, 10, 40, 120, 30,
    0x70,   // unpressed: border = 7 (Light Gray), fill = 0 (Black)
    0x72,   // hover:     border = 7 (Light Gray), fill = 2 (Dark Green)
    0x71,   // pressed:   border = 7 (Light Gray), fill = 1 (Dark Blue)
    "Click me", on_click);
The same encoding applies to:
FunctionPacked parameters
GCreateButtonu (unpressed), hvr (hover), p (pressed)
GCreateInputu (inactive), hvr (hover)
GCreateCheckboxcb_col (checkbox box colors)

Runtime Palette Modification

The palette can be changed at any point after GCreateWindow returns.

GPaletteModify

void GPaletteModify(int idx, unsigned char r, unsigned char g, unsigned char b, int redraw);
Replaces palette entry idx with the given RGB values. The old X11 color allocation is freed and a new one is allocated in its place.
  • If redraw is non-zero, all Image-type elements (GCreateImage) are immediately redrawn to pick up the new color.
  • Widget elements (buttons, inputs, etc.) pick up the new color automatically on the next rendered frame because they look up colors[idx] at draw time.

GPaletteReset

void GPaletteReset(void);
Restores all 16 palette entries to their factory defaults and calls GRedrawAllImages() to refresh image canvases.

GPaletteQuery

void GPaletteQuery(int idx, unsigned char* r, unsigned char* g, unsigned char* b);
Reads the current RGB values of palette entry idx back from the X11 colormap into *r, *g, *b. Useful for inspecting a live palette that may have been modified.

Example: Modifying and Resetting a Palette Entry

// Change slot 6 (Orange by default) to a custom blue, and redraw image canvases
GPaletteModify(6, 0, 100, 220, 1);

// ... application runs with the custom color ...

// Restore all 16 entries to defaults
GPaletteReset();
Palette changes affect every element that references the modified index — buttons, input fields, checkboxes, text labels, and all image canvases. There is no per-element color override mechanism. If you need two different shades that are active simultaneously, use two separate palette slots.

Build docs developers (and LLMs) love