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.

The LWXGL console element is a scrollable text display widget with a built-in scroll bar. It renders text in a monospaced grid using the window’s X11 font (9×15 pixels per character). The console accumulates output into an internal std::string buffer, word-wraps lines that exceed the configured column width, and displays the visible window of lines offset by the current scroll position.
Lines longer than cols characters are automatically hard-wrapped to the next visual line by the console renderer. There is no horizontal scroll — oversized lines simply continue on the line below, so the full content is always reachable by scrolling vertically.

Functions

GCreateConsole

void GCreateConsole(int id, int x, int y, int cols, int rows,
                    int con_clr, int txt_clr);
Creates a scrollable console element at window position (x, y). The pixel dimensions are derived automatically from the column and row counts:
  • Width: cols * 9 + 17 pixels (9 px per character + 8 px right margin for the scrollbar)
  • Height: rows * 15 + 10 pixels (15 px per row + 10 px vertical padding)
The console begins empty with scroll position 0.
id
int
required
Element slot to create the console at.
x
int
required
X position of the console’s top-left corner in the window (pixels).
y
int
required
Y position of the console’s top-left corner in the window (pixels).
cols
int
required
Number of character columns in the visible area. Also controls the line-wrap width: lines longer than cols characters are automatically wrapped.
rows
int
required
Number of visible character rows. Determines how many lines are shown at once and how large the scroll thumb is relative to the total content.
con_clr
int
required
Packed color byte for the console background and border (upper nibble = border palette index, lower nibble = fill palette index). The scrollbar thumb is drawn with the border color.
txt_clr
int
required
Packed color byte for text rendering. The upper nibble is used as the palette index for normal output text. The lower nibble is used as the foreground color for the scroll status overlay text (XDrawImageString) shown when the cursor hovers over the console.
Example
/*
 * 80-column, 24-row console at (10, 50).
 * Dark background (palette 1) with white border (palette 15).
 * White text (palette 15) with dark-blue overlay text color (palette 1).
 */
GCreateConsole(8, 10, 50, 80, 24, 0xF1, 0xF1);

GConsolePrint

void GConsolePrint(int id, const char* format, ...);
Appends formatted text to the console identified by id. The format string and variadic arguments follow the same conventions as the standard printf family — all standard format specifiers (%d, %s, %f, %.2f, etc.) are supported. Special characters are handled as follows:
  • \n — inserts a newline, starting a new logical line.
  • \t — expands to four spaces during rendering (stored as a literal tab in the buffer, expanded when drawn).
  • Any character outside the printable ASCII range 27–126 (except \n and \t) is rendered as ?.
If the console’s scroll position was already at the bottom before the print (i.e., the user was viewing the latest output), it auto-advances to the new bottom after appending, so new content stays in view. If the user has scrolled up to review earlier output, the scroll position is preserved. The formatted output buffer is capped at 1024 bytes per call. For longer output, split across multiple GConsolePrint calls.
id
int
required
The console element to append output to.
format
const char*
required
printf-style format string.
...
...
required
Variadic arguments matching the format string specifiers.
Example
GConsolePrint(8, "Server started on port %d\n", 8080);
GConsolePrint(8, "Connected: %s (%.1f ms latency)\n", "192.168.1.5", 12.4);
GConsolePrint(8, "Items:\n\tApples\n\tBananas\n\tOranges\n");

GConsoleClear

void GConsoleClear(int id);
Clears all accumulated content from the console. The internal string buffer is erased, the total line count is reset to 0, and the scroll position is reset to 0 (top). The console will render as empty on the next GRenderWindow call.
id
int
required
The console element to clear.
Example
/* Clear the log on user request */
void on_clear_button(void) {
    GConsoleClear(8);
    GConsolePrint(8, "Log cleared.\n");
}

Scrolling Behavior

The console supports interactive scrolling while the mouse cursor is inside its bounding box:
InteractionEffect
Scroll wheel upScroll up by 3 lines
Scroll wheel downScroll down by 3 lines
Spacebar (while hovering)Jump instantly to the bottom (latest output)
The scroll position is clamped so the display never shows past the first or last line of content.

Scroll Status Overlay

When the cursor is inside the console, two status strings are rendered in the top-right corner of the widget using XDrawImageString (opaque background, so they do not blend into the text beneath):
Viewing: X - Y / Z
Scroll: N%
  • X — first visible line number (1-based)
  • Y — last visible line number (X + rows - 1)
  • Z — total number of wrapped visual lines in the buffer
  • N — scroll percentage (scroll / max(1, total_lines - rows) * 100)
The overlay text color is the lower nibble of txt_clr (foreground) drawn on the lower nibble of con_clr (background).

Scrollbar

A vertical scrollbar thumb is drawn in the right margin (5 px wide, 8 px from the right edge of the widget). Its height is proportional to rows / total_lines, with a minimum height of 16 px. Its vertical position reflects the current scroll offset within the scrollable range.

Build docs developers (and LLMs) love