Color picker (lv_cpicker)

Overview

The color picker object draws a color band and knob that enable users to choose a color’s hue, saturation, and/or value.

Types of color pickers

The color band of a color picker can currently be drawn in two ways:

  • As a linear bar (LV_CPICKER_TYPE_RECT).

  • As a circular ring (LV_CPICKER_TYPE_DISC).

You can switch between these modes with lv_cpicker_set_type(cpicker, type).

Notes

In circular mode, the width and height of the color picker should be the same.

Styles

To set the style of a color picker object, use lv_cpicker_set_style(cpicker, LV_CPICKER_STYLE_XXX, &style). XXX can either be MAIN or INDICATOR, which represent the color band and knob, respectively.

  • line.width - the thickness of the color ring (in DISC mode)

  • body.[main/grad]_color - the background color of the color picker

Events

Besides the Generic events the following Special events are sent by color pickers:

  • LV_EVENT_VALUE_CHANGED - sent when the color changes.

Learn more about Events.

Keys

No Keys are processed by the object type.

Learn more about Keys.

Example

There is no official example available for this object type yet, but here is some sample test code:

    const lv_coord_t pickerSize = 200;

	/* Set the style of the color ring */
    static lv_style_t styleMain;
    lv_style_copy(&styleMain, &lv_style_plain);
    styleMain.line.width = 30;
	/* Make the background white */
    styleMain.body.main_color = styleMain.body.grad_color = LV_COLOR_WHITE;

	/* Set the style of the knob */
    static lv_style_t styleIndicator;
    lv_style_copy(&styleIndicator, &lv_style_pretty);
    styleIndicator.body.border.color = LV_COLOR_WHITE;
	/* Ensure that the knob is fully opaque */
    styleIndicator.body.opa = LV_OPA_COVER;
    styleIndicator.body.border.opa = LV_OPA_COVER;

    lv_obj_t * scr = lv_scr_act();

    lv_obj_t * colorPicker = lv_cpicker_create(scr, NULL);
    lv_obj_set_size(colorPicker, pickerSize, pickerSize);
	/* Choose the 'DISC' type */
    lv_cpicker_set_type(colorPicker, LV_CPICKER_TYPE_DISC);
    lv_obj_align(colorPicker, NULL, LV_ALIGN_CENTER, 0, 0);
	/* Set the styles */
    lv_cpicker_set_style(colorPicker, LV_CPICKER_STYLE_MAIN, &styleMain);
    lv_cpicker_set_style(colorPicker, LV_CPICKER_STYLE_INDICATOR, &styleIndicator);
	/* Change the knob's color to that of the selected color */
    lv_cpicker_set_indic_colored(colorPicker, true);

API

Typedefs

typedef uint8_t lv_cpicker_type_t
typedef uint8_t lv_cpicker_color_mode_t
typedef uint8_t lv_cpicker_style_t

Enums

enum [anonymous]

Values:

enumerator LV_CPICKER_TYPE_RECT
enumerator LV_CPICKER_TYPE_DISC
enum [anonymous]

Values:

enumerator LV_CPICKER_COLOR_MODE_HUE
enumerator LV_CPICKER_COLOR_MODE_SATURATION
enumerator LV_CPICKER_COLOR_MODE_VALUE
enum [anonymous]

Values:

enumerator LV_CPICKER_STYLE_MAIN
enumerator LV_CPICKER_STYLE_INDICATOR

Functions

lv_obj_t *lv_cpicker_create(lv_obj_t *par, const lv_obj_t *copy)

Create a colorpicker objects

Return

pointer to the created colorpicker

Parameters
  • par: pointer to an object, it will be the parent of the new colorpicker

  • copy: pointer to a colorpicker object, if not NULL then the new object will be copied from it

void lv_cpicker_set_type(lv_obj_t *cpicker, lv_cpicker_type_t type)

Set a new type for a colorpicker

Parameters
  • cpicker: pointer to a colorpicker object

  • type: new type of the colorpicker (from ‘lv_cpicker_type_t’ enum)

void lv_cpicker_set_style(lv_obj_t *cpicker, lv_cpicker_style_t type, lv_style_t *style)

Set a style of a colorpicker.

Parameters
  • cpicker: pointer to colorpicker object

  • type: which style should be set

  • style: pointer to a style

bool lv_cpicker_set_hue(lv_obj_t *cpicker, uint16_t hue)

Set the current hue of a colorpicker.

Return

true if changed, otherwise false

Parameters
  • cpicker: pointer to colorpicker object

  • hue: current selected hue [0..360]

