色轮 (lv_colorwheel)

概述

顾名思义,色轮 允许用户选择颜色。可以分别选择颜色的色相 (Hue)、饱和度 (Saturation) 和亮度 (Value)。

长按对象时,色轮将切换到颜色的下一个参数(色相、饱和度或亮度)。双击将重置当前参数。

部件和样式

  • LV_PART_MAIN 仅使用 arc_width 设置色轮的宽度。

  • LV_PART_KNOB 一个绘制在当前值上的矩形(或圆形)。它使用所有矩形样式属性和填充,使其比弧线宽度更大。

用法

创建色轮

lv_colorwheel_create(parent, knob_recolor) 创建一个新的色轮。如果 knob_recolor=true,旋钮的背景颜色将设置为当前颜色。

设置颜色

可以使用 lv_colorwheel_set_hue/saturation/value(colorwheel, x) 分别手动设置颜色,也可以使用 lv_colorwheel_set_hsv(colorwheel, hsv)lv_colorwheel_set_color(colorwheel, rgb) 一次性设置所有颜色参数。

颜色模式

可以使用 lv_colorwheel_set_mode(colorwheel, LV_COLORWHEEL_MODE_HUE/SATURATION/VALUE) 手动选择当前颜色模式。

可以使用 lv_colorwheel_set_mode_fixed(colorwheel, true) 固定颜色模式(不随长按更改)。

事件

  • LV_EVENT_VALUE_CHANGED 当选择了新颜色时发送。

了解更多关于事件的信息。

按键

  • LV_KEY_UP, LV_KEY_RIGHT 将当前参数的值增加 1。

  • LV_KEY_DOWN, LV_KEY_LEFT 将当前参数的值减少 1。

  • LV_KEY_ENTER 长按将显示下一个模式。双击重置当前参数。

了解更多关于按键的信息。

示例

简单的颜色轮

C code  

 GitHub
#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 code  

 GitHub Simulator
cw = lv.colorwheel(lv.scr_act(), True)
cw.set_size(200, 200)
cw.center()


API

Typedefs

typedef uint8_t lv_colorwheel_mode_t

Enums

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 object 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 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