Class “Color”
Object > Color
Represents a color. See also ColorValue
Type: |
Color extends Object |
Constructor: |
public |
Singleton: |
No |
Namespace: |
tabris |
Direct subclasses: |
None |
JSX Support: |
No |
Examples
JavaScript
import {Color} from 'tabris';
const color = Color.from('red');
console.log(color.red); // red channel value
Constructor
new Color(red, green, blue, alpha?)
Parameter |
Type |
Description |
red |
number |
A number between and including 0 and 255 |
green |
number |
A number between and including 0 and 255 |
blue |
number |
A number between and including 0 and 255 |
alpha |
number |
A number between and including 0 and 255. Defaults to 255. Optional. |
Methods
toArray()
Returns a array representation of the color in the format of [red, green, blue, alpha]
. Each value is a number between (and in including) 0 and 255.
Returns: [number, number, number, number]
toString()
Returns a string representation of the color. Is either in rgb(red, green, blue)
or rgba(red, green, blue, alpha)
format. Note that alpha is a value between 0 and 1 in the string representation, but between 0 and 255 on the Color object.
Returns: string
Static Methods
from(colorValue)
Creates a new instance of Color using any valid color expression. For any other value, including null
and 'initial'
the method throws.
Parameter |
Type |
Description |
colorValue |
ColorValue |
The value to create a Color instance from |
Returns: Color
isColorValue(value)
Returns true if value is a ColorValue. This includes null
and 'initial'
. Use this to check if a value will be accepted by a color property. This is also a valid TypeScript type guard function.
Parameter |
Type |
Description |
value |
any |
The value to test |
Returns: boolean
isValidColorValue(value)
Returns true if value is a valid ColorValue. This excludes null
and 'initial'
. Use this to check if a value will be accepted by Color.from. This is also a valid TypeScript type guard function.
Parameter |
Type |
Description |
value |
any |
The value to test |
Returns: boolean
Properties
alpha
A number between and including 0 and 255
This property can only be set via constructor. Once set, it cannot change anymore.
blue
A number between and including 0 and 255
This property can only be set via constructor. Once set, it cannot change anymore.
green
A number between and including 0 and 255
This property can only be set via constructor. Once set, it cannot change anymore.
red
A number between and including 0 and 255
This property can only be set via constructor. Once set, it cannot change anymore.
Static Properties
aqua
black
blue
fuchsia
gray
green
lime
maroon
navy
olive
purple
red
silver
teal
transparent
white
yellow