Short description
A library to easy coloring strings by hex codes, color tables, class names, color names and more.
Supported types
- hex code with 8 and 6 characters. [<alpha>]<red><green><blue> like 9E342C (alpha is optional)
- color table in two variants: { <red[number]>, <green[number]>, <blue[number]>, <alpha[number](optional)> } or { ["r"] = <{ <red[number]>, ["g"] = <green[number]>, ["b"] = <blue[number]>, ["a"] = <alpha[number](optional)> }
- class names supports english and localized names on non english clients
- ITEM_QUALITY_COLORS as quality[number] and lower string version of ITEM_QUALITY[number]_DESC
- or keywords
- playerclass will be relaced with the current players class color
- second parameter must not be a string to coloring it
- not set second parameter returns hex color code
- the string "colortable" as second parameter returns the requested color as color table
To use in addons
lib = LibStub("LibColors-1.0")
API
- num2hex
- convert a number between 0 and 1 into a hex code between 00 and ff
string = lib:num2hex( number )
- colorTable2HexCode
- converts numeric or associative color tables into a 8 character long hex color code.
assoc_table = { r = 0.8, g = 0.8, b = 0.1, a = 1 } numeric_table = { 0.8, -- red 0.8, -- green 0.8, -- blue 1 -- alpha } string = lib:colorTable2HexCode( table )
- any not defined or nil table entry will be ignored.
- an empty table returns the hex code for the color white.
- hexCode2ColorTable
- converts a hex code into a color table
table = lib:hexCode2ColorTable( string )
- coloset
- add a single color code
lib:colorset( string, string or table )
- or add a list of color codes
table = { ["color name"] = color string or color table } lib:colorset( table )
- color
- create a colored string like |c<color><string>|r
string = lib:color( color, string )
- as first parameter you can use colors names, color tables or keywords
- currently implemented keyword for color are "playerclass"
- as second parameter you can use normal text or a keyword
- currently implemented keyword for second parameter are "colortable"
- that returns the requested color as colortable.
- getNames
- the parameter are optional and used to return matching color names.
table = lib:getNames( [string] )
Available colors
- Direct integrated
-
colors = { -- basic colors yellow = "ffff00", orange = "ff8000", red = "ff0000", violet = "ff00ff", blue = "0000ff", cyan = "00ffff", green = "00ff00", black = "000000", gray = "808080", white = "ffffff", -- wow money colors money_gold = "ffd700", money_silver = "eeeeef", money_copper = "f0a55f", }
- Color sets in extra files
- You can find 3 files named colors_<name>.lua in the directory and in LibColors-1.0.xml the lines to use it.
- The sources for the color sets are on top of the files.
Licence
To the hell with all licenses, the hole money, all weapons and other bad things... :P