Color wheel (lv_colorwheel)

Overview

As its name implies Color wheel allows the user to select a color. The Hue, Saturation and Value of the color can be selected separately.

Long pressing the object, the color wheel will change to the next parameter of the color (hue, saturation or value). A double click will reset the current parameter.

Parts and Styles

  • LV_PART_MAIN Only arc_width is used to set the width of the color wheel

  • LV_PART_KNOB A 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 arc.

Usage

Create a color wheel

lv_colorwheel_create(parent, knob_recolor) creates a new color wheel. With knob_recolor=true the knob's background color will be set to the current color.

Set color

The color can be set manually with lv_colorwheel_set_hue/saturation/value(colorwheel, x) or all at once with lv_colorwheel_set_hsv(colorwheel, hsv) or lv_colorwheel_set_color(colorwheel, rgb)

Color mode

The current color mode can be manually selected with lv_colorwheel_set_color_mode(colorwheel, LV_COLORWHEEL_MODE_HUE/SATURATION/VALUE).

The color mode can be fixed (so as to not change with long press) using lv_colorwheel_set_color_mode_fixed(colorwheel, true)

Events

  • LV_EVENT_VALUE_CHANGED Sent if a new color is selected.

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 A long press will show the next mode. Double click to reset the current parameter.

Learn more about Keys.

Example

C

Simple Colorwheel

#include "../../lv_examples.h"
#if LV_USE_COLORWHEEL && LV_BUILD_EXAMPLES

void lv_example_colorwheel_1(void)
{
    lv_obj_t * cw;

    cw = lv_colorwheel_create(lv_scr_act(), true);
    lv_obj_set_size(cw, 200, 200);
    lv_obj_center(cw);
}

#endif

MicroPython

No examples yet.

API

Typedefs

typedef uint8_t lv_colorwheel_mode_t

Enums

enum [anonymous]

Values:

enumerator LV_COLORWHEEL_MODE_HUE
enumerator LV_COLORWHEEL_MODE_SATURATION
enumerator LV_COLORWHEEL_MODE_VALUE

Functions

lv_obj_t *lv_colorwheel_create(lv_obj_t *parent, bool knob_recolor)

Create a color picker objects with disc shape

Parameters
  • parent -- pointer to an object, it will be the parent of the new color picker

  • knob_recolor -- true: set the knob's color to the current color

Returns

pointer to the created color picker

bool lv_colorwheel_set_hsv(lv_obj_t *obj, lv_color_hsv_t hsv)

Set the current hsv of a color wheel.

Parameters
  • colorwheel -- pointer to color wheel object

  • color -- current selected hsv

Returns

true if changed, otherwise false

bool lv_colorwheel_set_rgb(lv_obj_t *obj, lv_color_t color)

Set the current color of a color wheel.

Parameters
  • colorwheel -- pointer to color wheel object

  • color -- current selected color

Returns

true if changed, otherwise false

void lv_colorwheel_set_mode(lv_obj_t *obj, lv_colorwheel_mode_t mode)

Set the current color mode.

Parameters
  • colorwheel -- pointer to color wheel object

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

void lv_colorwheel_set_mode_fixed(lv_obj_t *obj, bool fixed)

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

Parameters
  • colorwheel -- pointer to color wheel object

  • fixed -- color mode cannot be changed on long press

lv_color_hsv_t lv_colorwheel_get_hsv(lv_obj_t *obj)

Get the current selected hsv of a color wheel.

Parameters

colorwheel -- pointer to color wheel object

Returns

current selected hsv

lv_color_t lv_colorwheel_get_rgb(lv_obj_t *obj)

Get the current selected color of a color wheel.

Parameters

colorwheel -- pointer to color wheel object

Returns

color current selected color

lv_colorwheel_mode_t lv_colorwheel_get_color_mode(lv_obj_t *obj)

Get the current color mode.

Parameters

colorwheel -- pointer to color wheel object

Returns

color mode (hue/sat/val)

bool lv_colorwheel_get_color_mode_fixed(lv_obj_t *obj)

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

Parameters

colorwheel -- pointer to color wheel object

Returns

mode cannot be changed on long press

Variables

const lv_obj_class_t lv_colorwheel_class
struct lv_colorwheel_t

Public Members

lv_obj_t obj
lv_color_hsv_t hsv
lv_point_t pos
uint8_t recolor
struct lv_colorwheel_t::[anonymous] knob
uint32_t last_click_time
uint32_t last_change_time
lv_point_t last_press_point
lv_colorwheel_mode_t mode
uint8_t mode_fixed