1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_objx/lv_roller.c

509 lines
18 KiB
C
Raw Normal View History

/**
* @file lv_roller.c
2018-06-19 09:49:58 +02:00
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_roller.h"
#if USE_LV_ROLLER != 0
#include "../lv_draw/lv_draw.h"
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_group.h"
#include "../lv_themes/lv_theme.h"
/*********************
* DEFINES
*********************/
2017-12-21 00:19:59 +01:00
#if USE_LV_ANIMATION
# ifndef LV_ROLLER_ANIM_TIME
# define LV_ROLLER_ANIM_TIME 200 /*ms*/
# endif
#else
# undef LV_ROLLER_ANIM_TIME
# define LV_ROLLER_ANIM_TIME 0 /*No animation*/
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2017-11-23 21:28:36 +01:00
static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_design_mode_t mode);
2017-11-05 22:37:03 +01:00
static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param);
static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param);
2018-06-19 09:49:58 +02:00
static void refr_position(lv_obj_t * roller, bool anim_en);
static void draw_bg(lv_obj_t * roller, const lv_area_t * mask);
/**********************
* STATIC VARIABLES
**********************/
2017-11-05 22:37:03 +01:00
static lv_signal_func_t ancestor_signal;
static lv_signal_func_t ancestor_scrl_signal;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a roller object
* @param par pointer to an object, it will be the parent of the new roller
* @param copy pointer to a roller object, if not NULL then the new object will be copied from it
* @return pointer to the created roller
*/
lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy)
{
2018-07-25 20:39:24 +02:00
LV_LOG_TRACE("roller create started");
2018-07-25 17:57:08 +02:00
/*Create the ancestor of roller*/
2018-06-19 09:49:58 +02:00
lv_obj_t * new_roller = lv_ddlist_create(par, copy);
2017-11-26 11:38:28 +01:00
lv_mem_assert(new_roller);
if(new_roller == NULL) return NULL;
2017-11-05 22:37:03 +01:00
if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_roller));
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_roller);
2018-06-19 09:49:58 +02:00
/*Allocate the roller type specific extended data*/
lv_roller_ext_t * ext = lv_obj_allocate_ext_attr(new_roller, sizeof(lv_roller_ext_t));
2017-11-26 11:38:28 +01:00
lv_mem_assert(ext);
if(ext == NULL) return NULL;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_roller, lv_roller_signal);
lv_obj_set_design_func(new_roller, lv_roller_design);
/*Init the new roller roller*/
if(copy == NULL) {
lv_obj_t * scrl = lv_page_get_scrl(new_roller);
lv_obj_set_drag(scrl, true); /*In ddlist is might be disabled*/
2017-12-11 23:11:15 +01:00
lv_page_set_rel_action(new_roller, NULL); /*Roller don't uses it (like ddlist)*/
lv_page_set_scrl_fit(new_roller, true, false); /*Height is specified directly*/
lv_ddlist_open(new_roller, false);
2017-12-21 00:19:59 +01:00
lv_ddlist_set_anim_time(new_roller, LV_ROLLER_ANIM_TIME);
2017-12-19 22:00:32 +01:00
lv_roller_set_visible_row_count(new_roller, 3);
2017-11-16 10:20:30 +01:00
lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER);
2017-11-05 22:37:03 +01:00
lv_obj_set_signal_func(scrl, lv_roller_scrl_signal);
/*Set the default styles*/
2018-06-19 09:49:58 +02:00
lv_theme_t * th = lv_theme_get_current();
if(th) {
lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->roller.bg);
lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->roller.sel);
} else {
/*Let the ddlist's style*/
lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/
}
}
/*Copy an existing roller*/
else {
lv_obj_t * scrl = lv_page_get_scrl(new_roller);
lv_ddlist_open(new_roller, false);
lv_obj_set_signal_func(scrl, lv_roller_scrl_signal);
lv_obj_refresh_style(new_roller); /*Refresh the style with new signal function*/
}
2018-06-19 09:49:58 +02:00
2018-07-25 20:39:24 +02:00
LV_LOG_INFO("roller created");
2018-07-25 17:57:08 +02:00
return new_roller;
}
/*=====================
* Setter functions
*====================*/
/**
* Set the selected option
* @param roller pointer to a roller object
* @param sel_opt id of the selected option (0 ... number of option - 1);
* @param anim_en true: set with animation; false set immediately
*/
2018-06-19 09:49:58 +02:00
void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, bool anim_en)
{
#if USE_LV_ANIMATION == 0
anim_en = false;
#endif
if(lv_roller_get_selected(roller) == sel_opt) return;
lv_ddlist_set_selected(roller, sel_opt);
refr_position(roller, anim_en);
}
2017-12-17 20:11:14 +01:00
/**
* Set the height to show the given number of rows (options)
* @param roller pointer to a roller object
* @param row_cnt number of desired visible rows
*/
2018-06-19 09:49:58 +02:00
void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt)
2017-12-17 20:11:14 +01:00
{
2018-06-19 09:49:58 +02:00
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
2017-12-17 20:11:14 +01:00
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
2018-02-09 12:40:00 +01:00
lv_ddlist_set_fix_height(roller, lv_font_get_height(style_label->text.font) * row_cnt + style_label->text.line_space * (row_cnt));
2017-12-17 20:11:14 +01:00
}
/**
* Set a style of a roller
* @param roller pointer to a roller object
* @param type which style should be set
* @param style pointer to a style
*/
2018-06-19 09:49:58 +02:00
void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, lv_style_t * style)
{
2018-06-19 09:49:58 +02:00
switch(type) {
case LV_ROLLER_STYLE_BG:
lv_obj_set_style(roller, style);
break;
2017-11-16 10:20:30 +01:00
case LV_ROLLER_STYLE_SEL:
lv_ddlist_set_style(roller, LV_DDLIST_STYLE_SEL, style);
break;
}
}
/*=====================
* Getter functions
*====================*/
/**
* Get the auto width set attribute
* @param roller pointer to a roller object
* @return true: auto size enabled; false: manual width settings enabled
*/
2018-06-19 09:49:58 +02:00
bool lv_roller_get_hor_fit(lv_obj_t * roller)
{
return lv_page_get_scrl_hor_fit(roller);
}
/**
* Get a style of a roller
* @param roller pointer to a roller object
* @param type which style should be get
* @return style pointer to a style
* */
2018-06-19 09:49:58 +02:00
lv_style_t * lv_roller_get_style(lv_obj_t * roller, lv_roller_style_t type)
{
2018-06-19 09:49:58 +02:00
switch(type) {
case LV_ROLLER_STYLE_BG:
return lv_obj_get_style(roller);
case LV_ROLLER_STYLE_SEL:
return lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SEL);
default:
return NULL;
}
/*To avoid warning*/
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the rollers
* @param roller pointer to an object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return true/false, depends on 'mode'
*/
2017-11-23 21:28:36 +01:00
static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_design_mode_t mode)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
2018-06-19 09:49:58 +02:00
return false;
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
2017-11-05 22:37:03 +01:00
draw_bg(roller, mask);
2018-06-19 09:49:58 +02:00
lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
2018-06-14 13:08:19 +02:00
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
2017-11-23 21:28:36 +01:00
const lv_font_t * font = style->text.font;
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
2018-02-09 12:40:00 +01:00
lv_coord_t font_h = lv_font_get_height(font);
2017-11-23 21:28:36 +01:00
lv_area_t rect_area;
2017-11-05 22:37:03 +01:00
rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2;
2018-07-06 17:12:06 +03:00
if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1 --; /*Compensate the two rounding error*/
rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1;
2017-11-05 22:37:03 +01:00
rect_area.x1 = roller->coords.x1;
rect_area.x2 = roller->coords.x2;
2018-06-14 13:08:19 +02:00
lv_draw_rect(&rect_area, mask, ext->ddlist.sel_style, opa_scale);
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
2018-06-19 09:49:58 +02:00
lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
2017-11-23 21:28:36 +01:00
const lv_font_t * font = style->text.font;
2018-02-09 12:40:00 +01:00
lv_coord_t font_h = lv_font_get_height(font);
2018-06-14 13:08:19 +02:00
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
2017-12-17 20:11:14 +01:00
/*Redraw the text on the selected area with a different color*/
2017-11-23 21:28:36 +01:00
lv_area_t rect_area;
rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2;
2018-07-06 17:12:06 +03:00
if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1 --; /*Compensate the two rounding error*/
rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1;
rect_area.x1 = roller->coords.x1;
rect_area.x2 = roller->coords.x2;
2017-11-23 21:28:36 +01:00
lv_area_t mask_sel;
bool area_ok;
area_ok = lv_area_intersect(&mask_sel, mask, &rect_area);
if(area_ok) {
2018-06-19 09:49:58 +02:00
lv_style_t * sel_style = lv_roller_get_style(roller, LV_ROLLER_STYLE_SEL);
lv_style_t new_style;
lv_style_copy(&new_style, style);
new_style.text.color = sel_style->text.color;
2017-11-21 10:35:57 +01:00
new_style.text.opa = sel_style->text.opa;
2018-06-14 13:08:19 +02:00
lv_draw_label(&ext->ddlist.label->coords, &mask_sel, &new_style, opa_scale,
2017-11-24 17:48:47 +01:00
lv_label_get_text(ext->ddlist.label), LV_TXT_FLAG_CENTER, NULL);
}
}
return true;
}
2017-11-05 22:37:03 +01:00
/**
* Signal function of the roller
* @param roller pointer to a roller object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param)
{
2017-12-02 20:43:50 +01:00
lv_res_t res = LV_RES_OK;
2017-11-05 22:37:03 +01:00
/*Don't let the drop down list to handle the control signals. It works differently*/
if(sign != LV_SIGNAL_CONTROLL && sign != LV_SIGNAL_FOCUS && sign != LV_SIGNAL_DEFOCUS) {
2018-06-19 09:49:58 +02:00
/* Include the ancient signal function */
res = ancestor_signal(roller, sign, param);
if(res != LV_RES_OK) return res;
}
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_obj_set_height(lv_page_get_scrl(roller),
2018-06-19 09:49:58 +02:00
lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller));
2017-11-16 10:20:30 +01:00
lv_obj_align(ext->ddlist.label, NULL, LV_ALIGN_CENTER, 0, 0);
lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id);
refr_position(roller, false);
} else if(sign == LV_SIGNAL_CORD_CHG) {
2017-11-28 16:15:13 +01:00
if(lv_obj_get_width(roller) != lv_area_get_width(param) ||
2018-06-19 09:49:58 +02:00
lv_obj_get_height(roller) != lv_area_get_height(param)) {
lv_ddlist_set_fix_height(roller, lv_obj_get_height(roller));
2017-11-05 22:37:03 +01:00
lv_obj_set_height(lv_page_get_scrl(roller),
2018-06-19 09:49:58 +02:00
lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller));
2017-11-16 10:20:30 +01:00
lv_obj_align(ext->ddlist.label, NULL, LV_ALIGN_CENTER, 0, 0);
lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id);
2017-11-05 22:37:03 +01:00
refr_position(roller, false);
}
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_FOCUS) {
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id;
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_DEFOCUS) {
/*Revert the original state*/
if(ext->ddlist.sel_opt_id != ext->ddlist.sel_opt_id_ori) {
ext->ddlist.sel_opt_id = ext->ddlist.sel_opt_id_ori;
refr_position(roller, true);
}
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_CONTROLL) {
char c = *((char *)param);
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) {
2018-06-19 09:49:58 +02:00
if(ext->ddlist.sel_opt_id + 1 < ext->ddlist.option_cnt) {
lv_roller_set_selected(roller, ext->ddlist.sel_opt_id + 1, true);
}
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) {
if(ext->ddlist.sel_opt_id > 0) {
lv_roller_set_selected(roller, ext->ddlist.sel_opt_id - 1, true);
}
} else if(c == LV_GROUP_KEY_ENTER) {
if(ext->ddlist.action) ext->ddlist.action(roller);
2018-06-19 09:49:58 +02:00
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Set the entered value as default*/
}
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_GET_TYPE) {
2018-02-28 15:37:41 +01:00
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_roller";
}
2017-11-05 22:37:03 +01:00
return res;
}
2017-09-23 22:14:31 +02:00
/**
* Signal function of the scrollable part of the roller.
* @param roller_scrl ointer to the scrollable part of roller (page)
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
2017-11-05 22:37:03 +01:00
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
2017-09-23 22:14:31 +02:00
*/
2017-11-05 22:37:03 +01:00
static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param)
{
2017-11-05 22:37:03 +01:00
lv_res_t res;
/* Include the ancient signal function */
2017-11-05 22:37:03 +01:00
res = ancestor_scrl_signal(roller_scrl, sign, param);
if(res != LV_RES_OK) return res;
lv_indev_t * indev = lv_indev_get_act();
int32_t id = -1;
lv_obj_t * roller = lv_obj_get_parent(roller_scrl);
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
2017-12-03 00:35:39 +01:00
if(ext->ddlist.label == NULL) return LV_RES_INV; /*On delete the ddlist signal deletes the label so nothing left to do here*/
2017-11-16 10:20:30 +01:00
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
2017-11-23 21:28:36 +01:00
const lv_font_t * font = style_label->text.font;
2018-02-09 12:40:00 +01:00
lv_coord_t font_h = lv_font_get_height(font);
if(sign == LV_SIGNAL_DRAG_END) {
/*If dragged then align the list to there be an element in the middle*/
2017-11-23 21:28:36 +01:00
lv_coord_t label_y1 = ext->ddlist.label->coords.y1 - roller->coords.y1;
lv_coord_t label_unit = font_h + style_label->text.line_space;
lv_coord_t mid = (roller->coords.y2 - roller->coords.y1) / 2;
id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit;
if(id < 0) id = 0;
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
2017-11-16 10:20:30 +01:00
ext->ddlist.sel_opt_id = id;
2018-01-16 15:35:35 +01:00
if(ext->ddlist.action) ext->ddlist.action(roller);
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_RELEASED) {
/*If picked an option by clicking then set it*/
if(!lv_indev_is_dragging(indev)) {
2017-11-23 21:28:36 +01:00
lv_point_t p;
lv_indev_get_point(indev, &p);
2017-11-16 10:20:30 +01:00
p.y = p.y - ext->ddlist.label->coords.y1;
id = p.y / (font_h + style_label->text.line_space);
2017-10-05 12:51:29 +02:00
if(id < 0) id = 0;
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
2017-11-16 10:20:30 +01:00
ext->ddlist.sel_opt_id = id;
2018-01-16 15:35:35 +01:00
if(ext->ddlist.action) ext->ddlist.action(roller);
2017-10-05 12:51:29 +02:00
}
}
2017-09-22 23:55:54 +02:00
/*Position the scrollable according to the new selected option*/
if(id != -1) {
refr_position(roller, true);
}
2017-11-05 22:37:03 +01:00
return res;
}
2017-11-05 22:37:03 +01:00
/**
* Draw a rectangle which has gradient on its top and bottom
* @param roller pointer to a roller object
* @param mask pointer to the current mask (from the design function)
*/
2018-06-19 09:49:58 +02:00
static void draw_bg(lv_obj_t * roller, const lv_area_t * mask)
2017-11-05 22:37:03 +01:00
{
2018-06-19 09:49:58 +02:00
lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
2017-11-23 21:28:36 +01:00
lv_area_t half_mask;
lv_area_t half_roller;
lv_coord_t h = lv_obj_get_height(roller);
2017-11-05 22:37:03 +01:00
bool union_ok;
2017-11-28 16:15:13 +01:00
lv_area_copy(&half_roller, &roller->coords);
2017-11-05 22:37:03 +01:00
half_roller.x1 -= roller->ext_size; /*Add ext size too (e.g. because of shadow draw) */
half_roller.x2 += roller->ext_size;
half_roller.y1 -= roller->ext_size;
half_roller.y2 = roller->coords.y1 + h / 2;
union_ok = lv_area_intersect(&half_mask, &half_roller, mask);
2017-11-05 22:37:03 +01:00
half_roller.x1 += roller->ext_size; /*Revert ext. size adding*/
half_roller.x2 -= roller->ext_size;
half_roller.y1 += roller->ext_size;
half_roller.y2 += style->body.radius;
if(union_ok) {
2018-06-14 13:08:19 +02:00
lv_draw_rect(&half_roller, &half_mask, style, lv_obj_get_opa_scale(roller));
2017-11-05 22:37:03 +01:00
}
half_roller.x1 -= roller->ext_size; /*Add ext size too (e.g. because of shadow draw) */
half_roller.x2 += roller->ext_size;
half_roller.y2 = roller->coords.y2 + roller->ext_size;
half_roller.y1 = roller->coords.y1 + h / 2;
if((h & 0x1) == 0) half_roller.y1++; /*With even height the pixels in the middle would be drawn twice*/
union_ok = lv_area_intersect(&half_mask, &half_roller, mask);
2017-11-05 22:37:03 +01:00
half_roller.x1 += roller->ext_size; /*Revert ext. size adding*/
half_roller.x2 -= roller->ext_size;
half_roller.y2 -= roller->ext_size;
half_roller.y1 -= style->body.radius;
2018-06-19 09:49:58 +02:00
if(union_ok) {
2017-11-23 21:28:36 +01:00
lv_color_t main_tmp = style->body.main_color;
lv_color_t grad_tmp = style->body.grad_color;
2017-11-05 22:37:03 +01:00
style->body.main_color = grad_tmp;
2017-11-20 14:26:18 +01:00
style->body.grad_color = main_tmp;
2018-06-19 09:49:58 +02:00
lv_draw_rect(&half_roller, &half_mask, style, lv_obj_get_opa_scale(roller));
style->body.main_color = main_tmp;
2017-11-20 14:26:18 +01:00
style->body.grad_color = grad_tmp;
2017-11-05 22:37:03 +01:00
}
}
2017-11-05 22:37:03 +01:00
/**
* Refresh the position of the roller. It uses the id stored in: ext->ddlist.selected_option_id
* @param roller pointer to a roller object
* @param anim_en true: refresh with animation; false: without animation
*/
2018-06-19 09:49:58 +02:00
static void refr_position(lv_obj_t * roller, bool anim_en)
2017-11-05 22:37:03 +01:00
{
#if USE_LV_ANIMATION == 0
anim_en = false;
#endif
2018-06-19 09:49:58 +02:00
lv_obj_t * roller_scrl = lv_page_get_scrl(roller);
2017-11-05 22:37:03 +01:00
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
2017-11-16 10:20:30 +01:00
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
2017-11-23 21:28:36 +01:00
const lv_font_t * font = style_label->text.font;
2018-02-09 12:40:00 +01:00
lv_coord_t font_h = lv_font_get_height(font);
2017-11-23 21:28:36 +01:00
lv_coord_t h = lv_obj_get_height(roller);
2017-11-16 10:20:30 +01:00
int32_t id = ext->ddlist.sel_opt_id;
2017-11-23 21:28:36 +01:00
lv_coord_t line_y1 = id * (font_h + style_label->text.line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1;
lv_coord_t new_y = - line_y1 + (h - font_h) / 2;
2017-11-05 22:37:03 +01:00
if(ext->ddlist.anim_time == 0 || anim_en == false) {
lv_obj_set_y(roller_scrl, new_y);
} else {
#if USE_LV_ANIMATION
2017-11-23 21:28:36 +01:00
lv_anim_t a;
2017-11-05 22:37:03 +01:00
a.var = roller_scrl;
a.start = lv_obj_get_y(roller_scrl);
a.end = new_y;
2017-11-23 21:28:36 +01:00
a.fp = (lv_anim_fp_t)lv_obj_set_y;
2017-12-17 01:54:09 +01:00
a.path = lv_anim_path_linear;
2017-11-05 22:37:03 +01:00
a.end_cb = NULL;
a.act_time = 0;
a.time = ext->ddlist.anim_time;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
2017-11-23 21:28:36 +01:00
lv_anim_create(&a);
2017-11-27 17:48:54 +01:00
#endif
2017-11-05 22:37:03 +01:00
}
}
#endif