Button elements are interactive rectangles with a centered text label. LWXGL automatically tracks mouse position and button state to switch between three visual appearances: the default (unpressed) state, a hover state when the pointer is inside the button, and a pressed state while the left mouse button is held down. Each of the three state parameters is a packed color integer that encodes both the fill (background) and border (foreground) colors in a single value. The low nibble is the fill color index and the high nibble is the border color index.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.
Packed Color Format
Many LWXGL element parameters use a packed integer to store twoCLR_* indices:
L(x) = x & 0xF) for the fill and the high nibble (H(x) = (x >> 4) & 0xF) for the border.
Functions
CreateButton
Creates an interactive button element. The button is drawn as a filled rectangle with an outline; the label is centered horizontally and vertically inside the bounds.Unique integer identifier for this element. Reusing an existing ID replaces the old element.
Left edge of the button in pixels.
Top edge of the button in pixels.
Width of the button in pixels.
Height of the button in pixels.
Packed color for the unpressed (default) state. Low nibble = fill color, high nibble = border color.
Packed color for the hover state (pointer inside button, no click held). Same packing as
u.Packed color for the pressed state (left mouse button held while inside button). Same packing as
u.Text label drawn centered inside the button. Centering is calculated using a fixed character width of 9 px. The pointer is stored directly — keep the string valid for the element’s lifetime.
Callback invoked when the user releases the left mouse button while the pointer is inside the button. Pass
NULL to create a non-interactive (display-only) button.State Transitions
| State | Condition |
|---|---|
Unpressed (u) | Pointer is outside the button bounds, or no mouse button is held. |
Hover (hvr) | Pointer is inside the button bounds and no mouse button is pressed. |
Pressed (p) | Left mouse button is held (mouse_down == 1) while pointer is inside bounds. |
onclick callback fires on mouse release (not press), consistent with standard button behavior. The callback is suppressed while a modal dialog is open — onclick will not fire until the modal is dismissed.
The label pointer is stored without copying. If your label string is a stack variable, ensure it remains in scope for the element’s lifetime, or use a static/global string.