Color picker (lv_cpicker)

Overview

As its name implies Color picker allows to select color. The Hue, Saturation and Value of the color can be selected after each other.

The widget has two forms: circle (disc) and rectangle.

In both forms, be long pressing the object, the color picker will change to the next parameter of the color (hue, saturation or value). Besides, double click will reset the current parameter.

Parts and Styles

The Color picker's main part is called LV_CPICKER_PART_BG. In circular form it uses scale_width to set the the width of the circle and pad_inner for padding between the circle and the inner preview circle. In rectangle mode radius can be used to apply a radius on the rectangle.

The object has virtual part called LV_CPICKER_PART_KNOB which is rectangle (or circle) drawn on the current value. It uses all the rectangle like style properties and padding to make it larger than the width of the circle or rectangle background.

Usage

Type

The type of the Color picker can be changed with lv_cpicker_set_type(cpicker, LV_CPICKER_TYPE_RECT/DISC)

Set color

The colro can be set manually with lv_cpicker_set_hue/saturation/value(cpicker, x) or all at once with lv_cpicker_set_hsv(cpicker, hsv) or lv_cpicker_set_color(cpicker, rgb)

Color mode

The current color moed can be manually selected with lv_cpicker_set_color_mode(cpicker, LV_CPICKER_COLOR_MODE_HUE/SATURATION/VALUE).

The color moe be fixed (do not change with long press) using lv_cpicker_set_color_mode_fixed(cpicker, true)

Knob color

lv_cpicker_set_knob_colored(cpicker, true) make the knob to automatically show the selected color as background color.

Events

Only the Generic events are sent by the object type.

Learn more about Events.

Keys

  • LV_KEY_UP, LV_KEY_RIGHT Increment the current parameter's value by 1

  • LV_KEY_DOWN, LV_KEY_LEFT Decrement the current parameter's by 1

  • LV_KEY_ENTER By long press the next mode will be shown. By double click the current parameter will be reset.

Learn more about Keys.

Example

C

Disc color picker

code

#include "../../../lv_examples.h"
#if LV_USE_CPICKER

void lv_ex_cpicker_1(void)
{
    lv_obj_t * cpicker;

    cpicker = lv_cpicker_create(lv_scr_act(), NULL);
    lv_obj_set_size(cpicker, 200, 200);
    lv_obj_align(cpicker, NULL, LV_ALIGN_CENTER, 0, 0);
}

#endif

MicroPython

Disc color picker

Click to try in the simulator!
lv_ex_cpicker_1

code

cpicker = lv.cpicker(lv.scr_act(),None)
cpicker.set_size(200, 200)
cpicker.align(None, lv.ALIGN.CENTER, 0, 0)

API

Typedefs

typedef uint8_t lv_cpicker_type_t
typedef uint8_t lv_cpicker_color_mode_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_PART_MAIN
enumerator LV_CPICKER_PART_KNOB
enumerator _LV_CPICKER_PART_VIRTUAL_LAST
enumerator _LV_CPICKER_PART_REAL_LAST

Functions

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

Create a colorpicker objects

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

Returns

pointer to the created colorpicker

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)

bool lv_cpicker_set_hue(lv_obj_t *cpicker, uint16_t hue)

Set the current hue of a colorpicker.

Parameters
  • cpicker -- pointer to colorpicker object

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

Returns

true if changed, otherwise false

bool lv_cpicker_set_saturation(lv_obj_t *cpicker, uint8_t saturation)

Set the current saturation of a colorpicker.

Parameters
  • cpicker -- pointer to colorpicker object

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

Returns

true if changed, otherwise false

bool lv_cpicker_set_value(lv_obj_t *cpicker, uint8_t val)

Set the current value of a colorpicker.

Parameters
  • cpicker -- pointer to colorpicker object

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

Returns

true if changed, otherwise false

bool lv_cpicker_set_hsv(lv_obj_t *cpicker, lv_color_hsv_t hsv)

Set the current hsv of a colorpicker.

Parameters
  • cpicker -- pointer to colorpicker object

  • hsv -- current selected hsv

Returns

true if changed, otherwise false

bool lv_cpicker_set_color(lv_obj_t *cpicker, lv_color_t color)

Set the current color of a colorpicker.

Parameters
  • cpicker -- pointer to colorpicker object

  • color -- current selected color

Returns

true if changed, otherwise false

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_knob_colored(lv_obj_t *cpicker, bool en)

Make the knob to be colored to the current color

Parameters
  • cpicker -- pointer to colorpicker object

  • en -- true: color the knob; false: not color the knob

lv_cpicker_color_mode_t lv_cpicker_get_color_mode(lv_obj_t *cpicker)

Get the current color mode.

Parameters

cpicker -- pointer to colorpicker object

Returns

color mode (hue/sat/val)

bool lv_cpicker_get_color_mode_fixed(lv_obj_t *cpicker)

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

Parameters

cpicker -- pointer to colorpicker object

Returns

mode cannot be changed on long press

uint16_t lv_cpicker_get_hue(lv_obj_t *cpicker)

Get the current hue of a colorpicker.

Parameters

cpicker -- pointer to colorpicker object

Returns

current selected hue

uint8_t lv_cpicker_get_saturation(lv_obj_t *cpicker)

Get the current saturation of a colorpicker.

Parameters

cpicker -- pointer to colorpicker object

Returns

current selected saturation

uint8_t lv_cpicker_get_value(lv_obj_t *cpicker)

Get the current hue of a colorpicker.

Parameters

cpicker -- pointer to colorpicker object

Returns

current selected value

lv_color_hsv_t lv_cpicker_get_hsv(lv_obj_t *cpicker)

Get the current selected hsv of a colorpicker.

Parameters

cpicker -- pointer to colorpicker object

Returns

current selected hsv

lv_color_t lv_cpicker_get_color(lv_obj_t *cpicker)

Get the current selected color of a colorpicker.

Parameters

cpicker -- pointer to colorpicker object

Returns

current selected color

bool lv_cpicker_get_knob_colored(lv_obj_t *cpicker)

Whether the knob is colored to the current color or not

Parameters

cpicker -- pointer to color picker object

Returns

true: color the knob; false: not color the knob

struct lv_cpicker_ext_t

Public Members

lv_color_hsv_t hsv
lv_style_list_t style_list
lv_point_t pos
uint8_t colored
struct lv_cpicker_ext_t::[anonymous] knob
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