LVGL V8学习之colorwheel色轮
·
这一篇来研究下LVGL V8下colorwheel色轮的使用,这个色轮是HSV样式的,下面的代码通过创建色轮对象,然后添加对象事件处理,移动旋钮,显示对应的颜色和RGB值
还是通过codeblock来模拟代码的运行,代码如下:
// 事件回调函数
static void colorwheel_event_callback(lv_event_t * event)
{
if (event == NULL)
{
printf("[%s:%d] event is NULL\n", __FUNCTION__, __LINE__);
return ;
}
lv_event_code_t code = lv_event_get_code(event);
if (code == LV_EVENT_VALUE_CHANGED)
{
lv_obj_t *obj_colorwheel = lv_event_get_current_target(event);
lv_obj_t *obj_label = lv_event_get_user_data(event);
if (obj_label != NULL && obj_colorwheel != NULL)
{
lv_color_t color = lv_colorwheel_get_rgb(obj_colorwheel);
lv_label_set_text_fmt(obj_label, "Red:%d\n\nGreen:%d\n\nBlue:%d", color.ch.red, color.ch.green, color.ch.blue);
}
}
}
/*
创建一个HSV色轮colorwheel对象,沿色轮移动按钮显示对应的RGB值
*/
void lv_colorwheel_test()
{
lv_obj_t *obj_color_label = lv_label_create(lv_scr_act());
if (obj_color_label == NULL)
{
return ;
}
//lv_label_set_text(obj_color_label, "");
lv_obj_align(obj_color_label, LV_ALIGN_LEFT_MID, 100, 0);
lv_obj_t * obj_colorwheel = lv_colorwheel_create(lv_scr_act(), true);
if (obj_colorwheel != NULL)
{
//lv_obj_center(obj_colorwheel);
lv_obj_set_size(obj_colorwheel, 200, 200);
lv_obj_align(obj_colorwheel, LV_ALIGN_RIGHT_MID, -100, 0);
// 处理值改变事件LV_EVENT_VALUE_CHANGED
lv_obj_add_event_cb(obj_colorwheel, colorwheel_event_callback, LV_EVENT_VALUE_CHANGED, (void *)obj_color_label);
lv_color_t color = lv_colorwheel_get_rgb(obj_colorwheel);
lv_label_set_text_fmt(obj_color_label, "Red:%d\n\nGreen:%d\n\nBlue:%d", color.ch.red, color.ch.green, color.ch.blue);
}
}
运行效果:
更多推荐
已为社区贡献18条内容
所有评论(0)