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 console widget provides a scrollable, terminal-style text pane that is useful for displaying real-time log output, debug information, or any stream of text lines. Text is appended with a printf-style interface, the view auto-scrolls to the bottom when new content arrives (provided the user has not scrolled up), and a scroll position overlay is shown on hover. The widget auto-sizes itself from the cols and rows parameters, eliminating manual pixel arithmetic.

Dimensions

The pixel size of the console is computed automatically from the column and row counts:
width  = cols * 9 + 17   /* 9 px per character + 8 px right margin for scrollbar */
height = rows * 15 + 10  /* 15 px per line + 10 px vertical padding              */

Color Parameters

Both con_clr and txt_clr are packed color integers:
ParameterLow nibbleHigh nibble
con_clrConsole background fillConsole border / scrollbar thumb fill
txt_clrScrollbar fill (used for hover overlay background)Text color

Character Rendering

  • Characters in the range 27–126 are rendered as-is.
  • Tab characters (\t) are expanded to 4 spaces before rendering.
  • Newline characters (\n) advance to the next line.
  • Any other byte (outside 27–126 and not \n or \t) is replaced with ?.

Scroll Behavior

ActionEffect
Mouse wheel up (button 4)Scroll up 3 lines.
Mouse wheel down (button 5)Scroll down 3 lines.
Space key (while hovering)Jump to the bottom (last page).
ConsolePrint / new contentAuto-scroll to bottom if the view was already at the bottom before the print.
A status overlay (Viewing: start - end / total and Scroll: N%) is drawn over the console when the mouse pointer is inside the element.

Functions

CreateConsole

Creates a scrollable console widget.
void CreateConsole(int id, int x, int y, int cols, int rows,
                   int con_clr, int txt_clr);
id
int
required
Unique integer identifier for this element.
x
int
required
Left edge of the console widget in pixels.
y
int
required
Top edge of the console widget in pixels.
cols
int
required
Number of character columns visible at once. The pixel width is computed as cols * 9 + 17. Lines longer than cols characters are wrapped automatically.
rows
int
required
Number of text rows visible at once. The pixel height is computed as rows * 15 + 10.
con_clr
int
required
Packed color for the console pane itself. Low nibble = background fill; high nibble = border and scrollbar thumb color.
txt_clr
int
required
Packed color for text. Low nibble = scrollbar/hover-overlay background; high nibble = text foreground color.

ConsolePrint

Appends formatted text to the console’s internal buffer using printf-style format strings. If the view was already scrolled to the bottom before this call, it auto-scrolls to keep the latest content visible.
void ConsolePrint(int id, const char* format, ...);
id
int
required
The identifier of the console element to print to.
format
const char*
required
A printf-compatible format string. The formatted output is appended verbatim to the internal std::string buffer. Include \n to start a new line.
...
variadic
Additional arguments matched to format specifiers in format, following the same rules as printf.
You do not need to append \n to every call — text wraps at cols characters automatically. However, using \n gives you explicit control over line breaks.

ConsoleClear

Clears all text from the console buffer and resets the scroll position to the top.
void ConsoleClear(int id);
id
int
required
The identifier of the console element to clear.

Code Example

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

#define CON_ID 1
#define BTN_CLEAR 2

static int log_counter = 0;

static void on_clear(void) {
    ConsoleClear(CON_ID);
    log_counter = 0;
}

static void on_frame(int tick, float dt) {
    /* Log one line per second */
    static float acc = 0.0f;
    acc += dt;
    if (acc >= 1.0f) {
        acc -= 1.0f;
        ConsolePrint(CON_ID, "[%04d] tick=%d  dt=%.4f s\n",
                     log_counter++, tick, dt);
    }
}

int main(void) {
    CreateWindow(600, 400, "Log Viewer", CLR_BLACK, FLAG_NONE);

    /*
     * Console:
     *   con_clr: black fill (low), white border + scrollbar (high)
     *   txt_clr: gray overlay bg (low), light-green text (high)
     */
    int con_clr = CLR_BLACK | (CLR_WHITE  << 4);
    int txt_clr = CLR_GRAY  | (CLR_LGREEN << 4);

    /* 60 columns × 20 rows => 557 × 310 px */
    CreateConsole(CON_ID, 10, 10, 60, 20, con_clr, txt_clr);

    ConsolePrint(CON_ID, "=== Log started ===\n");

    /* Clear button below the console */
    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(BTN_CLEAR, 10, 330, 100, 28, btn_u, btn_hvr, btn_p, "Clear", on_clear);

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

Build docs developers (and LLMs) love