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.

Checkbox elements provide a simple boolean toggle control. Each checkbox is a square box that fills with a smaller inner square when checked. An optional text label can be placed to the right of the box. Left-clicking anywhere within the hit-test region — the box itself plus the label area — toggles the checked state. The box colors follow the same packed integer convention as buttons and inputs: the low nibble is the fill color and the high nibble is the border color.

Hit-Test Region

The clickable area extends beyond the visible box to include the label:
effective_width = size + 10 + strlen(label) * 9
If label is NULL the hit area is just size × size. The height of the hit region always equals size.

Functions

CreateCheckbox

Creates a toggleable checkbox element with an optional text label.
void CreateCheckbox(int id, int x, int y, int size,
                    int cb_col, int txt_col, const char* label);
id
int
required
Unique integer identifier for this element.
x
int
required
Left edge of the checkbox box in pixels.
y
int
required
Top edge of the checkbox box in pixels.
size
int
required
Width and height of the checkbox box in pixels. Also determines the height of the hit-test region.
cb_col
int
required
Packed color for the checkbox box. Low nibble = fill color (CLR_*); high nibble = border color (CLR_*). When checked, the inner indicator square is drawn in the border color (high nibble).
txt_col
int
required
Color of the label text, one of the CLR_* palette constants. The packing convention does not apply here — this is used directly as a CLR_* index. Pass any value if label is NULL.
label
const char*
required
Text label drawn size + 5 pixels to the right of the box. Pass NULL for no label; the hit region then equals only the box area.

GetCheckbox

Returns the current checked state of a checkbox element.
int GetCheckbox(int id);
id
int
required
The identifier of a checkbox element previously created with CreateCheckbox.
Returns 1 if the checkbox is currently checked, or 0 if it is unchecked. The state is toggled internally each time the user clicks within the hit-test region.

Visual Details

The renderer draws the checkbox as follows:
  1. Fill the size × size box with the low-nibble color.
  2. Outline the box with the high-nibble color (XDrawRectangle).
  3. If checked, fill an inner rectangle inset by 4 px on each side with the high-nibble color.
  4. If a label is provided, draw it size + 5 px to the right, vertically centered at y + size/2 + 5.

Code Example

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

/* Checkbox IDs */
#define CHK_VSYNC    10
#define CHK_FULLSCR  11
#define CHK_SHADOWS  12
#define CHK_SOUND    13

static void on_apply(void) {
    printf("Settings:\n");
    printf("  VSync:       %s\n", GetCheckbox(CHK_VSYNC)   ? "ON" : "OFF");
    printf("  Fullscreen:  %s\n", GetCheckbox(CHK_FULLSCR) ? "ON" : "OFF");
    printf("  Shadows:     %s\n", GetCheckbox(CHK_SHADOWS) ? "ON" : "OFF");
    printf("  Sound:       %s\n", GetCheckbox(CHK_SOUND)   ? "ON" : "OFF");
}

static void on_frame(int tick, float dt) {
    (void)tick; (void)dt;
    ImmediateText(20, 10, "Graphics Settings", CLR_WHITE);
}

int main(void) {
    CreateWindow(320, 260, "Settings Panel", CLR_BLACK, FLAG_NONE);

    /* Checkbox style: white fill, gray border */
    int cb_col = CLR_WHITE | (CLR_GRAY << 4);

    CreateCheckbox(CHK_VSYNC,   20, 50,  18, cb_col, CLR_WHITE, "Enable VSync");
    CreateCheckbox(CHK_FULLSCR, 20, 90,  18, cb_col, CLR_WHITE, "Fullscreen mode");
    CreateCheckbox(CHK_SHADOWS, 20, 130, 18, cb_col, CLR_LGRAY, "High-quality shadows");
    CreateCheckbox(CHK_SOUND,   20, 170, 18, cb_col, CLR_WHITE, "Enable sound");

    /* Apply button */
    int btn_u   = CLR_GRAY  | (CLR_WHITE << 4);
    int btn_hvr = CLR_LGRAY | (CLR_WHITE << 4);
    int btn_p   = CLR_BLACK | (CLR_LGRAY << 4);
    CreateButton(20, 100, 210, 120, 30, btn_u, btn_hvr, btn_p, "Apply", on_apply);

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

Build docs developers (and LLMs) love