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’s screen system lets you organize elements into numbered layers. Only elements whose screen number matches the currently active screen — plus any elements assigned to the special screen -1 — are rendered and receive input. Switching screens is instantaneous: no elements are created, deleted, or reset.

How screens work

  • Every element starts on screen 0 by default.
  • GScreenApply assigns a batch of elements to a screen number in one call.
  • GScreenActive returns a pointer to the active screen integer. Write a new value through the pointer to switch screens.
  • Elements with screen value -1 are always visible regardless of which screen is active.
int* GScreenActive(void);
void GScreenApply(int s, int ids[], int count);

Example: two-page application

// ---- Page 0: welcome screen ----
GCreateText(0, 20, 20, 15, "Welcome!");
GCreateButton(1, 20, 50, 100, 28, 0x70, 0x72, 0x07, "Next", go_to_page1);

int page0_ids[] = {0, 1};
GScreenApply(0, page0_ids, 2);

// ---- Page 1: settings screen ----
GCreateText(2, 20, 20, 15, "Settings");
GCreateCheckbox(3, 20, 50, 14, 0x77, 15, "Enable audio");
GCreateButton(4, 20, 80, 100, 28, 0x70, 0x72, 0x07, "Back", go_to_page0);

int page1_ids[] = {2, 3, 4};
GScreenApply(1, page1_ids, 3);

// ---- Navigation callbacks ----
void go_to_page1(void) { *GScreenActive() = 1; }
void go_to_page0(void) { *GScreenActive() = 0; }

Persistent elements (screen -1)

Elements that should always be visible — such as a status bar, a background panel, or a persistent menu — can be assigned to screen -1:
// Background header bar — always visible
GCreateRect(99, 0, 0, 640, 30, -1, 8);

int always_ids[] = {99};
GScreenApply(-1, always_ids, 1);
These elements are rendered on every screen and also respond to input (hover, click) regardless of the active screen.

Renderer integration

The renderer checks e->screen == active_screen || e->screen == -1 before drawing or processing input for each element. There is no overhead for elements on inactive screens — they are simply skipped.
Screen switching does not affect element state. Checkbox values, input text, console content, and image pixel buffers are all preserved when the active screen changes. Switching back to a screen restores elements exactly as they were left.
Use a named enum for screen indices to keep navigation code readable and maintainable:
enum Screen {
    SCREEN_MAIN     = 0,
    SCREEN_SETTINGS = 1,
    SCREEN_GAME     = 2,
};

// Switch to the settings screen:
*GScreenActive() = SCREEN_SETTINGS;

Build docs developers (and LLMs) love