Skip to content

Color Palette

Dreller edited this page Sep 10, 2023 · 3 revisions

The Color Palette component is an utility to automatically build a color palette, to use within your apps, from a single HEX color code.


comColorPalette Build a Color Palette based on a single Hex Color Code.


Description

When you need to change the color you have set everywhere, it can be complicated to complete and can leads to mistakes. Using a color palette is the fastest way to apply an uniform set of colors on your controls. Using that component, updating colors everywhere is a matter of seconds: you only need to update a single color code, and the component will do the rest of the work for you.

Instructions

How to create a color palette

You must initialize the component using the Create() action. There is 2 possibilities:

  1. If you know which hexadecimal color code you wish to use, the formula will be: Component.Create("#84c32b");,
  2. If you want to create a color palette from a random color, the formula will be: Component.Create();.

Palette properties

Properties are accessibles under Component.Colors. The structure of the record is:

{
    Color: "#afd875ff",
    Dec: {
        R: 117,
        G: 216,
        B: 175
    },
    Font: "#141414ff",
    Hex: "#AFD875",
    IsDark: false,
    IsLight: true,
    Shade: "light"
}

Component logic

The component only need one hexadecimal color code to create your color palette. The palette also include a Font color you can use to set the Color property of controls, so users will be able to read the text.

Font color

For each color, the palette provides a Font value, which is the color to use for the text placed over that color. It is calculated using the color's brightness level, insuring the text will be readable.

If the color is light, the text will be dark; same for the opposite: if the color is dark, the text will be light.

Brightness level

To calculate the brightness level of a color, the following formula is used:

$\sqrt{ 0.241*Red^2 + 0.691*Green^2 + 0.068*Blue^2 }$

If the result is less than the threshold of 130, it means the color is dark (i.e. the perceived brigthness is dark).

Transformation from the base color

Color Transformation
Main color As is
Alternate color 35% lighter than Main color
Tertiary color 27% darker than Main color
Background color 92% lighter than Main color

Try it from the Library

The Library contains the Color Palette Screen, in which you can try the Component by yourself.

image

Enter an Hexadecimal Color Code and click "Mix Colors!". You can also click "Mix Random!" to generate a random Hex Color Code. You will see the Colors and the Record that holds the Color Palette you can use.