mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
cpicker: add preview feature
This commit is contained in:
parent
e8625aaf65
commit
d4196c7534
@ -110,7 +110,9 @@ lv_obj_t * lv_cpicker_create(lv_obj_t * par, const lv_obj_t * copy)
|
|||||||
ext->indic.colored = 0;
|
ext->indic.colored = 0;
|
||||||
ext->color_mode = LV_CPICKER_COLOR_MODE_HUE;
|
ext->color_mode = LV_CPICKER_COLOR_MODE_HUE;
|
||||||
ext->color_mode_fixed = 0;
|
ext->color_mode_fixed = 0;
|
||||||
|
ext->preview = 0;
|
||||||
ext->last_click_time = 0;
|
ext->last_click_time = 0;
|
||||||
|
ext->last_change_time = 0;
|
||||||
|
|
||||||
/*The signal and design functions are not copied so set them here*/
|
/*The signal and design functions are not copied so set them here*/
|
||||||
lv_obj_set_signal_cb(new_cpicker, lv_cpicker_signal);
|
lv_obj_set_signal_cb(new_cpicker, lv_cpicker_signal);
|
||||||
@ -133,6 +135,7 @@ lv_obj_t * lv_cpicker_create(lv_obj_t * par, const lv_obj_t * copy)
|
|||||||
ext->type = copy_ext->type;
|
ext->type = copy_ext->type;
|
||||||
ext->color_mode = copy_ext->color_mode;
|
ext->color_mode = copy_ext->color_mode;
|
||||||
ext->color_mode_fixed = copy_ext->color_mode_fixed;
|
ext->color_mode_fixed = copy_ext->color_mode_fixed;
|
||||||
|
ext->preview = copy_ext->preview;
|
||||||
ext->hsv = copy_ext->hsv;
|
ext->hsv = copy_ext->hsv;
|
||||||
ext->indic.colored = copy_ext->indic.colored;
|
ext->indic.colored = copy_ext->indic.colored;
|
||||||
ext->indic.style = copy_ext->indic.style;
|
ext->indic.style = copy_ext->indic.style;
|
||||||
@ -314,6 +317,19 @@ void lv_cpicker_set_indic_colored(lv_obj_t * cpicker, bool en)
|
|||||||
invalidate_indic(cpicker);
|
invalidate_indic(cpicker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a color preview in the middle of the DISC type color picker
|
||||||
|
* @param cpicker pointer to colorpicker object
|
||||||
|
* @param en true: enable preview; false: disable preview
|
||||||
|
*/
|
||||||
|
void lv_cpicker_set_preview(lv_obj_t * cpicker, bool en)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(cpicker, LV_OBJX_NAME);
|
||||||
|
|
||||||
|
lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);
|
||||||
|
ext->preview = en ? 1 : 0;
|
||||||
|
lv_obj_invalidate(cpicker);
|
||||||
|
}
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@ -455,6 +471,21 @@ bool lv_cpicker_get_indic_colored(lv_obj_t * cpicker)
|
|||||||
return ext->indic.colored ? true : false;
|
return ext->indic.colored ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the preview is enabled or not
|
||||||
|
* @param cpicker pointer to colorpicker object
|
||||||
|
* @return en true: preview is enabled; false: preview is disabled
|
||||||
|
*/
|
||||||
|
bool lv_cpicker_get_preview(lv_obj_t * cpicker)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(cpicker, LV_OBJX_NAME);
|
||||||
|
|
||||||
|
lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);
|
||||||
|
|
||||||
|
return ext->preview ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@ -502,6 +533,7 @@ static bool lv_cpicker_design(lv_obj_t * cpicker, const lv_area_t * mask, lv_des
|
|||||||
|
|
||||||
static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale)
|
static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale)
|
||||||
{
|
{
|
||||||
|
lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);
|
||||||
int16_t start_angle = 0; /*Default*/
|
int16_t start_angle = 0; /*Default*/
|
||||||
int16_t end_angle = 360 - LV_CPICKER_DEF_QF; /*Default*/
|
int16_t end_angle = 360 - LV_CPICKER_DEF_QF; /*Default*/
|
||||||
|
|
||||||
@ -625,6 +657,18 @@ static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t
|
|||||||
area_mid.y2 -= style_main->line.width;
|
area_mid.y2 -= style_main->line.width;
|
||||||
|
|
||||||
lv_draw_rect(&area_mid, mask, &style, opa_scale);
|
lv_draw_rect(&area_mid, mask, &style, opa_scale);
|
||||||
|
|
||||||
|
if(ext->preview) {
|
||||||
|
lv_color_t color = lv_cpicker_get_color(cpicker);
|
||||||
|
style.body.main_color = color;
|
||||||
|
style.body.grad_color = color;
|
||||||
|
area_mid.x1 += style_main->line.width;
|
||||||
|
area_mid.y1 += style_main->line.width;
|
||||||
|
area_mid.x2 -= style_main->line.width;
|
||||||
|
area_mid.y2 -= style_main->line.width;
|
||||||
|
|
||||||
|
lv_draw_rect(&area_mid, mask, &style, opa_scale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_rect_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale)
|
static void draw_rect_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale)
|
||||||
|
@ -61,6 +61,7 @@ typedef struct {
|
|||||||
lv_cpicker_color_mode_t color_mode :2;
|
lv_cpicker_color_mode_t color_mode :2;
|
||||||
uint8_t color_mode_fixed :1;
|
uint8_t color_mode_fixed :1;
|
||||||
lv_cpicker_type_t type :1;
|
lv_cpicker_type_t type :1;
|
||||||
|
uint8_t preview :1;
|
||||||
} lv_cpicker_ext_t;
|
} lv_cpicker_ext_t;
|
||||||
|
|
||||||
/*Styles*/
|
/*Styles*/
|
||||||
@ -158,6 +159,13 @@ void lv_cpicker_set_color_mode_fixed(lv_obj_t * cpicker, bool fixed);
|
|||||||
*/
|
*/
|
||||||
void lv_cpicker_set_indic_colored(lv_obj_t * cpicker, bool en);
|
void lv_cpicker_set_indic_colored(lv_obj_t * cpicker, bool en);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a color preview in the middle of the DISC type color picker
|
||||||
|
* @param cpicker pointer to colorpicker object
|
||||||
|
* @param en true: enable preview; false: disable preview
|
||||||
|
*/
|
||||||
|
void lv_cpicker_set_preview(lv_obj_t * cpicker, bool en);
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@ -226,6 +234,13 @@ lv_color_t lv_cpicker_get_color(lv_obj_t * cpicker);
|
|||||||
*/
|
*/
|
||||||
bool lv_cpicker_get_indic_colored(lv_obj_t * cpicker);
|
bool lv_cpicker_get_indic_colored(lv_obj_t * cpicker);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the preview is enabled or not
|
||||||
|
* @param cpicker pointer to colorpicker object
|
||||||
|
* @return en true: preview is enabled; false: preview is disabled
|
||||||
|
*/
|
||||||
|
bool lv_cpicker_get_preview(lv_obj_t * cpicker);
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user