A library to easy coloring strings by hex codes, color tables, class names, color names and more.
- 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
lib = LibStub("LibColors-1.0")
Convert a number between 0 and 1 into a hex code between 00 and ff
string = lib:num2hex( number )
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.
Converts a hex code into a color table
table = lib:hexCode2ColorTable( string )
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 )
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.
the parameter are optional and used to return matching color names.
table = lib:getNames( [string] )
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",
}
You can find 3 files named colors_.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.
World of Warcraft© and Blizzard Entertainment© are all trademarks or registered trademarks of Blizzard Entertainment in the United States and/or other countries. These terms and all related materials, logos, and images are copyright © Blizzard Entertainment.