LVGL——色环部件

目录

一、部件组成

二、部件操作

1、创建

2、设置

3、获取

三、项目案例


一、部件组成

主体(LV_PART_MAIN

旋钮(LV_PART_KNOB)

二、部件操作

1、创建

lv_obj_t  *cw = lv_colorwheel_create( parent, knob_recolor );

2、设置

lv_colorwheel_set_rgb(cw, lv_color_hex(0xff0000));

lv_colorwheel_set_mode(cw, LV_COLORWHEEL_MODE_HUE/SATURATION/VALUE);	    /* 色相、饱和度、明度 */
lv_colorwheel_set_mode_fixed(cw, true);							    /* 固定色环模式 */

3、获取

lv_colorwheel_get_rgb(cw);

三、项目案例

#include "mygui.h"
#include "lvgl.h"
#include <stdio.h>
#include <stdbool.h>

/* 获取当前活动屏幕的宽高 */
#define scr_act_width() lv_obj_get_width(lv_scr_act())
#define scr_act_height() lv_obj_get_height(lv_scr_act())

lv_obj_t* obj;


static void colorwheel_event_cb(lv_event_t *e)
{
    lv_obj_t *target = lv_event_get_target(e);                                          /* 获取触发源 */

    lv_obj_set_style_bg_color(obj, lv_colorwheel_get_rgb(target), LV_PART_MAIN);        /* 设置基础对象背景颜色 */
}

void lv_colorwheel()
{
    /* 色环(用于选择颜色) */
    lv_obj_t *colorwheel = lv_colorwheel_create(lv_scr_act(), true);                    /* 创建色环 */
    lv_obj_set_size(colorwheel, scr_act_height() * 2 / 3, scr_act_height()* 2 / 3);     /* 设置大小 */
    lv_obj_center(colorwheel);                                                          /* 设置位置 */
    lv_obj_set_style_arc_width(colorwheel, scr_act_height() * 0.1, LV_PART_MAIN);       /* 设置色环圆弧宽度 */
    lv_colorwheel_set_mode_fixed(colorwheel, true);                                     /* 固定色环模式 */

    /* 基础对象(用于显示所选颜色) */
    obj = lv_obj_create(lv_scr_act());                                                  /* 创建基础对象 */
    lv_obj_set_size(obj, scr_act_height() / 3, scr_act_height() / 3);                   /* 设置大小 */
    lv_obj_align_to(obj, colorwheel, LV_ALIGN_CENTER, 0, 0);                            /* 设置位置 */
    lv_obj_set_style_radius(obj, LV_RADIUS_CIRCLE, LV_PART_MAIN);                       /* 设置圆角 */
    lv_obj_set_style_bg_color(obj, lv_colorwheel_get_rgb(colorwheel), LV_PART_MAIN);    /* 设置背景颜色 */
    lv_obj_add_event_cb(colorwheel, colorwheel_event_cb, LV_EVENT_VALUE_CHANGED, NULL); /* 设置色环事件回调 */
}


void my_gui(void)
{
    lv_colorwheel();
}