Colors

Color Objects

Colors in lib-st are tables of color values.

<tt>
-- red, barely visible
local color = { 
    ["r"] = 1.0,
    ["g"] = 0.0,
    ["b"] = 0.0,
    ["a"] = 0.2,
};
</tt>

In most places where you would specify a color object, you can instead specify a function that will return a color object. if this function needs arguments, they can be supplied wrapped in a table ( an array of args ) and assigned to colorargs.

Example

For example, if you wanted to define a column that had text with a color based on which column left-to-right it was, then you would define your columns something like this:

<tt>
ColumnColor = function(index)
    return { 
        ["r"] = index/10, -- must be a number from 0 to 1.
        ["g"] = index/10,
        ["b"] = index/10,
        ["a"] = 1.0,
    }, -- will go from black to white, left to right.    
end;

cols = {
    {
        ["name"] = "Column 1",
        ["width"] = 50,
        ["color"] = ColumnColor,
        ["colorargs"] = {1,},
    }, -- [1]
    {
        ["name"] = "Column 2",
        ["width"] = 50,
        ["color"] = ColumnColor,
        ["colorargs"] = {2,},
    }, -- [2]
};
</tt>

You would then use cols when constructing your scrolling table.
This technique can be used to color rows or even an individual cell's text. Row and cell coloring is controlled in the table data... table... -- yay, lua...




Comments

  • To post a comment, please or register a new account.
Posts Quoted:
Reply
Clear All Quotes