CLua Documentation


🎨 Colors & Schemes

CLua provides a comprehensive system for working with colors in the GUI. Color values are simple Lua tables, usable anywhere — in direct element styling or in named color schemes.


🏗️ Color constructors

Basic functions for creating a color value:

RGB(r, g, b)   -- {red, green, blue}
GRAY(v)        -- gray: RGB(v, v, v)
BLACK()        -- RGB(0, 0, 0)
WHITE()        -- RGB(255, 255, 255)

All functions return a table compatible with any function that accepts a color value.


🎨 Predefined colors — COLOR

The global COLOR table contains named color constants. They can be used anywhere instead of RGB(...):

setColor(el, COLOR.PureCyan, COLOR.DarkBlue)

Colors are organized into groups:

Group Examples
Standard Black Red Green Yellow Blue Magenta Cyan White
Bright BrightBlack BrightRed BrightGreen BrightYellow …
Dark DarkGray DarkRed DarkGreen DarkBlue DarkCyan
Pure PureRed PureGreen PureBlue PureYellow PureMagenta PureCyan
Grays Gray LightGray Silver Gainsboro
Reds & pinks Crimson Tomato Coral Salmon Pink HotPink DeepPink
Oranges & browns OrangeRed Orange Gold Chocolate SaddleBrown Brown Tan
Greens ForestGreen Olive LimeGreen Lime SpringGreen
Blues Navy RoyalBlue SteelBlue DodgerBlue SkyBlue LightBlue
Purples Indigo DarkViolet Purple MediumPurple Violet Orchid Plum
Teals & cyans Teal Turquoise Aquamarine

The Dark, Bright and Pure groups are consistently derived from the base terminal palette:

Dark (~60 %) Base (~50 %) Bright (mixed) Pure (255)
DarkRed Red BrightRed PureRed
DarkGreen Green BrightGreen PureGreen
DarkBlue Blue BrightBlue PureBlue
DarkCyan Cyan BrightCyan PureCyan

Some entries are aliases (noted in source comments): Navy = Blue, Teal = Cyan, Lime = PureGreen, etc.


🖌️ Direct element color setters

Every element inherits from ElementClass methods for setting colors on specific states. All accept fg (foreground/text color) and bg (background color). Setting a direct color detaches the entire element from its scheme — the remaining states keep whatever colors they had from the scheme at that moment, but the element no longer reacts to any scheme changes.

Method Sets state(s)
el:SetColor(fg, bg) All states at once
el:SetColorNormal(fg, bg) Normal
el:SetColorFocus(fg, bg) Focus
el:SetColorHot(fg, bg) HotNormal + HotFocus
el:SetColorHotNormal(fg, bg) HotNormal
el:SetColorHotFocus(fg, bg) HotFocus
el:SetColorDisabled(fg, bg) Disabled
el:SetColorHighlight(fg, bg) Highlight
lbl:SetColor(COLOR.BrightWhite, COLOR.DarkBlue);
btn:SetColorFocus(COLOR.PureYellow, COLOR.DarkGreen);
btn:SetColorDisabled(COLOR.Gray, COLOR.DarkGray);

🗂️ Color schemes

A scheme is a named set of colors covering all element states at once. One scheme can be shared across many elements — define it once, apply repeatedly.

Constructor SchemeColors

Creates a color scheme table from positional arguments. Arguments must be passed in complete groups:

Argument count What is set
2 — normalFg, normalBg All states = normal
4 — + focusFg, focusBg Normal + Focus; Hot* derived
10 — + hotNormalFg/Bg, hotFocusFg/Bg, disabledFg/Bg + HotNormal, HotFocus, Disabled
12 — + highlightFg, highlightBg Full scheme
SchemeColors(normalFg, normalBg
    [, focusFg, focusBg
        [, hotNormalFg, hotNormalBg, hotFocusFg, hotFocusBg,
           disabledFg,  disabledBg
            [, highlightFg, highlightBg]]])

COLOR.* constants and RGB() calls can be freely mixed:

local myColors = SchemeColors(
    COLOR.BrightWhite, COLOR.DarkBlue,    -- normalFg,    normalBg
    COLOR.PureCyan,    RGB(10, 10, 60)    -- focusFg,     focusBg
);

Function SetScheme

Creates or overwrites a named scheme:

SetScheme(name, schemeColors)
Parameter Type Description
name string Scheme name
schemeColors SchemeColors Table created via SchemeColors(...)
local uiColors = SchemeColors(
    COLOR.PureMagenta, COLOR.DarkRed,       -- normalFg,    normalBg
    COLOR.Magenta,     COLOR.Gray,           -- focusFg,     focusBg
    COLOR.PureBlue,    COLOR.DarkGreen,      -- hotNormalFg, hotNormalBg
    COLOR.PureCyan,    COLOR.DarkBlue,       -- hotFocusFg,  hotFocusBg
    COLOR.BrightBlack, COLOR.DarkCyan,       -- disabledFg,  disabledBg
    COLOR.Green,       COLOR.DarkRed         -- highlightFg, highlightBg
);

SetScheme("Base",   uiColors);
SetScheme("Button", uiColors);

Built-in scheme names: Base, Menu, Dialog, Label, Button, ProgressBar, Checkbox, TextField, logView. Each is automatically the default for its corresponding element type — Button for buttons, Label for labels, etc. (Base is the default for windows, frames, and scrollbar areas.) Overwriting a scheme via SetScheme applies immediately to all elements that still use it — including ones already created.


✅ Applying a scheme to an element

Via method

el:ApplyScheme(schemeName)
btn:ApplyScheme("Button");
frame:ApplyScheme("Base");

Via el parameter at creation

Every get* function accepts an optional schemeName field in its last el parameter. When present, the scheme is applied automatically right after the element is created:

local btn = getButton(win, XYWH(2, 3, 20, 1), "OK", onOk, {
    schemeName = "Button"
});

local frame = getFrame(win, XYWH(0, 0, 40, 10), "Panel", {
    schemeName = "Base"
});

✍️ Example: full color setup

-- Define a scheme
local dark = SchemeColors(
    COLOR.BrightWhite, RGB(20, 20, 40),   -- Normal
    COLOR.PureCyan,    RGB(10, 10, 60)    -- Focus
);
SetScheme("DarkTheme", dark);

-- Apply at element creation
local win   = getWindow("Tool", true, {});
local frame = getFrame(win, XYWH(0, 0, 60, 20), "Results", {
    schemeName = "DarkTheme"
});
local btn   = getButton(frame, XYWH(2, 16, 15, 1), "Run", runMacro, {
    schemeName = "DarkTheme"
});

-- Direct color without a scheme
local lbl = getLabel(frame, XYWH(2, 1, 40, 1), "Status:", {});
lbl:SetColor(COLOR.Gold, RGB(20, 20, 40));