-
Notifications
You must be signed in to change notification settings - Fork 14
Color
All elements inside the ContextMenu use the Color class.
The Color.lua file comes with a table with predefined named colors. You can simply access the Color.lua file to see all available colors or add new ones.
local red = Colors.Red
local green = Colors.Green
local lightBlue = Colors.LightBlueShould you accidentally misspell a color or use a name that is not inside that table, instead of throwing an error, the script will default to a magenta/pink color that is known in many games as the "missing texture" color.
Create a new color from its RGBA channels (red, green, blue, alpha) (range is from 0-255). Should you not pass parameters to the function, it'll simply return a black color.
| Parameter | Type | Range | Default | Description |
|---|---|---|---|---|
| r | integer | 0-255 | 0 | The red channel of the color. |
| g | integer | 0-255 | 0 | The green channel of the color. |
| b | integer | 0-255 | 0 | The blue channel of the color. |
| a | integer | 0-255 | 255 | The alpha channel of the color. |
local red = Color(255, 0, 0, 255)
local green = Color(0, 255, 0, 255)
local blue = Color(0, 0, 255, 255)Other possible combinations:
local black = Color() -- same as Color(0, 0, 0, 255)
local red = Color(255) -- same as Color(255, 0, 0, 255)
local green = Color(0, 255) -- same as Color(0, 255, 0, 255)After a color has been created, you can easily change its values one by one as well:
-- create a color first
local myCol = Color(255, 0, 0)
-- change the RGBA values
-- this results in the same as Color(147, 50, 4, 150)
myCol.r = 147
myCol.g = 50
myCol.b = 4
myCol.a = 150Alternatively you can also return a new color with a changed alpha. This way you can still keep the old variable as needed.
-- create a color first
local red = Color(255, 0, 0)
-- return a new color with a different alpha value
local seethroughRed = red:Alpha(150)If you need the color in text form, you can just use the tostring function.
local colorText = "My color: " .. tostring(Colors.Red)
print(colorText)> My color: Color(255, 0, 0, 255)