2017-09-03 16:01:51 +02:00
|
|
|
/**
|
|
|
|
* @file lv_roller.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-09-03 16:01:51 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_roller.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ROLLER != 0
|
2017-09-03 16:01:51 +02:00
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-09-03 16:01:51 +02:00
|
|
|
#include "../lv_draw/lv_draw.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_group.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-09-03 16:01:51 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_roller"
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2019-04-04 07:15:40 +02:00
|
|
|
#undef LV_ROLLER_DEF_ANIM_TIME
|
|
|
|
#define LV_ROLLER_DEF_ANIM_TIME 0 /*No animation*/
|
2017-12-21 00:19:59 +01:00
|
|
|
#endif
|
2017-09-03 16:01:51 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* 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);
|
2019-06-11 13:51:14 +02:00
|
|
|
static void refr_position(lv_obj_t * roller, lv_anim_enable_t animen);
|
2019-04-22 10:17:21 +02:00
|
|
|
static void refr_height(lv_obj_t * roller);
|
2019-03-17 04:32:37 +01:00
|
|
|
static void inf_normalize(void * roller_scrl);
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-22 08:45:07 +02:00
|
|
|
static void scroll_anim_ready_cb(lv_anim_t * a);
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2018-06-19 09:49:58 +02:00
|
|
|
static void draw_bg(lv_obj_t * roller, const lv_area_t * mask);
|
2017-09-03 16:01:51 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
|
|
|
static lv_signal_cb_t ancestor_scrl_signal;
|
2017-09-03 16:01:51 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* 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
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy)
|
2017-09-03 16:01:51 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("roller create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-09-03 16:01:51 +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);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(new_roller);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(new_roller == NULL) return NULL;
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_cb(lv_page_get_scrl(new_roller));
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_roller);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2017-09-03 16:01:51 +02:00
|
|
|
/*Allocate the roller type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_roller_ext_t * ext = lv_obj_allocate_ext_attr(new_roller, sizeof(lv_roller_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext == NULL) return NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->ddlist.draw_arrow = 0; /*Do not draw arrow by default*/
|
2018-12-05 11:46:37 +02:00
|
|
|
|
2017-09-03 16:01:51 +02:00
|
|
|
/*The signal and design functions are not copied so set them here*/
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_roller, lv_roller_signal);
|
|
|
|
lv_obj_set_design_cb(new_roller, lv_roller_design);
|
2017-09-03 16:01:51 +02:00
|
|
|
|
|
|
|
/*Init the new roller roller*/
|
|
|
|
if(copy == NULL) {
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(new_roller);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_drag(scrl, true); /*In ddlist it might be disabled*/
|
2019-04-22 10:17:21 +02:00
|
|
|
lv_page_set_scrl_fit2(new_roller, LV_FIT_TIGHT, LV_FIT_NONE); /*Height is specified directly*/
|
2017-10-26 21:20:10 +02:00
|
|
|
lv_ddlist_open(new_roller, false);
|
2019-04-04 07:07:17 +02:00
|
|
|
lv_ddlist_set_anim_time(new_roller, LV_ROLLER_DEF_ANIM_TIME);
|
2019-02-26 16:07:40 +01:00
|
|
|
lv_ddlist_set_stay_open(new_roller, true);
|
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
|
|
|
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(scrl, lv_roller_scrl_signal);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
|
|
|
/*Set the default styles*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_theme_t * th = lv_theme_get_current();
|
2017-11-16 15:32:33 +01:00
|
|
|
if(th) {
|
2019-02-11 09:35:06 +01:00
|
|
|
lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->style.roller.bg);
|
|
|
|
lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->style.roller.sel);
|
2017-11-16 15:32:33 +01:00
|
|
|
} else {
|
2019-03-15 22:51:49 +01:00
|
|
|
/*Refresh the roller's style*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/
|
2017-11-16 15:32:33 +01:00
|
|
|
}
|
2017-09-03 16:01:51 +02:00
|
|
|
}
|
|
|
|
/*Copy an existing roller*/
|
|
|
|
else {
|
2019-03-17 04:32:37 +01:00
|
|
|
lv_roller_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2019-06-27 07:16:15 +02:00
|
|
|
ext->mode = copy_ext->mode;
|
2019-03-17 04:32:37 +01:00
|
|
|
|
2017-11-06 16:27:00 +01:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(new_roller);
|
|
|
|
lv_ddlist_open(new_roller, false);
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(scrl, lv_roller_scrl_signal);
|
2017-09-03 16:01:51 +02:00
|
|
|
|
2019-03-15 22:51:49 +01:00
|
|
|
/*Refresh the roller's style*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_refresh_style(new_roller); /*Refresh the style with new signal function*/
|
2017-09-03 16:01:51 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("roller created");
|
2018-07-25 20:39:24 +02:00
|
|
|
|
2017-09-03 16:01:51 +02:00
|
|
|
return new_roller;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2019-03-17 04:32:37 +01:00
|
|
|
/**
|
|
|
|
* Set the options on a roller
|
|
|
|
* @param roller pointer to roller object
|
|
|
|
* @param options a string with '\n' separated options. E.g. "One\nTwo\nThree"
|
2019-06-25 15:14:47 +02:00
|
|
|
* @param mode `LV_ROLLER_MODE_NORMAL` or `LV_ROLLER_MODE_INFINITE`
|
2019-03-17 04:32:37 +01:00
|
|
|
*/
|
2019-06-25 15:14:47 +02:00
|
|
|
void lv_roller_set_options(lv_obj_t * roller, const char * options, lv_roller_mode_t mode)
|
2019-03-17 04:32:37 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_STR(options);
|
|
|
|
|
2019-03-17 04:32:37 +01:00
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
|
|
|
|
2019-06-25 15:14:47 +02:00
|
|
|
if(mode == LV_ROLLER_MODE_NORMAL) {
|
|
|
|
ext->mode = LV_ROLLER_MODE_NORMAL;
|
2019-03-17 04:32:37 +01:00
|
|
|
lv_ddlist_set_options(roller, options);
|
2019-04-22 10:17:21 +02:00
|
|
|
|
|
|
|
/* Make sure the roller's height and the scrollable's height is refreshed.
|
|
|
|
* They are refreshed in `LV_SIGNAL_COORD_CHG` but if the new options has the same width
|
|
|
|
* that signal won't be called. (It called because LV_FIT_TIGHT hor fit)*/
|
|
|
|
refr_height(roller);
|
2019-03-17 04:32:37 +01:00
|
|
|
} else {
|
2019-06-25 15:14:47 +02:00
|
|
|
ext->mode = LV_ROLLER_MODE_INIFINITE;
|
2019-03-17 04:32:37 +01:00
|
|
|
|
|
|
|
uint32_t opt_len = strlen(options) + 1; /*+1 to add '\n' after option lists*/
|
|
|
|
char * opt_extra = lv_mem_alloc(opt_len * LV_ROLLER_INF_PAGES);
|
|
|
|
uint8_t i;
|
|
|
|
for(i = 0; i < LV_ROLLER_INF_PAGES; i++) {
|
|
|
|
strcpy(&opt_extra[opt_len * i], options);
|
|
|
|
opt_extra[opt_len * (i + 1) - 1] = '\n';
|
|
|
|
}
|
|
|
|
opt_extra[opt_len * LV_ROLLER_INF_PAGES - 1] = '\0';
|
|
|
|
lv_ddlist_set_options(roller, opt_extra);
|
|
|
|
lv_mem_free(opt_extra);
|
|
|
|
|
2019-04-22 10:17:21 +02:00
|
|
|
/* Make sure the roller's height and the scrollable's height is refreshed.
|
|
|
|
* They are refreshed in `LV_SIGNAL_COORD_CHG` but if the new options has the same width
|
|
|
|
* that signal won't be called. (It called because LV_FIT_TIGHT hor fit)*/
|
|
|
|
refr_height(roller);
|
|
|
|
|
2019-03-17 04:32:37 +01:00
|
|
|
uint16_t real_id_cnt = ext->ddlist.option_cnt / LV_ROLLER_INF_PAGES;
|
2019-04-22 10:17:21 +02:00
|
|
|
lv_roller_set_selected(roller, ((LV_ROLLER_INF_PAGES / 2) + 1) * real_id_cnt, false); /*Select the middle page*/
|
2019-03-17 04:32:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 11:46:37 +02:00
|
|
|
/**
|
|
|
|
* Set the align of the roller's options (left or center)
|
|
|
|
* @param roller - pointer to a roller object
|
|
|
|
* @param align - one of lv_label_align_t values (left, right, center)
|
|
|
|
*/
|
|
|
|
void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2018-12-05 11:46:37 +02:00
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
2019-08-16 16:43:05 +02:00
|
|
|
|
|
|
|
lv_obj_t * label = ext->ddlist.label;
|
|
|
|
|
|
|
|
if(label == NULL) return; /*Probably the roller is being deleted if the label is NULL.*/
|
|
|
|
lv_label_set_align(label, align);
|
|
|
|
|
|
|
|
switch(lv_label_get_align(label)) {
|
|
|
|
case LV_LABEL_ALIGN_LEFT: lv_obj_align(label, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0); break;
|
|
|
|
case LV_LABEL_ALIGN_CENTER: lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); break;
|
|
|
|
case LV_LABEL_ALIGN_RIGHT: lv_obj_align(label, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); break;
|
|
|
|
}
|
2018-12-05 11:46:37 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 16:27:00 +01:00
|
|
|
/**
|
|
|
|
* Set the selected option
|
|
|
|
* @param roller pointer to a roller object
|
|
|
|
* @param sel_opt id of the selected option (0 ... number of option - 1);
|
2019-06-11 13:51:14 +02:00
|
|
|
* @param anim_en LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately
|
2017-09-03 16:01:51 +02:00
|
|
|
*/
|
2019-06-11 13:51:14 +02:00
|
|
|
void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, lv_anim_enable_t anim)
|
2017-11-06 16:27:00 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2019-06-11 13:51:14 +02:00
|
|
|
anim = LV_ANIM_OFF;
|
2018-03-01 12:21:49 +01:00
|
|
|
#endif
|
2018-05-16 23:09:30 +02:00
|
|
|
|
|
|
|
if(lv_roller_get_selected(roller) == sel_opt) return;
|
|
|
|
|
2017-11-06 16:27:00 +01:00
|
|
|
lv_ddlist_set_selected(roller, sel_opt);
|
2019-06-11 13:51:14 +02:00
|
|
|
refr_position(roller, anim);
|
2017-11-06 16:27:00 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
|
|
|
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
|
|
|
|
uint8_t n_line_space = (row_cnt > 1) ? row_cnt - 1 : 1;
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_ddlist_set_fix_height(roller, lv_font_get_line_height(style_label->text.font) * row_cnt +
|
2019-04-04 07:15:40 +02:00
|
|
|
style_label->text.line_space * n_line_space);
|
2017-12-17 20:11:14 +01:00
|
|
|
}
|
2018-12-05 11:46:37 +02:00
|
|
|
|
2017-11-15 15:50:33 +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
|
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, const lv_style_t * style)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_ROLLER_STYLE_BG: lv_obj_set_style(roller, style); break;
|
|
|
|
case LV_ROLLER_STYLE_SEL: lv_ddlist_set_style(roller, LV_DDLIST_STYLE_SEL, style); break;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-03 16:01:51 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2019-03-17 04:32:37 +01:00
|
|
|
/**
|
|
|
|
* Get the id of the selected option
|
|
|
|
* @param roller pointer to a roller object
|
|
|
|
* @return id of the selected option (0 ... number of option - 1);
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
uint16_t lv_roller_get_selected(const lv_obj_t * roller)
|
2019-03-17 04:32:37 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2019-03-17 04:32:37 +01:00
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
2019-06-25 15:14:47 +02:00
|
|
|
if(ext->mode == LV_ROLLER_MODE_INIFINITE) {
|
2019-03-17 04:32:37 +01:00
|
|
|
uint16_t real_id_cnt = ext->ddlist.option_cnt / LV_ROLLER_INF_PAGES;
|
|
|
|
return lv_ddlist_get_selected(roller) % real_id_cnt;
|
|
|
|
} else {
|
|
|
|
return lv_ddlist_get_selected(roller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 11:46:37 +02:00
|
|
|
/**
|
|
|
|
* Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER
|
|
|
|
* @param roller pointer to a roller object
|
|
|
|
* @return LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER
|
|
|
|
*/
|
|
|
|
lv_label_align_t lv_roller_get_align(const lv_obj_t * roller)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2018-12-05 11:46:37 +02:00
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
|
|
|
LV_ASSERT_MEM(ext->ddlist.label);
|
2018-12-05 11:46:37 +02:00
|
|
|
return lv_label_get_align(ext->ddlist.label);
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:27:00 +01:00
|
|
|
/**
|
|
|
|
* Get the auto width set attribute
|
|
|
|
* @param roller pointer to a roller object
|
|
|
|
* @return true: auto size enabled; false: manual width settings enabled
|
2017-09-03 16:01:51 +02:00
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
bool lv_roller_get_hor_fit(const lv_obj_t * roller)
|
2017-11-06 16:27:00 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
return lv_page_get_scrl_fit_left(roller);
|
2017-11-06 16:27:00 +01:00
|
|
|
}
|
2017-09-03 16:01:51 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* */
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * lv_roller_get_style(const lv_obj_t * roller, lv_roller_style_t type)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(roller, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
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;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
2018-11-08 22:39:08 +08:00
|
|
|
/*To avoid warning*/
|
|
|
|
return NULL;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
2017-09-03 16:01:51 +02:00
|
|
|
/**********************
|
|
|
|
* 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)
|
2017-09-03 16:01:51 +02:00
|
|
|
{
|
|
|
|
/*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;
|
2017-09-03 16:01:51 +02:00
|
|
|
}
|
|
|
|
/*Draw the object*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
2017-11-05 22:37:03 +01:00
|
|
|
draw_bg(roller, mask);
|
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
|
|
|
|
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
|
|
|
|
const lv_font_t * font = style->text.font;
|
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_area_t rect_area;
|
2019-06-06 06:05:40 +02:00
|
|
|
rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2;
|
|
|
|
if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/
|
2018-06-21 22:15:19 +02:00
|
|
|
rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1;
|
2019-06-27 07:16:15 +02:00
|
|
|
lv_area_t roller_coords;
|
|
|
|
lv_obj_get_coords(roller, &roller_coords);
|
|
|
|
lv_obj_get_inner_coords(roller, &roller_coords);
|
2019-06-01 21:37:25 -04:00
|
|
|
|
|
|
|
rect_area.x1 = roller_coords.x1;
|
|
|
|
rect_area.x2 = roller_coords.x2;
|
2017-09-03 16:01:51 +02:00
|
|
|
|
2018-06-14 13:08:19 +02:00
|
|
|
lv_draw_rect(&rect_area, mask, ext->ddlist.sel_style, opa_scale);
|
2017-09-03 16:01:51 +02:00
|
|
|
}
|
|
|
|
/*Post draw when the children are drawn*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG);
|
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
|
|
|
const lv_font_t * font = style->text.font;
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_opa_t opa_scale = lv_obj_get_opa_scale(roller);
|
2017-12-17 20:11:14 +01:00
|
|
|
|
2017-11-15 22:23:17 +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;
|
2019-06-06 06:05:40 +02:00
|
|
|
rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2;
|
|
|
|
if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/
|
2018-06-21 22:15:19 +02:00
|
|
|
rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1;
|
2017-11-15 22:23:17 +01:00
|
|
|
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;
|
2017-11-15 22:23:17 +01:00
|
|
|
bool area_ok;
|
2018-07-17 16:40:52 +02:00
|
|
|
area_ok = lv_area_intersect(&mask_sel, mask, &rect_area);
|
2017-11-15 22:23:17 +01:00
|
|
|
if(area_ok) {
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * sel_style = lv_roller_get_style(roller, LV_ROLLER_STYLE_SEL);
|
2017-11-15 22:23:17 +01:00
|
|
|
lv_style_t new_style;
|
2018-12-05 11:46:37 +02:00
|
|
|
lv_txt_flag_t txt_align = LV_TXT_FLAG_NONE;
|
|
|
|
|
|
|
|
{
|
|
|
|
lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label);
|
|
|
|
|
|
|
|
if(LV_LABEL_ALIGN_CENTER == label_align) {
|
|
|
|
txt_align |= LV_TXT_FLAG_CENTER;
|
|
|
|
} else if(LV_LABEL_ALIGN_RIGHT == label_align) {
|
|
|
|
txt_align |= LV_TXT_FLAG_RIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 22:23:17 +01:00
|
|
|
lv_style_copy(&new_style, style);
|
|
|
|
new_style.text.color = sel_style->text.color;
|
2019-04-04 07:15:40 +02: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,
|
2019-06-14 14:57:59 +02:00
|
|
|
lv_label_get_text(ext->ddlist.label), txt_align, NULL, -1, -1, NULL);
|
2017-11-15 22:23:17 +01:00
|
|
|
}
|
2017-09-03 16:01:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_res_t res = LV_RES_OK;
|
2017-11-05 22:37:03 +01:00
|
|
|
|
2017-11-18 00:18:19 +01:00
|
|
|
/*Don't let the drop down list to handle the control signals. It works differently*/
|
2019-03-19 07:15:00 +01:00
|
|
|
if(sign != LV_SIGNAL_CONTROL && sign != LV_SIGNAL_FOCUS && sign != LV_SIGNAL_DEFOCUS) {
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Include the ancient signal function */
|
2017-11-18 00:18:19 +01:00
|
|
|
res = ancestor_signal(roller, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
|
|
|
}
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2017-11-07 17:00:55 +01:00
|
|
|
|
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
2018-12-05 11:46:37 +02:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
if(sign == LV_SIGNAL_STYLE_CHG) {
|
2019-04-22 10:17:21 +02:00
|
|
|
refr_height(roller);
|
2019-03-24 07:16:13 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
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) ||
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_get_height(roller) != lv_area_get_height(param)) {
|
2017-11-07 17:00:55 +01:00
|
|
|
|
2019-04-22 10:17:21 +02:00
|
|
|
refr_height(roller);
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-12 23:10:54 +02:00
|
|
|
lv_anim_del(lv_page_get_scrl(roller), (lv_anim_exec_xcb_t)lv_obj_set_y);
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2017-11-16 10:20:30 +01:00
|
|
|
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) {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_group_t * g = lv_obj_get_group(roller);
|
|
|
|
bool editing = lv_group_get_editing(g);
|
2019-03-29 16:10:18 +01:00
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
|
2018-09-24 22:59:48 +02:00
|
|
|
|
|
|
|
/*Encoders need special handling*/
|
|
|
|
if(indev_type == LV_INDEV_TYPE_ENCODER) {
|
|
|
|
/*In navigate mode revert the original value*/
|
|
|
|
if(!editing) {
|
|
|
|
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-09-24 00:35:19 +02:00
|
|
|
}
|
2018-09-24 22:59:48 +02:00
|
|
|
/*Save the current state when entered to edit mode*/
|
|
|
|
else {
|
|
|
|
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id;
|
|
|
|
}
|
|
|
|
} else {
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Save the current value. Used to revert this state if
|
|
|
|
ENER wont't be pressed*/
|
2018-09-24 00:35:19 +02:00
|
|
|
}
|
2019-02-18 12:17:56 -05:00
|
|
|
#endif
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_DEFOCUS) {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-03-01 12:21:49 +01:00
|
|
|
/*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);
|
|
|
|
}
|
2019-02-18 12:17:56 -05:00
|
|
|
#endif
|
2019-03-19 07:15:00 +01:00
|
|
|
} else if(sign == LV_SIGNAL_CONTROL) {
|
2018-06-19 09:49:58 +02:00
|
|
|
char c = *((char *)param);
|
2019-04-08 14:36:20 +02:00
|
|
|
if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) {
|
2018-06-19 09:49:58 +02:00
|
|
|
if(ext->ddlist.sel_opt_id + 1 < ext->ddlist.option_cnt) {
|
2019-06-06 06:05:40 +02:00
|
|
|
uint16_t ori_id = ext->ddlist.sel_opt_id_ori; /*lv_roller_set_selceted will overwrite this*/
|
2017-11-18 00:18:19 +01:00
|
|
|
lv_roller_set_selected(roller, ext->ddlist.sel_opt_id + 1, true);
|
2019-03-24 07:16:13 +01:00
|
|
|
ext->ddlist.sel_opt_id_ori = ori_id;
|
2017-11-18 00:18:19 +01:00
|
|
|
}
|
2019-04-08 14:36:20 +02:00
|
|
|
} else if(c == LV_KEY_LEFT || c == LV_KEY_UP) {
|
2017-11-18 00:18:19 +01:00
|
|
|
if(ext->ddlist.sel_opt_id > 0) {
|
2019-06-06 06:05:40 +02:00
|
|
|
uint16_t ori_id = ext->ddlist.sel_opt_id_ori; /*lv_roller_set_selceted will overwrite this*/
|
2017-11-18 00:18:19 +01:00
|
|
|
lv_roller_set_selected(roller, ext->ddlist.sel_opt_id - 1, true);
|
2019-03-24 07:16:13 +01:00
|
|
|
ext->ddlist.sel_opt_id_ori = ori_id;
|
2017-11-18 00:18:19 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
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-09-03 16:01:51 +02:00
|
|
|
{
|
2017-11-05 22:37:03 +01:00
|
|
|
lv_res_t res;
|
2017-09-03 16:01:51 +02:00
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
2017-11-05 22:37:03 +01:00
|
|
|
res = ancestor_scrl_signal(roller_scrl, sign, param);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
|
|
|
int32_t id = -1;
|
|
|
|
lv_obj_t * roller = lv_obj_get_parent(roller_scrl);
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
2017-12-03 00:35:39 +01:00
|
|
|
|
2019-04-04 07:15:40 +02: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-12-03 00:35:39 +01:00
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
|
|
|
|
const lv_font_t * font = style_label->text.font;
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2017-11-07 17:00:55 +01:00
|
|
|
|
|
|
|
if(sign == LV_SIGNAL_DRAG_END) {
|
2019-08-16 13:43:28 +02:00
|
|
|
/*If dragged then align the list to have an element in the middle*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t label_y1 = ext->ddlist.label->coords.y1 - roller->coords.y1;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t label_unit = font_h + style_label->text.line_space;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t mid = (roller->coords.y2 - roller->coords.y1) / 2;
|
2019-05-04 07:53:31 +02:00
|
|
|
|
|
|
|
id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit;
|
2019-03-17 04:32:37 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
if(id < 0) id = 0;
|
|
|
|
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
|
2019-03-17 04:32:37 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->ddlist.sel_opt_id = id;
|
2019-03-17 04:32:37 +01:00
|
|
|
ext->ddlist.sel_opt_id_ori = id;
|
2019-04-04 07:15:40 +02:00
|
|
|
res = lv_event_send(roller, LV_EVENT_VALUE_CHANGED, &id);
|
2019-03-07 00:42:08 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2019-05-04 07:53:31 +02:00
|
|
|
}
|
|
|
|
/*If picked an option by clicking then set it*/
|
|
|
|
else if(sign == LV_SIGNAL_RELEASED) {
|
2017-11-07 17:00:55 +01:00
|
|
|
if(!lv_indev_is_dragging(indev)) {
|
2019-03-24 07:16:13 +01:00
|
|
|
id = ext->ddlist.sel_opt_id;
|
2019-03-12 19:20:23 +01:00
|
|
|
#if LV_USE_GROUP
|
2019-05-04 07:53:31 +02:00
|
|
|
/*In edit mode go to navigate mode if an option is selected*/
|
2019-03-12 19:20:23 +01:00
|
|
|
lv_group_t * g = lv_obj_get_group(roller);
|
2019-04-04 07:15:40 +02:00
|
|
|
bool editing = lv_group_get_editing(g);
|
2019-06-06 06:05:40 +02:00
|
|
|
if(editing) lv_group_set_editing(g, false);
|
2019-03-12 19:20:23 +01:00
|
|
|
#endif
|
2017-10-05 12:51:29 +02:00
|
|
|
}
|
2019-06-06 06:05:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_PRESSED) {
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-12 23:10:54 +02:00
|
|
|
lv_anim_del(roller_scrl, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2019-05-04 07:53:31 +02:00
|
|
|
}
|
2017-09-22 23:55:54 +02:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/*Position the scrollable according to the new selected option*/
|
2018-11-08 22:39:08 +08:00
|
|
|
if(id != -1) {
|
2017-11-07 17:00:55 +01:00
|
|
|
refr_position(roller, true);
|
2017-09-03 16:01:51 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 22:37:03 +01:00
|
|
|
return res;
|
2017-09-03 16:01:51 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-04-11 19:59:55 +08:00
|
|
|
const 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
|
|
|
|
2019-04-11 06:26:41 +02:00
|
|
|
half_roller.x1 -= roller->ext_draw_pad; /*Add ext size too (e.g. because of shadow draw) */
|
|
|
|
half_roller.x2 += roller->ext_draw_pad;
|
|
|
|
half_roller.y1 -= roller->ext_draw_pad;
|
2017-11-05 22:37:03 +01:00
|
|
|
half_roller.y2 = roller->coords.y1 + h / 2;
|
|
|
|
|
2018-07-17 16:40:52 +02:00
|
|
|
union_ok = lv_area_intersect(&half_mask, &half_roller, mask);
|
2017-11-05 22:37:03 +01:00
|
|
|
|
2019-04-11 06:26:41 +02:00
|
|
|
half_roller.x1 += roller->ext_draw_pad; /*Revert ext. size adding*/
|
|
|
|
half_roller.x2 -= roller->ext_draw_pad;
|
|
|
|
half_roller.y1 += roller->ext_draw_pad;
|
2017-11-05 22:37:03 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-04-11 06:26:41 +02:00
|
|
|
half_roller.x1 -= roller->ext_draw_pad; /*Add ext size too (e.g. because of shadow draw) */
|
|
|
|
half_roller.x2 += roller->ext_draw_pad;
|
|
|
|
half_roller.y2 = roller->coords.y2 + roller->ext_draw_pad;
|
2017-11-05 22:37:03 +01:00
|
|
|
half_roller.y1 = roller->coords.y1 + h / 2;
|
2019-06-06 06:05:40 +02:00
|
|
|
if((h & 0x1) == 0) half_roller.y1++; /*With even height the pixels in the middle would be drawn twice*/
|
2017-11-05 22:37:03 +01:00
|
|
|
|
2018-07-17 16:40:52 +02:00
|
|
|
union_ok = lv_area_intersect(&half_mask, &half_roller, mask);
|
2017-11-05 22:37:03 +01:00
|
|
|
|
2019-04-11 06:26:41 +02:00
|
|
|
half_roller.x1 += roller->ext_draw_pad; /*Revert ext. size adding*/
|
|
|
|
half_roller.x2 -= roller->ext_draw_pad;
|
|
|
|
half_roller.y2 -= roller->ext_draw_pad;
|
2017-11-05 22:37:03 +01:00
|
|
|
half_roller.y1 -= style->body.radius;
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
if(union_ok) {
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_style_t style_tmp;
|
|
|
|
memcpy(&style_tmp, style, sizeof(lv_style_t));
|
|
|
|
style_tmp.body.main_color = style->body.grad_color;
|
|
|
|
style_tmp.body.grad_color = style->body.main_color;
|
|
|
|
lv_draw_rect(&half_roller, &half_mask, &style_tmp, lv_obj_get_opa_scale(roller));
|
2017-11-05 22:37:03 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-03 16:01:51 +02: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
|
2019-06-19 00:35:35 +02:00
|
|
|
* @param anim_en LV_ANIM_ON: refresh with animation; LV_ANOM_OFF: without animation
|
2017-11-05 22:37:03 +01:00
|
|
|
*/
|
2019-06-19 00:35:35 +02:00
|
|
|
static void refr_position(lv_obj_t * roller, lv_anim_enable_t anim_en)
|
2017-11-05 22:37:03 +01:00
|
|
|
{
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2019-06-19 00:35:35 +02:00
|
|
|
anim_en = LV_ANIM_OFF;
|
2018-03-01 12:21:49 +01:00
|
|
|
#endif
|
2019-06-19 00:35:35 +02:00
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_obj_t * roller_scrl = lv_page_get_scrl(roller);
|
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
|
|
|
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
|
|
|
|
const lv_font_t * font = style_label->text.font;
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_coord_t h = lv_obj_get_height(roller);
|
2019-06-27 07:16:15 +02:00
|
|
|
uint16_t anim_time = lv_roller_get_anim_time(roller);
|
2019-03-17 04:32:37 +01:00
|
|
|
|
|
|
|
/* Normally the animtaion's `end_cb` sets correct position of the roller is infinite.
|
|
|
|
* But without animations do it manually*/
|
2019-06-19 00:35:35 +02:00
|
|
|
if(anim_en == LV_ANIM_OFF || anim_time == 0) {
|
2019-03-17 04:32:37 +01:00
|
|
|
inf_normalize(roller_scrl);
|
|
|
|
}
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
int32_t id = ext->ddlist.sel_opt_id;
|
|
|
|
lv_coord_t line_y1 =
|
|
|
|
id * (font_h + style_label->text.line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t new_y = -line_y1 + (h - font_h) / 2;
|
2017-11-05 22:37:03 +01:00
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
if(anim_en == LV_ANIM_OFF || anim_time == 0) {
|
2017-11-05 22:37:03 +01:00
|
|
|
lv_obj_set_y(roller_scrl, new_y);
|
|
|
|
} else {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.var = roller_scrl;
|
|
|
|
a.start = lv_obj_get_y(roller_scrl);
|
|
|
|
a.end = new_y;
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_y;
|
2019-04-22 08:45:07 +02:00
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = scroll_anim_ready_cb;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.act_time = 0;
|
2019-06-19 00:35:35 +02:00
|
|
|
a.time = anim_time;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.playback = 0;
|
2017-11-05 22:37:03 +01:00
|
|
|
a.playback_pause = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2017-09-03 16:01:51 +02:00
|
|
|
|
2019-04-22 10:17:21 +02:00
|
|
|
/**
|
|
|
|
* Refresh the height of the roller and the scrolable
|
|
|
|
* @param roller pointer to roller
|
|
|
|
*/
|
|
|
|
static void refr_height(lv_obj_t * roller)
|
|
|
|
{
|
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
|
|
|
lv_align_t obj_align = LV_ALIGN_IN_LEFT_MID;
|
|
|
|
if(ext->ddlist.label) {
|
|
|
|
lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label);
|
|
|
|
if(LV_LABEL_ALIGN_CENTER == label_align)
|
|
|
|
obj_align = LV_ALIGN_CENTER;
|
|
|
|
else if(LV_LABEL_ALIGN_RIGHT == label_align)
|
|
|
|
obj_align = LV_ALIGN_IN_RIGHT_MID;
|
|
|
|
}
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_height(lv_page_get_scrl(roller), lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller));
|
2019-04-22 10:17:21 +02:00
|
|
|
lv_obj_align(ext->ddlist.label, NULL, obj_align, 0, 0);
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-12 23:10:54 +02:00
|
|
|
lv_anim_del(lv_page_get_scrl(roller), (lv_anim_exec_xcb_t)lv_obj_set_y);
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2019-04-22 10:17:21 +02:00
|
|
|
lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id);
|
|
|
|
}
|
|
|
|
|
2019-03-17 04:32:37 +01:00
|
|
|
/**
|
|
|
|
* Set the middle page for the roller if inifinte is enabled
|
2019-04-09 16:18:04 -04:00
|
|
|
* @param scrl pointer to the roller's scrollable (lv_obj_t *)
|
2019-03-17 04:32:37 +01:00
|
|
|
*/
|
2019-04-09 16:18:04 -04:00
|
|
|
static void inf_normalize(void * scrl)
|
2019-03-17 04:32:37 +01:00
|
|
|
{
|
2019-04-10 08:40:52 +02:00
|
|
|
lv_obj_t * roller_scrl = (lv_obj_t *)scrl;
|
|
|
|
lv_obj_t * roller = lv_obj_get_parent(roller_scrl);
|
|
|
|
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
2019-03-17 04:32:37 +01:00
|
|
|
|
2019-06-25 15:14:47 +02:00
|
|
|
if(ext->mode == LV_ROLLER_MODE_INIFINITE) {
|
2019-03-17 04:32:37 +01:00
|
|
|
uint16_t real_id_cnt = ext->ddlist.option_cnt / LV_ROLLER_INF_PAGES;
|
|
|
|
|
|
|
|
ext->ddlist.sel_opt_id = ext->ddlist.sel_opt_id % real_id_cnt;
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->ddlist.sel_opt_id += (LV_ROLLER_INF_PAGES / 2) * real_id_cnt; /*Select the middle page*/
|
2019-03-17 04:32:37 +01:00
|
|
|
|
|
|
|
/*Move to the new id*/
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
|
|
|
|
const lv_font_t * font = style_label->text.font;
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_coord_t h = lv_obj_get_height(roller);
|
2019-03-17 04:32:37 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t line_y1 = ext->ddlist.sel_opt_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;
|
2019-03-17 04:32:37 +01:00
|
|
|
lv_obj_set_y(roller_scrl, new_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-22 08:45:07 +02:00
|
|
|
static void scroll_anim_ready_cb(lv_anim_t * a)
|
|
|
|
{
|
|
|
|
inf_normalize(a->var);
|
|
|
|
}
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2019-04-22 08:45:07 +02:00
|
|
|
|
2017-09-03 16:01:51 +02:00
|
|
|
#endif
|