bool lv_cpicker_set_saturation(lv_obj_t *cpicker, uint8_t saturation)

Set the current saturation of a colorpicker.

Return

true if changed, otherwise false

Parameters
  • cpicker: pointer to colorpicker object

  • saturation: current selected saturation [0..100]

bool lv_cpicker_set_value(lv_obj_t *cpicker, uint8_t val)

Set the current value of a colorpicker.

Return

true if changed, otherwise false

Parameters
  • cpicker: pointer to colorpicker object

  • val: current selected value [0..100]

bool lv_cpicker_set_hsv(lv_obj_t *cpicker, lv_color_hsv_t hsv)

Set the current hsv of a colorpicker.

Return

true if changed, otherwise false

Parameters
  • cpicker: pointer to colorpicker object

  • hsv: current selected hsv

bool lv_cpicker_set_color(lv_obj_t *cpicker, lv_color_t color)

Set the current color of a colorpicker.

Return

true if changed, otherwise false

Parameters
  • cpicker: pointer to colorpicker object

  • color: current selected color

void lv_cpicker_set_color_mode(lv_obj_t *cpicker, lv_cpicker_color_mode_t mode)

Set the current color mode.

Parameters
  • cpicker: pointer to colorpicker object

  • mode: color mode (hue/sat/val)

void lv_cpicker_set_color_mode_fixed(lv_obj_t *cpicker, bool fixed)

Set if the color mode is changed on long press on center

Parameters
  • cpicker: pointer to colorpicker object

  • fixed: color mode cannot be changed on long press

void lv_cpicker_set_indic_colored(lv_obj_t *cpicker, bool en)

Make the indicator to be colored to the current color

Parameters
  • cpicker: pointer to colorpicker object

  • en: true: color the indicator; false: not color the indicator

void lv_cpicker_set_preview(lv_obj_t *cpicker, bool en)

Add a color preview in the middle of the DISC type color picker

Parameters
  • cpicker: pointer to colorpicker object

  • en: true: enable preview; false: disable preview

lv_cpicker_color_mode_t lv_cpicker_get_color_mode(lv_obj_t *cpicker)

Get the current color mode.

Return

color mode (hue/sat/val)

Parameters
  • cpicker: pointer to colorpicker object

bool lv_cpicker_get_color_mode_fixed(lv_obj_t *cpicker)

Get if the color mode is changed on long press on center

Return

mode cannot be changed on long press

Parameters
  • cpicker: pointer to colorpicker object

const lv_style_t *lv_cpicker_get_style(const lv_obj_t *cpicker, lv_cpicker_style_t type)

Get style of a colorpicker.

Return

pointer to the style

Parameters
  • cpicker: pointer to colorpicker object

  • type: which style should be get

uint16_t lv_cpicker_get_hue(lv_obj_t *cpicker)

Get the current hue of a colorpicker.

Return

current selected hue

Parameters
  • cpicker: pointer to colorpicker object

uint8_t lv_cpicker_get_saturation(lv_obj_t *cpicker)

Get the current saturation of a colorpicker.

Return

current selected saturation

Parameters
  • cpicker: pointer to colorpicker object

uint8_t lv_cpicker_get_value(lv_obj_t *cpicker)

Get the current hue of a colorpicker.

Return

current selected value

Parameters
  • cpicker: pointer to colorpicker object

lv_color_hsv_t lv_cpicker_get_hsv(lv_obj_t *cpicker)

Get the current selected hsv of a colorpicker.

Return

current selected hsv

Parameters
  • cpicker: pointer to colorpicker object

lv_color_t lv_cpicker_get_color(lv_obj_t *cpicker)

Get the current selected color of a colorpicker.

Return

current selected color

Parameters
  • cpicker: pointer to colorpicker object

bool lv_cpicker_get_indic_colored(lv_obj_t *cpicker)

Whether the indicator is colored to the current color or not

Return

true: color the indicator; false: not color the indicator

Parameters
  • cpicker: pointer to colorpicker object

bool lv_cpicker_get_preview(lv_obj_t *cpicker)

Whether the preview is enabled or not

Return

en true: preview is enabled; false: preview is disabled

Parameters
  • cpicker: pointer to colorpicker object

struct lv_cpicker_ext_t

Public Members

lv_color_hsv_t hsv
lv_style_t *style
lv_point_t pos
uint8_t colored
struct lv_cpicker_ext_t::[anonymous] indic
uint32_t last_click_time
uint32_t last_change_time
lv_point_t last_press_point
lv_cpicker_color_mode_t color_mode
uint8_t color_mode_fixed
lv_cpicker_type_t type
uint8_t preview