TweakerColorizer

Provides functionality for giving meaningful names to colors and applying those colors to pieces of text. TweakerColorizer objects can inherit from other TweakerColorizer objects and access their colors. The base TweakerColorizer object defines many standard colors.

new

Instantiates a new TweakerColorizer object.

Syntax

TweakerColorizer:new([colors])

Arguments

  1. colors - (table) A table of key/value pairs where the key is the name of a color and the value is the 6 digit hexadecimal representation of that color

Returns

  1. (TweakerColorizer) A new TweakerColorizer object

Examples

  • Create a new TweakerColorizer local colorizer = TweakerColorizer:new({ cooldude = "8080af", coolchick = "af8080", })
  • Inherit from an existing TweakerColorizer local new_colorizer = colorizer:new({ lamedude = "afaf80", lamechick = "80afaf", })

Notes

  • You can use Tweaker.Colorizer to access Tweaker's default colorizer.

Properties

GetColor

Receives the name of a color and returns its hexadecimal representation. Parent classes are searched recursively until a match is found, or else returns nil.

Syntax

TweakerColorizer:GetColor(name)

Arguments

  1. name - (string) The name of a color to retrieve

Returns

  1. (string) The color associated with the given name, or nil if there isn't one

Examples

  • TweakerColorizer defines many common colors that can be retrieved without defining them local colorizer = TweakerColorizer:new() colorizer:GetColor("red") -- returns "ff0000"
  • You can expand on this yourself by inheriting from TweakerColorizer local blues = TweakerColorizer:new({ blue1 = "000033", blue2 = "000066", blue3 = "000099", }) local blues_and_purples = blues:new({ purple1 = "330033", purple2 = "660066", purple3 = "990099", }) blues_and_purples:GetColor("red") -- returns "ff0000" blues_and_purples:GetColor("blue2") -- returns "000066" blues_and_purples:GetColor("cardboard") -- returns nil

GetColors

Works like GetColor but accepts multiple names and returns a color for each name. Values are returned in the same order and manner in which the names are supplied. If no names are supplied, all colors are returned in a hash table of name/color pairs.

Syntax

TweakerColorizer:GetColors() -- or -- TweakerColorizer:GetColors(names) -- or -- TweakerColorizer:GetColors(name1[, name2[, name3[, ...]]])

Arguments

  1. arg1 - Can be one of following:
    • nil - (nil)
    • names - (table) An array of color names
    • name1..namen - (string) A list of names

Returns

  1. Depending on the argument supplied, can be one of the following:
    • (table) A hash table of all the name/color pairs for the colorizer, including those of its parents
    • (table) A hash table of name/color pairs for each name given in the supplied array
    • (string list) A list of colors, returned in the same order as the list of names supplied

Examples

  • Get all the colors local a = TweakerColorizer:new() local b = a:new({skyblue = "87ceeb"}) local c = b:new({powderblue = "b0e0e6"}) local colors = c:GetColors() -- returns { powderblue = "b0e0e6", skyblue = "87ceeb", ... } where the ellipsis represents all colors defined by the base TweakerColorizer class
  • Get the specified colors, as a hash table local a = TweakerColorizer:new() local colors = a:GetColors(["red", "green", "blue"]) -- returns { red = "ff0000", green = "00ff00", blue = "0000ff" }
  • Get the specified colors in sequence local a = TweakerColorizer:new() local red, green, blue = a:GetColors("red", "green", "blue") -- returns "ff0000", "00ff00", "0000ff"

GetCustomColors

Returns all the colors custom defined by the colorizer. Unlike GetColor and GetColors, does not include colors defined by any parents of the colorizer.

Syntax

TweakerColorizer:GetCustomColors()

Returns

  1. (table) A hash table of name/color pairs for all the colors defined by the colorizer

Examples

  • Get the colorizer's custom colors local a = TweakerColorizer:new({skyblue = "87ceeb", powderblue = "b0e0e6"}) local custom_colors = a:GetCustomColors() -- returns { skyblue = "87ceeb", powderblue = "b0e0e6" }

SetColor

Defines a new color for the colorizer, using the given name.

Syntax

TweakerColorizer:SetColor(name, color)

Arguments

  1. name - (string) Any name you'd like to use to reference the given color
  2. color - (string) A 6-digit hexadecimal string that represents the color

Examples

  • Set a new color local colorizer = TweakerColorizer:new() colorizer:SetColor("sky blue", "87ceeb")

SetColors

Defines new colors for the colorizer

Syntax

TweakerColorizer:SetColors(colors)

Arguments

  1. colors - (table) A hash table of name/color pairs to add to the colorizer

Examples

  • Set new colors local colorizer = TweakerColorizer:new() colorizer:SetColors({ ["sky blue"] = "87ceeb", ["powder blue"] = "b0e0e6" })

Utilities

ToHexString

Converts rgb values to a hex string appropriate for storage in a colorizer

Syntax

TweakerColorizer:ToHexString(r,g,b)

Arguments

  1. r - (integer) A value from 0 to 255 that denotes how much red to use
  2. g - (integer) A value from 0 to 255 that denotes how much green to use
  3. b - (integer) A value from 0 to 255 that denotes how much blue to use

Returns

  1. (string) A 6 digit hexadecimal string that can be used as the "color" in TweakerColorizer

Examples

  • Using ToHexString to set a new color local colorizer = TweakerColorizer:new() colorizer:SetColor("sky blue", colorizer:ToHexString(135, 206, 235))

ToDecimal

Converts a hexadecimal number to a decimal number

Syntax

TweakerColorizer:ToDecimal(hex)

Arguments

  1. hex - (string) A hexadecimal number

Returns

  1. (number) The decimal equivalent of the hexadecimal number

Examples

  • Store a color as a decimal value local colorizer = TweakerColorizer:new() colorizer:ToDecimal("87ceeb") -- returns 8900331

Notes

  • I'm not exactly sure of a good use for this, but I figured I might as well include it since I figured out how to do it.

Functions

Apply

Applies a color to a string of text. The text supports string.format functionality.

Syntax

TweakerColorizer:Apply(name, text, ...)

Arguments

  1. name - (string) The name of a color defined by the colorizer to apply to the text
  2. text - (string) The text to apply the color to, supports string.format replacements
  3. ... - (mixed list) Values to replace into the text

Returns

  1. (string) Returns the result of string.format(text, ...) with tags to apply the given color to it

Examples

  • Print an error message to the user local colorizer = TweakerColorizer:new() function print_error(msg) DEFAULT_CHAT_FRAME:AddMessage(colorizer:Apply("red", "An error has occured: %s", msg)) end

RegexApply

Performs string.format then applies the specified color to the parts of the result that match the regex

Syntax

TweakerColorizer:RegexApply(name, regex, text, ...)

Arguments

  1. name - (string) The name of a color defined by the colorizer to apply to the text
  2. regex - (string) A regex pattern that matches the text that should be colored
  3. text - (string) The base text, supports string.format replacement
  4. ... - (mixed list) Values to replace into the text

Returns

  1. (string) Returns the result of string.format(text, ...) with tags to apply the given color to all parts of the text that match the given regex

Examples

  • Color the argument names in a list local colorizer = TweakerColorizer:new() local argument_list = "arg1[, arg2[, arg3[, ...[, argN]]]]" argument_list = colorizer:RegexApply("blue", "[^\[\] ,\.]+", argument_list)