Class “Color”
Object > Color
Represents a color. See also ColorValue
| Constructor |
public |
| Singleton |
No |
| Namespace |
tabris |
| Direct subclasses |
None |
| JSX support |
No |
Example
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 |
Optional |
Description |
| red |
number |
No |
A number between and including 0 and 255 |
| green |
number |
No |
A number between and including 0 and 255 |
| blue |
number |
No |
A number between and including 0 and 255 |
| alpha |
number |
Yes |
A number between and including 0 and 255. Defaults to 255. |
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 |
Optional |
Description |
| colorValue |
ColorValue |
No |
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 |
Optional |
Description |
| value |
any |
No |
The value to test |
Returns value is ColorValue
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 |
Optional |
Description |
| value |
any |
No |
The value to test |
Returns value is ColorValue
Properties
alpha
A number between and including 0 and 255
| Type |
number |
| Settable |
No |
| Change events |
No |
This property can only be set via constructor. Once set, it cannot change anymore.
blue
A number between and including 0 and 255
| Type |
number |
| Settable |
No |
| Change events |
No |
This property can only be set via constructor. Once set, it cannot change anymore.
green
A number between and including 0 and 255
| Type |
number |
| Settable |
No |
| Change events |
No |
This property can only be set via constructor. Once set, it cannot change anymore.
red
A number between and including 0 and 255
| Type |
number |
| Settable |
No |
| Change events |
No |
This property can only be set via constructor. Once set, it cannot change anymore.
Static Properties
aqua
| Type |
Color |
| Settable |
No |
| Change events |
No |
black
| Type |
Color |
| Settable |
No |
| Change events |
No |
blue
| Type |
Color |
| Settable |
No |
| Change events |
No |
fuchsia
| Type |
Color |
| Settable |
No |
| Change events |
No |
gray
| Type |
Color |
| Settable |
No |
| Change events |
No |
green
| Type |
Color |
| Settable |
No |
| Change events |
No |
lime
| Type |
Color |
| Settable |
No |
| Change events |
No |
maroon
| Type |
Color |
| Settable |
No |
| Change events |
No |
navy
| Type |
Color |
| Settable |
No |
| Change events |
No |
olive
| Type |
Color |
| Settable |
No |
| Change events |
No |
purple
| Type |
Color |
| Settable |
No |
| Change events |
No |
red
| Type |
Color |
| Settable |
No |
| Change events |
No |
silver
| Type |
Color |
| Settable |
No |
| Change events |
No |
teal
| Type |
Color |
| Settable |
No |
| Change events |
No |
transparent
| Type |
Color |
| Settable |
No |
| Change events |
No |
white
| Type |
Color |
| Settable |
No |
| Change events |
No |
yellow
| Type |
Color |
| Settable |
No |
| Change events |
No |