2017-02-06 10:06:18 +01:00
|
|
|
/**
|
|
|
|
* @file lv_ddlist.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-02-06 10:06:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2020-02-14 12:44:15 +01:00
|
|
|
#include "lv_dropdown.h"
|
2020-02-14 12:36:44 +01:00
|
|
|
#if LV_USE_DROPDOWN != 0
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-02-06 10:06:18 +01:00
|
|
|
#include "../lv_draw/lv_draw.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_group.h"
|
|
|
|
#include "../lv_core/lv_indev.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2019-06-06 05:55:17 +02:00
|
|
|
#include "../lv_font/lv_symbol_def.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
2019-03-14 19:37:09 +01:00
|
|
|
#include "../lv_misc/lv_math.h"
|
2019-01-24 16:36:13 +01:00
|
|
|
#include <string.h>
|
2017-02-06 10:06:18 +01:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2020-02-14 12:36:44 +01:00
|
|
|
#define LV_OBJX_NAME "lv_dropdown"
|
2019-09-26 10:51:54 +02:00
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2020-02-26 19:48:27 +01:00
|
|
|
#undef LV_DROPDOWN_DEF_ANIM_TIME
|
|
|
|
#define LV_DROPDOWN_DEF_ANIM_TIME 0 /*No animation*/
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-05-02 00:16:48 +02:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#define LV_DROPDOWN_PR_NONE 0xFFFF
|
2020-01-24 14:55:56 +01:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_page_ext_t page;
|
|
|
|
lv_obj_t * ddlist; /*Pointer to the ddlist where the page belongs*/
|
2020-02-26 19:48:27 +01:00
|
|
|
} lv_dropdown_page_ext_t;
|
2017-02-06 10:06:18 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * clip_area, lv_design_mode_t mode);
|
|
|
|
static lv_design_res_t lv_dropdown_page_design(lv_obj_t * ddlist, const lv_area_t * clip_area, lv_design_mode_t mode);
|
|
|
|
static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param);
|
|
|
|
static lv_res_t lv_dropdown_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
|
|
|
|
static lv_res_t lv_dropdown_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
|
|
|
|
static lv_style_list_t * lv_dropdown_get_style(lv_obj_t * ddlist, uint8_t part);
|
2020-02-13 14:26:51 +01:00
|
|
|
static void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_state_t state);
|
|
|
|
static void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_state_t state);
|
2020-01-23 17:16:11 +01:00
|
|
|
static lv_res_t page_release_handler(lv_obj_t * page);
|
2020-01-24 14:55:56 +01:00
|
|
|
static void page_press_handler(lv_obj_t * page);
|
|
|
|
static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y);
|
2020-04-08 20:54:02 +02:00
|
|
|
static void position_to_selected(lv_obj_t * ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
static lv_obj_t * get_label(const lv_obj_t * ddlist);
|
2017-02-06 10:06:18 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-04-04 07:15:40 +02:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2020-01-23 17:16:11 +01:00
|
|
|
static lv_signal_cb_t ancestor_page_signal;
|
|
|
|
static lv_signal_cb_t ancestor_page_scrl_signal;
|
2019-04-04 07:15:40 +02:00
|
|
|
static lv_design_cb_t ancestor_design;
|
2020-01-23 17:16:11 +01:00
|
|
|
static lv_design_cb_t ancestor_page_design;
|
2018-03-01 12:21:49 +01:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a drop down list objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new drop down list
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param copy pointer to a drop down list object, if not NULL then the new object will be copied
|
|
|
|
* from it
|
2017-02-06 10:06:18 +01:00
|
|
|
* @return pointer to the created drop down list
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_t * lv_dropdown_create(lv_obj_t * par, const lv_obj_t * copy)
|
2017-02-06 10:06:18 +01:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("drop down list create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/*Create the ancestor drop down list*/
|
2020-03-06 13:14:25 +01:00
|
|
|
lv_obj_t * ddlist = lv_obj_create(par, copy);
|
2020-01-23 17:16:11 +01:00
|
|
|
LV_ASSERT_MEM(ddlist);
|
|
|
|
if(ddlist == NULL) return NULL;
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(ddlist);
|
|
|
|
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(ddlist);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/*Allocate the drop down list type specific extended data*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_allocate_ext_attr(ddlist, sizeof(lv_dropdown_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_del(ddlist);
|
2019-12-03 18:16:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-02-06 10:06:18 +01:00
|
|
|
|
|
|
|
/*Initialize the allocated 'ext' */
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->page = NULL;
|
2020-03-10 20:55:32 +01:00
|
|
|
ext->options = NULL;
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->symbol = LV_SYMBOL_DOWN;
|
2020-02-12 08:54:03 +01:00
|
|
|
ext->text = "Select";
|
2020-03-10 18:30:49 +01:00
|
|
|
ext->static_txt = 1;
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->show_selected = 1;
|
|
|
|
ext->sel_opt_id = 0;
|
|
|
|
ext->sel_opt_id_orig = 0;
|
2020-02-14 12:36:44 +01:00
|
|
|
ext->pr_opt_id = LV_DROPDOWN_PR_NONE;
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->option_cnt = 0;
|
2020-02-14 12:36:44 +01:00
|
|
|
ext->dir = LV_DROPDOWN_DIR_DOWN;
|
2020-03-06 13:14:25 +01:00
|
|
|
ext->max_height = (3 * lv_disp_get_ver_res(NULL)) / 4;
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_style_list_init(&ext->style_page);
|
|
|
|
lv_style_list_init(&ext->style_scrlbar);
|
|
|
|
lv_style_list_init(&ext->style_selected);
|
2018-11-09 20:32:08 +08:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/*The signal and design functions are not copied so set them here*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_signal_cb(ddlist, lv_dropdown_signal);
|
|
|
|
lv_obj_set_design_cb(ddlist, lv_dropdown_design);
|
2017-02-06 10:06:18 +01:00
|
|
|
|
|
|
|
/*Init the new drop down list drop down list*/
|
|
|
|
if(copy == NULL) {
|
2020-04-23 09:50:50 +02:00
|
|
|
lv_obj_set_width(ddlist, LV_DPX(150));
|
2020-04-28 21:07:10 +02:00
|
|
|
lv_dropdown_set_options_static(ddlist, "Option 1\nOption 2\nOption 3");
|
2020-02-14 17:03:25 +01:00
|
|
|
lv_theme_apply(ddlist, LV_THEME_DROPDOWN);
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
/*Copy an existing drop down list*/
|
|
|
|
else {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2020-03-02 08:18:58 -08:00
|
|
|
if(copy_ext->static_txt == 0)
|
|
|
|
lv_dropdown_set_options(ddlist, lv_dropdown_get_options(copy));
|
2020-03-24 10:13:52 +01:00
|
|
|
else
|
2020-04-28 21:07:10 +02:00
|
|
|
lv_dropdown_set_options_static(ddlist, lv_dropdown_get_options(copy));
|
2020-02-13 06:56:14 +01:00
|
|
|
ext->option_cnt = copy_ext->option_cnt;
|
|
|
|
ext->sel_opt_id = copy_ext->sel_opt_id;
|
|
|
|
ext->sel_opt_id_orig = copy_ext->sel_opt_id;
|
|
|
|
ext->symbol = copy_ext->symbol;
|
|
|
|
ext->max_height = copy_ext->max_height;
|
|
|
|
ext->text = copy_ext->text;
|
|
|
|
ext->dir = copy_ext->dir;
|
|
|
|
ext->show_selected = copy_ext->show_selected;
|
|
|
|
lv_style_list_copy(&ext->style_page, ©_ext->style_page);
|
|
|
|
lv_style_list_copy(&ext->style_selected, ©_ext->style_selected);
|
|
|
|
lv_style_list_copy(&ext->style_scrlbar, ©_ext->style_scrlbar);
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("drop down list created");
|
2018-07-25 20:39:24 +02:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
return ddlist;
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Set text of the ddlist (Displayed on the button if `show_selected = false`)
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @param txt the text as a string (Only it's pointer is saved)
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_text(lv_obj_t * ddlist, const char * txt)
|
2020-02-12 08:54:03 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-02-12 08:54:03 +01:00
|
|
|
if(ext->text == txt) return;
|
|
|
|
|
|
|
|
ext->text = txt;
|
|
|
|
|
|
|
|
lv_obj_invalidate(ddlist);
|
|
|
|
}
|
|
|
|
|
2020-03-11 13:14:47 -07:00
|
|
|
/**
|
|
|
|
* Clear any options in a drop down list. Static or dynamic.
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
*/
|
|
|
|
void lv_dropdown_clear_options(lv_obj_t * ddlist)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
|
|
|
if(ext->options == NULL) return;
|
|
|
|
|
|
|
|
if(ext->static_txt == 0)
|
|
|
|
lv_mem_free(ext->options);
|
|
|
|
|
|
|
|
ext->options = NULL;
|
|
|
|
ext->static_txt = 0;
|
|
|
|
ext->option_cnt = 0;
|
|
|
|
|
|
|
|
lv_obj_invalidate(ddlist);
|
|
|
|
}
|
|
|
|
|
2017-06-07 12:38:43 +02:00
|
|
|
/**
|
|
|
|
* Set the options in a drop down list from a string
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @param options a string with '\n' separated options. E.g. "One\nTwo\nThree"
|
2020-03-02 08:18:58 -08:00
|
|
|
* The options string can be destroyed after calling this function
|
2017-06-07 12:38:43 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_options(lv_obj_t * ddlist, const char * options)
|
2017-06-07 12:38:43 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_STR(options);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2017-07-20 12:26:34 +02:00
|
|
|
|
|
|
|
/*Count the '\n'-s to determine the number of options*/
|
2017-10-26 21:20:10 +02:00
|
|
|
ext->option_cnt = 0;
|
2017-07-20 12:26:34 +02:00
|
|
|
uint16_t i;
|
|
|
|
for(i = 0; options[i] != '\0'; i++) {
|
2017-10-26 21:20:10 +02:00
|
|
|
if(options[i] == '\n') ext->option_cnt++;
|
2017-07-20 12:26:34 +02:00
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->option_cnt++; /*Last option has no `\n`*/
|
|
|
|
ext->sel_opt_id = 0;
|
|
|
|
ext->sel_opt_id_orig = 0;
|
2020-03-24 10:13:52 +01:00
|
|
|
|
2020-03-02 08:18:58 -08:00
|
|
|
/*Allocate space for the new text*/
|
|
|
|
size_t len = strlen(options) + 1;
|
|
|
|
if(ext->options != NULL && ext->static_txt == 0) {
|
|
|
|
lv_mem_free(ext->options);
|
|
|
|
ext->options = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext->options = lv_mem_alloc(len);
|
|
|
|
|
|
|
|
LV_ASSERT_MEM(ext->options);
|
|
|
|
if(ext->options == NULL) return;
|
|
|
|
|
|
|
|
strcpy(ext->options, options);
|
|
|
|
|
|
|
|
/*Now the text is dynamically allocated*/
|
|
|
|
ext->static_txt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the options in a drop down list from a string
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @param options a staic string with '\n' separated options. E.g. "One\nTwo\nThree"
|
|
|
|
*/
|
2020-04-28 21:07:10 +02:00
|
|
|
void lv_dropdown_set_options_static(lv_obj_t * ddlist, const char * options)
|
2020-03-02 08:18:58 -08:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_STR(options);
|
|
|
|
|
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
|
|
|
|
|
|
|
/*Count the '\n'-s to determine the number of options*/
|
|
|
|
ext->option_cnt = 0;
|
|
|
|
uint16_t i;
|
|
|
|
for(i = 0; options[i] != '\0'; i++) {
|
|
|
|
if(options[i] == '\n') ext->option_cnt++;
|
|
|
|
}
|
|
|
|
ext->option_cnt++; /*Last option has no `\n`*/
|
|
|
|
ext->sel_opt_id = 0;
|
|
|
|
ext->sel_opt_id_orig = 0;
|
|
|
|
|
|
|
|
if(ext->static_txt == 0 && ext->options != NULL) {
|
|
|
|
lv_mem_free(ext->options);
|
|
|
|
ext->options = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext->static_txt = 1;
|
|
|
|
ext->options = (char *)options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an options to a drop down list from a string. Only works for dynamic options.
|
|
|
|
* @param ddlist pointer to drop down list object
|
2020-03-03 06:37:01 -08:00
|
|
|
* @param option a string without '\n'. E.g. "Four"
|
|
|
|
* @param pos the insert position, indexed from 0, LV_DROPDOWN_POS_LAST = end of string
|
2020-03-02 08:18:58 -08:00
|
|
|
*/
|
2020-03-03 06:37:01 -08:00
|
|
|
void lv_dropdown_add_option(lv_obj_t * ddlist, const char * option, uint16_t pos)
|
2020-03-02 08:18:58 -08:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_STR(option);
|
|
|
|
|
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
|
|
|
|
2020-03-30 15:06:14 -07:00
|
|
|
/*Convert static options to dynamic*/
|
2020-03-11 03:30:56 -07:00
|
|
|
if(ext->static_txt != 0) {
|
2020-03-11 13:14:47 -07:00
|
|
|
char * static_options = ext->options;
|
|
|
|
size_t len = strlen(static_options) + 1;
|
|
|
|
|
|
|
|
ext->options = lv_mem_alloc(len);
|
|
|
|
LV_ASSERT_MEM(ext->options);
|
|
|
|
if(ext->options == NULL) return;
|
|
|
|
|
|
|
|
strcpy(ext->options, static_options);
|
2020-03-11 03:30:56 -07:00
|
|
|
ext->static_txt = 0;
|
|
|
|
}
|
2020-03-02 08:18:58 -08:00
|
|
|
|
|
|
|
/*Allocate space for the new option*/
|
|
|
|
size_t old_len = (ext->options == NULL) ? 0 : strlen(ext->options);
|
2020-03-24 10:13:52 +01:00
|
|
|
size_t ins_len = strlen(option);
|
|
|
|
size_t new_len = ins_len + old_len + 2; /* +2 for terminating NULL and possible \n */
|
|
|
|
ext->options = lv_mem_realloc(ext->options, new_len + 1);
|
|
|
|
LV_ASSERT_MEM(ext->options);
|
|
|
|
if(ext->options == NULL) return;
|
2020-03-02 08:18:58 -08:00
|
|
|
|
|
|
|
ext->options[old_len] = 0;
|
|
|
|
|
|
|
|
/*Find the insert character position*/
|
2020-03-03 06:37:01 -08:00
|
|
|
uint16_t insert_pos = old_len;
|
2020-03-02 09:10:48 -08:00
|
|
|
if(pos != LV_DROPDOWN_POS_LAST) {
|
2020-03-02 08:18:58 -08:00
|
|
|
int opcnt = 0;
|
2020-03-02 21:01:24 -08:00
|
|
|
for(insert_pos = 0; ext->options[insert_pos] != 0; insert_pos++) {
|
|
|
|
if(opcnt == pos)
|
|
|
|
break;
|
|
|
|
if(ext->options[insert_pos] == '\n')
|
|
|
|
opcnt++;
|
2020-03-02 08:18:58 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 09:10:48 -08:00
|
|
|
/*Add delimiter to existing options*/
|
2020-03-02 21:01:24 -08:00
|
|
|
if((insert_pos > 0) && (pos >= ext->option_cnt))
|
2020-03-30 15:06:14 -07:00
|
|
|
lv_txt_ins(ext->options, lv_txt_encoded_get_char_id(ext->options, insert_pos++), "\n");
|
2020-03-02 09:10:48 -08:00
|
|
|
|
|
|
|
/*Insert the new option, adding \n if necessary*/
|
2020-03-02 21:01:24 -08:00
|
|
|
char * ins_buf = lv_mem_buf_get(ins_len + 2); /* + 2 for terminating NULL and possible \n */
|
2020-03-02 08:18:58 -08:00
|
|
|
LV_ASSERT_MEM(ins_buf);
|
|
|
|
if(ins_buf == NULL) return;
|
2020-03-24 10:13:52 +01:00
|
|
|
strcpy(ins_buf, option);
|
2020-03-02 08:18:58 -08:00
|
|
|
if(pos < ext->option_cnt)
|
|
|
|
strcat(ins_buf, "\n");
|
2020-03-30 15:06:14 -07:00
|
|
|
lv_txt_ins(ext->options, lv_txt_encoded_get_char_id(ext->options, insert_pos), ins_buf);
|
2020-03-02 08:18:58 -08:00
|
|
|
lv_mem_buf_release(ins_buf);
|
|
|
|
|
|
|
|
ext->option_cnt++;
|
2020-03-24 20:25:04 +01:00
|
|
|
|
|
|
|
lv_obj_invalidate(ddlist);
|
2017-06-07 12:38:43 +02:00
|
|
|
}
|
|
|
|
|
2017-02-06 16:05:02 +01:00
|
|
|
/**
|
|
|
|
* Set the selected option
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @param sel_opt id of the selected option (0 ... number of option - 1);
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_selected(lv_obj_t * ddlist, uint16_t sel_opt)
|
2017-02-06 16:05:02 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2018-05-16 23:09:30 +02:00
|
|
|
if(ext->sel_opt_id == sel_opt) return;
|
2017-02-06 16:05:02 +01:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->sel_opt_id = sel_opt < ext->option_cnt ? sel_opt : ext->option_cnt - 1;
|
|
|
|
ext->sel_opt_id_orig = ext->sel_opt_id;
|
2017-02-06 16:05:02 +01:00
|
|
|
/*Move the list to show the current option*/
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ext->page != NULL) {
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_invalidate(ddlist);
|
2017-02-06 16:05:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-06 13:14:25 +01:00
|
|
|
* Set the direction of the a drop down list
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @param dir LV_DROPDOWN_DIR_LEF/RIGHT/TOP/BOTTOM
|
|
|
|
*/
|
|
|
|
void lv_dropdown_set_dir(lv_obj_t * ddlist, lv_dropdown_dir_t dir)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
|
|
|
if(ext->dir == dir) return;
|
|
|
|
|
|
|
|
ext->dir = dir;
|
|
|
|
|
|
|
|
lv_obj_invalidate(ddlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximal height for the drop down list
|
2017-02-06 16:05:02 +01:00
|
|
|
* @param ddlist pointer to a drop down list
|
2020-03-06 13:14:25 +01:00
|
|
|
* @param h the maximal height
|
2017-02-06 16:05:02 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_max_height(lv_obj_t * ddlist, lv_coord_t h)
|
2017-02-06 16:05:02 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ext->max_height == h) return;
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->max_height = h;
|
2017-11-17 15:43:08 +01:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ext->page) {
|
|
|
|
if(h == 0) {
|
|
|
|
lv_cont_set_fit(ext->page, LV_FIT_TIGHT);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_cont_set_fit2(ext->page, LV_FIT_TIGHT, LV_FIT_NONE);
|
|
|
|
lv_obj_set_height(ext->page, h);
|
|
|
|
}
|
2019-08-16 16:43:05 +02:00
|
|
|
}
|
2017-11-17 15:43:08 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 16:07:40 +01:00
|
|
|
/**
|
2019-11-20 16:18:56 +01:00
|
|
|
* Set an arrow or other symbol to display when the drop-down list is closed.
|
2019-02-26 16:07:40 +01:00
|
|
|
* @param ddlist pointer to drop down list object
|
2019-11-20 16:18:56 +01:00
|
|
|
* @param symbol a text like `LV_SYMBOL_DOWN` or NULL to not draw icon
|
2019-02-26 16:07:40 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_symbol(lv_obj_t * ddlist, const char * symbol)
|
2019-02-26 16:07:40 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2019-11-20 16:18:56 +01:00
|
|
|
ext->symbol = symbol;
|
|
|
|
lv_obj_invalidate(ddlist);
|
2019-02-26 16:07:40 +01:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Set whether the ddlist highlight the last selected option and display its text or not
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @param show true/false
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_show_selected(lv_obj_t * ddlist, bool show)
|
2020-02-12 08:54:03 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-02-12 08:54:03 +01:00
|
|
|
if(ext->show_selected == show) return;
|
|
|
|
|
|
|
|
ext->show_selected = show;
|
|
|
|
|
|
|
|
lv_obj_invalidate(ddlist);
|
|
|
|
}
|
2020-03-21 01:24:58 +01:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Get text of the ddlist (Displayed on the button if `show_selected = false`)
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @return the text string
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_dropdown_get_text(lv_obj_t * ddlist)
|
2020-02-12 08:54:03 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-02-12 08:54:03 +01:00
|
|
|
|
|
|
|
return ext->text;
|
|
|
|
}
|
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**
|
|
|
|
* Get the options of a drop down list
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_dropdown_get_options(const lv_obj_t * ddlist)
|
2017-02-06 10:06:18 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
return ext->options;
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
|
2017-02-06 16:05:02 +01:00
|
|
|
/**
|
|
|
|
* Get the selected option
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @return id of the selected option (0 ... number of option - 1);
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_dropdown_get_selected(const lv_obj_t * ddlist)
|
2017-02-06 16:05:02 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2017-02-06 16:05:02 +01:00
|
|
|
|
2017-11-16 10:20:30 +01:00
|
|
|
return ext->sel_opt_id;
|
2017-02-06 16:05:02 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 16:34:10 -05:00
|
|
|
/**
|
|
|
|
* Get the total number of options
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @return the total number of options in the list
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_dropdown_get_option_cnt(const lv_obj_t * ddlist)
|
2019-12-19 16:34:10 -05:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2019-12-19 16:34:10 -05:00
|
|
|
|
|
|
|
return ext->option_cnt;
|
|
|
|
}
|
|
|
|
|
2017-06-07 12:38:43 +02:00
|
|
|
/**
|
|
|
|
* Get the current selected option as a string
|
|
|
|
* @param ddlist pointer to ddlist object
|
|
|
|
* @param buf pointer to an array to store the string
|
2019-03-29 16:10:18 +01:00
|
|
|
* @param buf_size size of `buf` in bytes. 0: to ignore it.
|
2017-06-07 12:38:43 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_get_selected_str(const lv_obj_t * ddlist, char * buf, uint16_t buf_size)
|
2017-06-07 12:38:43 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2017-06-07 12:38:43 +02:00
|
|
|
|
|
|
|
uint16_t i;
|
2019-04-04 07:15:40 +02:00
|
|
|
uint16_t line = 0;
|
2020-01-23 17:16:11 +01:00
|
|
|
size_t txt_len = strlen(ext->options);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2020-01-24 06:03:43 +01:00
|
|
|
for(i = 0; i < txt_len && line != ext->sel_opt_id_orig; i++) {
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ext->options[i] == '\n') line++;
|
2017-06-07 12:38:43 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2017-06-07 12:38:43 +02:00
|
|
|
uint16_t c;
|
2020-02-25 15:32:35 +01:00
|
|
|
for(c = 0; i < txt_len && ext->options[i] != '\n'; c++, i++) {
|
2019-03-29 16:10:18 +01:00
|
|
|
if(buf_size && c >= buf_size - 1) {
|
2020-02-14 12:36:44 +01:00
|
|
|
LV_LOG_WARN("lv_dropdown_get_selected_str: the buffer was too small")
|
2019-03-29 16:10:18 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
buf[c] = ext->options[i];
|
2019-03-29 16:10:18 +01:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2017-06-07 12:38:43 +02:00
|
|
|
buf[c] = '\0';
|
|
|
|
}
|
|
|
|
|
2017-02-06 16:05:02 +01:00
|
|
|
/**
|
2017-10-05 11:29:21 +02:00
|
|
|
* Get the fix height value.
|
2017-04-13 10:20:35 +02:00
|
|
|
* @param ddlist pointer to a drop down list object
|
2017-10-05 11:29:21 +02:00
|
|
|
* @return the height if the ddlist is opened (0: auto size)
|
2017-02-06 16:05:02 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_coord_t lv_dropdown_get_max_height(const lv_obj_t * ddlist)
|
2017-02-06 16:05:02 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
return ext->max_height;
|
2017-02-06 16:05:02 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 16:07:40 +01:00
|
|
|
/**
|
2019-11-20 16:18:56 +01:00
|
|
|
* Get the symbol to draw when the drop-down list is closed
|
2019-02-26 16:07:40 +01:00
|
|
|
* @param ddlist pointer to drop down list object
|
2019-11-20 16:18:56 +01:00
|
|
|
* @return the symbol or NULL if not enabled
|
2019-02-26 16:07:40 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_dropdown_get_symbol(lv_obj_t * ddlist)
|
2019-02-26 16:07:40 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2019-02-26 16:07:40 +01:00
|
|
|
|
2019-11-20 16:18:56 +01:00
|
|
|
return ext->symbol;
|
2019-02-26 16:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-23 17:16:11 +01:00
|
|
|
* Get the direction of the drop down list
|
2017-04-13 10:20:35 +02:00
|
|
|
* @param ddlist pointer to a drop down list object
|
2020-02-14 12:36:44 +01:00
|
|
|
* @return LV_DROPDOWN_DIR_LEF/RIGHT/TOP/BOTTOM
|
2017-02-06 10:06:18 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_dir_t lv_dropdown_get_dir(const lv_obj_t * ddlist)
|
2018-12-09 20:51:32 -05:00
|
|
|
{
|
2020-03-21 01:24:58 +01:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2018-12-09 20:51:32 -05:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
return ext->dir;
|
2018-12-09 20:51:32 -05:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Get whether the ddlist highlight the last selected option and display its text or not
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @return true/false
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_dropdown_get_show_selected(lv_obj_t * ddlist)
|
2020-02-12 08:54:03 +01:00
|
|
|
{
|
2020-03-21 01:24:58 +01:00
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-02-12 08:54:03 +01:00
|
|
|
|
|
|
|
return ext->show_selected ? true : false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
2017-05-02 00:16:48 +02:00
|
|
|
/**
|
2017-11-10 15:01:40 +01:00
|
|
|
* Open the drop down list with or without animation
|
|
|
|
* @param ddlist pointer to drop down list object
|
2017-05-02 00:16:48 +02:00
|
|
|
*/
|
2020-04-08 20:54:02 +02:00
|
|
|
void lv_dropdown_open(lv_obj_t * ddlist)
|
2017-05-02 00:16:48 +02:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ext->page) return;
|
|
|
|
|
|
|
|
ext->page = lv_page_create(lv_obj_get_screen(ddlist), NULL);
|
2020-02-14 22:04:00 +01:00
|
|
|
lv_obj_add_protect(ext->page, LV_PROTECT_POS | LV_PROTECT_CLICK_FOCUS);
|
|
|
|
lv_obj_add_protect(lv_page_get_scrl(ext->page), LV_PROTECT_CLICK_FOCUS);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
if(ancestor_page_signal == NULL) ancestor_page_signal = lv_obj_get_signal_cb(ext->page);
|
|
|
|
if(ancestor_page_scrl_signal == NULL) ancestor_page_scrl_signal = lv_obj_get_signal_cb(lv_page_get_scrl(ext->page));
|
|
|
|
if(ancestor_page_design == NULL) ancestor_page_design = lv_obj_get_design_cb(ext->page);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_page_ext_t * page_ext = lv_obj_allocate_ext_attr(ext->page, sizeof(lv_dropdown_page_ext_t));
|
2020-03-10 08:34:07 +01:00
|
|
|
LV_ASSERT_MEM(page_ext);
|
|
|
|
if(page_ext == NULL) {
|
|
|
|
lv_obj_del(ext->page);
|
|
|
|
ext->page = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
page_ext->ddlist = ddlist;
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_design_cb(ext->page, lv_dropdown_page_design);
|
|
|
|
lv_obj_set_signal_cb(ext->page, lv_dropdown_page_signal);
|
|
|
|
lv_obj_set_signal_cb(lv_page_get_scrl(ext->page), lv_dropdown_page_scrl_signal);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
lv_style_list_copy(lv_obj_get_style_list(ext->page, LV_PAGE_PART_BG), &ext->style_page);
|
2020-04-21 11:36:05 +02:00
|
|
|
lv_style_list_copy(lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCROLLBAR), &ext->style_scrlbar);
|
|
|
|
lv_obj_clean_style_list(ext->page, LV_PAGE_PART_SCROLLABLE);
|
2020-03-10 10:41:39 +01:00
|
|
|
lv_obj_refresh_style(ext->page, LV_STYLE_PROP_ALL);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
lv_page_set_scrl_fit(ext->page, LV_FIT_TIGHT);
|
|
|
|
|
|
|
|
lv_obj_t * label = lv_label_create(ext->page, NULL);
|
2020-04-28 21:07:10 +02:00
|
|
|
lv_label_set_text_static(label, ext->options);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_cont_set_fit2(ext->page, LV_FIT_TIGHT, LV_FIT_NONE);
|
|
|
|
lv_coord_t label_h = lv_obj_get_height(label);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ddlist, LV_DROPDOWN_PART_LIST);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ddlist, LV_DROPDOWN_PART_LIST);
|
2020-01-24 14:55:56 +01:00
|
|
|
|
|
|
|
lv_coord_t list_h = label_h + top + bottom;
|
|
|
|
|
|
|
|
if(list_h > ext->max_height) list_h = ext->max_height;
|
|
|
|
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_dir_t dir = ext->dir;
|
|
|
|
/*No place on the bottom? See if top is better.*/
|
|
|
|
if(ext->dir == LV_DROPDOWN_DIR_DOWN) {
|
|
|
|
if(ddlist->coords.y2 + list_h > LV_VER_RES) {
|
|
|
|
if(ddlist->coords.y1 > LV_VER_RES - ddlist->coords.y2) {
|
|
|
|
/*There is more space on the top, so make it drop up*/
|
|
|
|
dir = LV_DROPDOWN_DIR_UP;
|
|
|
|
list_h = ddlist->coords.y1;
|
2020-05-01 11:17:43 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-04-08 20:54:02 +02:00
|
|
|
list_h = LV_VER_RES - ddlist->coords.y2;
|
|
|
|
}
|
2020-02-13 06:56:14 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-08 20:54:02 +02:00
|
|
|
/*No place on the top? See if bottom is better.*/
|
|
|
|
else if(ext->dir == LV_DROPDOWN_DIR_UP) {
|
|
|
|
if(ddlist->coords.y1 - list_h < 0) {
|
|
|
|
if(ddlist->coords.y1 < LV_VER_RES - ddlist->coords.y2) {
|
|
|
|
/*There is more space on the top, so make it drop up*/
|
|
|
|
dir = LV_DROPDOWN_DIR_DOWN;
|
|
|
|
list_h = LV_VER_RES - ddlist->coords.y2;
|
2020-05-01 11:17:43 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-04-08 20:54:02 +02:00
|
|
|
list_h = ddlist->coords.y1;
|
|
|
|
}
|
2020-02-13 06:56:14 +01:00
|
|
|
}
|
2020-02-09 11:23:22 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_obj_set_height(ext->page, list_h);
|
|
|
|
|
|
|
|
position_to_selected(ddlist);
|
|
|
|
|
|
|
|
if(dir == LV_DROPDOWN_DIR_DOWN) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
|
|
|
else if(dir == LV_DROPDOWN_DIR_UP) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
|
|
|
|
else if(dir == LV_DROPDOWN_DIR_LEFT) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_LEFT_TOP, 0, 0);
|
|
|
|
else if(dir == LV_DROPDOWN_DIR_RIGHT)lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
|
|
|
|
|
|
|
|
if(ext->dir == LV_DROPDOWN_DIR_LEFT || ext->dir == LV_DROPDOWN_DIR_RIGHT) {
|
|
|
|
if(ext->page->coords.y2 > LV_VER_RES) {
|
|
|
|
lv_obj_set_y(ext->page, lv_obj_get_y(ext->page) - (ext->page->coords.y2 - LV_VER_RES));
|
|
|
|
}
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close (Collapse) the drop down list
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
*/
|
2020-04-08 20:54:02 +02:00
|
|
|
void lv_dropdown_close(lv_obj_t * ddlist)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ext->page == NULL) return;
|
2020-01-24 14:55:56 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
ext->pr_opt_id = LV_DROPDOWN_PR_NONE;
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_obj_del(ext->page);
|
|
|
|
ext->page = NULL;
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2020-01-23 17:16:11 +01:00
|
|
|
* Handle the drawing related tasks of the drop down list
|
2017-02-06 10:06:18 +01:00
|
|
|
* @param ddlist pointer to an object
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param clip_area the object will be drawn only in this area
|
2017-02-06 10:06:18 +01:00
|
|
|
* @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
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param return an element of `lv_design_res_t`
|
2017-02-06 10:06:18 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * clip_area, lv_design_mode_t mode)
|
2017-02-06 10:06:18 +01:00
|
|
|
{
|
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
2019-09-06 19:53:39 +02:00
|
|
|
return ancestor_design(ddlist, clip_area, mode);
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
/*Draw the object*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
2019-09-06 19:53:39 +02:00
|
|
|
ancestor_design(ddlist, clip_area, mode);
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-03-06 13:14:25 +01:00
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ddlist, LV_DROPDOWN_PART_MAIN);
|
|
|
|
lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_MAIN);
|
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ddlist, LV_DROPDOWN_PART_MAIN);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
lv_draw_label_dsc_t label_dsc;
|
|
|
|
lv_draw_label_dsc_init(&label_dsc);
|
2020-03-06 13:14:25 +01:00
|
|
|
lv_obj_init_draw_label_dsc(ddlist, LV_DROPDOWN_PART_MAIN, &label_dsc);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
lv_area_t txt_area;
|
|
|
|
lv_point_t txt_size;
|
|
|
|
|
|
|
|
const char * opt_txt = ext->text;
|
2020-01-24 06:03:43 +01:00
|
|
|
if(ext->show_selected) {
|
2020-02-12 08:54:03 +01:00
|
|
|
char * buf = lv_mem_buf_get(128);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_get_selected_str(ddlist, buf, 128);
|
2020-01-23 17:16:11 +01:00
|
|
|
opt_txt = buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * txt;
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? opt_txt : ext->symbol;
|
2020-01-23 17:16:11 +01:00
|
|
|
if(txt) {
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
|
|
|
|
label_dsc.flag);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
txt_area.y1 = ddlist->coords.y1 + top;
|
|
|
|
txt_area.y2 = txt_area.y1 + txt_size.y;
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/*Center align the text if no symbol*/
|
|
|
|
if(ext->symbol == NULL && txt == opt_txt) {
|
|
|
|
txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2;
|
|
|
|
txt_area.x2 = txt_area.x1 + txt_size.x;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-02-12 08:54:03 +01:00
|
|
|
txt_area.x1 = ddlist->coords.x1 + left;
|
|
|
|
txt_area.x2 = txt_area.x1 + txt_size.x;
|
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_draw_label(&txt_area, clip_area, &label_dsc, txt, NULL);
|
|
|
|
}
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? ext->symbol : opt_txt;
|
2020-01-23 17:16:11 +01:00
|
|
|
if(txt) {
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
|
|
|
|
label_dsc.flag);
|
2020-01-23 17:16:11 +01:00
|
|
|
txt_area.y1 = ddlist->coords.y1 + top;
|
|
|
|
txt_area.y2 = txt_area.y1 + txt_size.y;
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/*Center align the text if no symbol*/
|
|
|
|
if(ext->symbol == NULL && txt == opt_txt) {
|
|
|
|
txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2;
|
|
|
|
txt_area.x2 = txt_area.x1 + txt_size.x;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-02-14 17:03:25 +01:00
|
|
|
txt_area.x1 = ddlist->coords.x2 - right - txt_size.x;
|
|
|
|
txt_area.x2 = txt_area.x1 + txt_size.x;
|
2020-02-12 08:54:03 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_draw_label(&txt_area, clip_area, &label_dsc, txt, NULL);
|
|
|
|
}
|
|
|
|
|
2020-02-15 02:19:44 +01:00
|
|
|
if(ext->show_selected) {
|
2020-02-12 08:54:03 +01:00
|
|
|
lv_mem_buf_release((char *)opt_txt);
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
2020-01-23 17:16:11 +01:00
|
|
|
ancestor_design(ddlist, clip_area, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return LV_DESIGN_RES_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the drawing related tasks of the drop down list's page
|
|
|
|
* @param page pointer to an object
|
|
|
|
* @param clip_area 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 an element of `lv_design_res_t`
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_design_res_t lv_dropdown_page_design(lv_obj_t * page, const lv_area_t * clip_area, lv_design_mode_t mode)
|
2020-01-23 17:16:11 +01:00
|
|
|
{
|
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
|
|
|
return ancestor_page_design(page, clip_area, mode);
|
|
|
|
}
|
|
|
|
/*Draw the object*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
|
|
|
ancestor_page_design(page, clip_area, mode);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * ddlist = page_ext->ddlist;
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
/*Draw the boxes if the page is not being deleted*/
|
|
|
|
if(ext->page) {
|
2020-02-14 12:36:44 +01:00
|
|
|
if(ext->pr_opt_id != LV_DROPDOWN_PR_NONE) {
|
2020-02-13 14:26:51 +01:00
|
|
|
draw_box(ddlist, clip_area, ext->pr_opt_id, LV_STATE_PRESSED);
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
if(ext->show_selected) {
|
2020-02-22 01:09:29 +01:00
|
|
|
draw_box(ddlist, clip_area, ext->sel_opt_id, LV_STATE_DEFAULT);
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
/*Post draw when the children are drawn*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
2020-01-23 17:16:11 +01:00
|
|
|
/*Draw the scrollbar in the ancestor page design function*/
|
|
|
|
ancestor_page_design(page, clip_area, mode);
|
|
|
|
|
2017-12-17 20:11:14 +01:00
|
|
|
/*Redraw the text on the selected area with a different color*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * ddlist = page_ext->ddlist;
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2017-12-17 20:11:14 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
/*Draw the box labels if the page is not being deleted*/
|
|
|
|
if(ext->page) {
|
2020-02-14 12:36:44 +01:00
|
|
|
if(ext->pr_opt_id != LV_DROPDOWN_PR_NONE) {
|
2020-02-13 14:26:51 +01:00
|
|
|
draw_box_label(ddlist, clip_area, ext->pr_opt_id, LV_STATE_PRESSED);
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
if(ext->show_selected) {
|
2020-02-22 01:09:29 +01:00
|
|
|
draw_box_label(ddlist, clip_area, ext->sel_opt_id, LV_STATE_DEFAULT);
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
2017-12-17 20:11:14 +01:00
|
|
|
}
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
|
2019-09-06 19:53:39 +02:00
|
|
|
return LV_DESIGN_RES_OK;
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/**
|
|
|
|
* Signal function of the drop down list
|
|
|
|
* @param ddlist pointer to a drop down list 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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
|
2017-11-07 17:00:55 +01:00
|
|
|
{
|
|
|
|
lv_res_t res;
|
2020-01-01 15:25:16 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(ddlist, 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
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2017-12-03 00:35:39 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
|
|
|
lv_get_style_info_t * info = param;
|
2020-02-14 12:36:44 +01:00
|
|
|
info->result = lv_dropdown_get_style(ddlist, info->part);
|
2020-01-24 14:55:56 +01:00
|
|
|
if(info->result != NULL) return LV_RES_OK;
|
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
|
|
|
lv_get_state_info_t * info = param;
|
2020-02-14 12:36:44 +01:00
|
|
|
if(info->part == LV_DROPDOWN_PART_LIST ||
|
2020-02-26 19:48:27 +01:00
|
|
|
info->part == LV_DROPDOWN_PART_SCRLBAR ||
|
|
|
|
info->part == LV_DROPDOWN_PART_SELECTED) {
|
|
|
|
info->result = lv_obj_get_state(ext->page, LV_PAGE_PART_BG);
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_CLEANUP) {
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_close(ddlist);
|
2020-03-02 08:20:02 -08:00
|
|
|
if(ext->static_txt == 0) {
|
|
|
|
lv_mem_free(ext->options);
|
|
|
|
ext->options = NULL;
|
|
|
|
}
|
2020-03-24 10:13:52 +01:00
|
|
|
|
2020-02-21 16:33:42 +01:00
|
|
|
/*`lv_obj_clean_style_list` is not required because these styles are only copied to the page
|
|
|
|
* so they can have transitions or other object related things. */
|
2020-02-15 02:30:20 +01:00
|
|
|
lv_style_list_reset(&ext->style_page);
|
|
|
|
lv_style_list_reset(&ext->style_scrlbar);
|
|
|
|
lv_style_list_reset(&ext->style_selected);
|
2020-02-21 16:33:42 +01:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
}
|
2020-01-24 06:03:43 +01:00
|
|
|
else if(sign == LV_SIGNAL_FOCUS) {
|
|
|
|
#if LV_USE_GROUP
|
|
|
|
lv_group_t * g = lv_obj_get_group(ddlist);
|
|
|
|
bool editing = lv_group_get_editing(g);
|
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
|
|
|
|
|
|
|
|
/*Encoders need special handling*/
|
|
|
|
if(indev_type == LV_INDEV_TYPE_ENCODER) {
|
|
|
|
/*Open the list if editing*/
|
2020-04-08 20:54:02 +02:00
|
|
|
if(editing) lv_dropdown_open(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
/*Close the list if navigating*/
|
|
|
|
else
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_close(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
}
|
|
|
|
#endif
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_LEAVE) {
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_close(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
else if(sign == LV_SIGNAL_RELEASED) {
|
2020-04-23 09:50:50 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
|
|
|
if(lv_indev_is_dragging(indev) == false) {
|
2020-01-24 06:03:43 +01:00
|
|
|
if(ext->page) {
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_close(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
if(ext->sel_opt_id_orig != ext->sel_opt_id) {
|
|
|
|
ext->sel_opt_id_orig = ext->sel_opt_id;
|
|
|
|
lv_obj_invalidate(ddlist);
|
|
|
|
}
|
2020-04-23 15:45:08 +02:00
|
|
|
#if LV_USE_GROUP
|
2020-04-23 09:50:50 +02:00
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(indev);
|
|
|
|
if(indev_type == LV_INDEV_TYPE_ENCODER) {
|
|
|
|
lv_group_set_editing(lv_obj_get_group(ddlist), false);
|
|
|
|
}
|
2020-04-23 15:45:08 +02:00
|
|
|
#endif
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_open(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
else {
|
2020-01-24 06:03:43 +01:00
|
|
|
ext->sel_opt_id = ext->sel_opt_id_orig;
|
|
|
|
lv_obj_invalidate(ddlist);
|
2017-11-07 17:00:55 +01:00
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_COORD_CHG) {
|
2020-04-08 20:54:02 +02:00
|
|
|
if(ext->page) lv_dropdown_close(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2020-03-06 13:14:25 +01:00
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ddlist, LV_DROPDOWN_PART_MAIN);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ddlist, LV_DROPDOWN_PART_MAIN);
|
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ddlist, LV_DROPDOWN_PART_MAIN);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_set_height(ddlist, top + bottom + lv_font_get_line_height(font));
|
2020-01-24 06:03:43 +01:00
|
|
|
|
2020-03-10 10:41:39 +01:00
|
|
|
if(ext->page) lv_obj_refresh_style(ext->page, LV_STYLE_PROP_ALL);
|
2020-01-24 06:03:43 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_CONTROL) {
|
|
|
|
char c = *((char *)param);
|
|
|
|
if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) {
|
|
|
|
if(ext->page == NULL) {
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_open(ddlist);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(ext->sel_opt_id + 1 < ext->option_cnt) {
|
2020-01-24 06:03:43 +01:00
|
|
|
ext->sel_opt_id++;
|
2020-04-08 20:54:02 +02:00
|
|
|
position_to_selected(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(c == LV_KEY_LEFT || c == LV_KEY_UP) {
|
2020-01-24 06:03:43 +01:00
|
|
|
|
|
|
|
if(ext->page == NULL) {
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_open(ddlist);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(ext->sel_opt_id > 0) {
|
2020-01-24 06:03:43 +01:00
|
|
|
ext->sel_opt_id--;
|
2020-04-08 20:54:02 +02:00
|
|
|
position_to_selected(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(c == LV_KEY_ESC) {
|
|
|
|
ext->sel_opt_id = ext->sel_opt_id_orig;
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_close(ddlist);
|
2020-01-24 06:03:43 +01:00
|
|
|
}
|
2020-01-23 17:16:11 +01:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
2018-10-05 17:22:49 +02:00
|
|
|
bool * editable = (bool *)param;
|
2019-04-04 07:15:40 +02:00
|
|
|
*editable = true;
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/**
|
|
|
|
* Signal function of the drop down list's scrollable part
|
|
|
|
* @param scrl pointer to a drop down list's scrollable part
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
2017-11-06 16:27:00 +01:00
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2017-11-05 00:48:57 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_res_t lv_dropdown_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
2017-11-05 00:48:57 +01:00
|
|
|
{
|
2017-11-06 16:27:00 +01:00
|
|
|
lv_res_t res;
|
2017-11-05 00:48:57 +01:00
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
2020-01-23 17:16:11 +01:00
|
|
|
res = ancestor_page_signal(page, sign, param);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2019-12-07 21:11:38 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, "");
|
2017-11-07 17:00:55 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * ddlist = page_ext->ddlist;
|
2017-12-03 00:35:39 +01:00
|
|
|
|
2019-04-11 06:26:41 +02:00
|
|
|
if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
2020-01-01 15:25:16 +01:00
|
|
|
/* Make possible to draw on the full width of the background to redraw the selected rectangle
|
|
|
|
* when the ddlist is scrolled in fix height mode.
|
|
|
|
* (The scrollabel is scrolled the "select rectangle" is drawn on the bg too)*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ddlist, LV_DROPDOWN_PART_LIST);
|
|
|
|
lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_LIST);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(page);
|
2020-03-10 10:41:39 +01:00
|
|
|
scrl->ext_draw_pad = LV_MATH_MAX3(scrl->ext_draw_pad, left, right);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_RELEASED) {
|
2019-02-26 16:07:40 +01:00
|
|
|
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
2020-01-23 17:16:11 +01:00
|
|
|
page_release_handler(page);
|
2019-02-26 16:07:40 +01:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_PRESSED) {
|
|
|
|
page_press_handler(page);
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_CLEANUP) {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->page = NULL; /*The page is just being deleted*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal function of the drop down list's scrollable part
|
|
|
|
* @param scrl pointer to a drop down list's scrollable part
|
|
|
|
* @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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_res_t lv_dropdown_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
|
2020-01-23 17:16:11 +01:00
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_page_scrl_signal(scrl, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, "");
|
|
|
|
|
|
|
|
lv_obj_t * page = lv_obj_get_parent(scrl);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * ddlist = page_ext->ddlist;
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
if(sign == LV_SIGNAL_RELEASED) {
|
2020-01-23 17:16:11 +01:00
|
|
|
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
|
|
|
page_release_handler(page);
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_PRESSED) {
|
|
|
|
page_press_handler(page);
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_DRAG_BEGIN) {
|
|
|
|
ext->pr_opt_id = LV_DROPDOWN_PR_NONE;
|
|
|
|
lv_obj_invalidate(page);
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
|
|
|
/* Make possible to draw on the full width of the background to redraw the selected rectangle
|
|
|
|
* when the ddlist is scrolled in fix height mode.
|
|
|
|
* (The scrollabel is scrolled the "select rectangle" is drawn on the bg too)*/
|
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ddlist, LV_DROPDOWN_PART_LIST);
|
|
|
|
lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_LIST);
|
2020-03-10 10:41:39 +01:00
|
|
|
scrl->ext_draw_pad = LV_MATH_MAX3(scrl->ext_draw_pad, left, right);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-11-06 16:27:00 +01:00
|
|
|
return res;
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-01-01 15:25:16 +01:00
|
|
|
/**
|
|
|
|
* Get the style descriptor of a part of the object
|
|
|
|
* @param page pointer the object
|
2020-02-14 12:36:44 +01:00
|
|
|
* @param part the part from `lv_dropdown_part_t`. (LV_DROPDOWN_PART_...)
|
2020-01-01 15:25:16 +01:00
|
|
|
* @return pointer to the style descriptor of the specified part
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_style_list_t * lv_dropdown_get_style(lv_obj_t * ddlist, uint8_t part)
|
2020-01-01 15:25:16 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_t * style_dsc_p;
|
2020-01-01 15:25:16 +01:00
|
|
|
|
|
|
|
switch(part) {
|
2020-03-06 13:14:25 +01:00
|
|
|
case LV_DROPDOWN_PART_MAIN:
|
2020-02-26 19:48:27 +01:00
|
|
|
style_dsc_p = &ddlist->style_list;
|
|
|
|
break;
|
|
|
|
case LV_DROPDOWN_PART_LIST:
|
|
|
|
style_dsc_p = &ext->style_page;
|
|
|
|
break;
|
|
|
|
case LV_DROPDOWN_PART_SCRLBAR:
|
|
|
|
style_dsc_p = &ext->style_scrlbar;
|
|
|
|
break;
|
|
|
|
case LV_DROPDOWN_PART_SELECTED:
|
|
|
|
style_dsc_p = &ext->style_selected;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
2020-01-01 15:25:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return style_dsc_p;
|
|
|
|
}
|
|
|
|
|
2020-02-13 14:26:51 +01:00
|
|
|
static void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_state_t state)
|
2020-01-24 14:55:56 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_obj_t * page = ext->page;
|
2020-02-21 16:56:05 +01:00
|
|
|
lv_state_t state_orig = page->state;
|
2020-01-24 14:55:56 +01:00
|
|
|
|
2020-02-22 01:09:29 +01:00
|
|
|
page->state = LV_STATE_DEFAULT;
|
2020-02-21 16:56:05 +01:00
|
|
|
page->state |= state;
|
2020-01-24 14:55:56 +01:00
|
|
|
|
|
|
|
/*Draw a rectangle under the selected item*/
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ddlist, LV_DROPDOWN_PART_LIST);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ddlist, LV_DROPDOWN_PART_LIST);
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
|
|
|
|
|
|
|
/*Draw the selected*/
|
|
|
|
lv_obj_t * label = get_label(ddlist);
|
|
|
|
lv_area_t rect_area;
|
|
|
|
rect_area.y1 = label->coords.y1;
|
|
|
|
rect_area.y1 += id * (font_h + line_space);
|
|
|
|
rect_area.y1 -= line_space / 2;
|
|
|
|
|
|
|
|
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
|
|
|
|
rect_area.x1 = ext->page->coords.x1;
|
|
|
|
rect_area.x2 = ext->page->coords.x2;
|
|
|
|
|
|
|
|
lv_draw_rect_dsc_t sel_rect;
|
|
|
|
lv_draw_rect_dsc_init(&sel_rect);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_init_draw_rect_dsc(ddlist, LV_DROPDOWN_PART_SELECTED, &sel_rect);
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_draw_rect(&rect_area, clip_area, &sel_rect);
|
|
|
|
|
2020-02-21 16:56:05 +01:00
|
|
|
page->state = state_orig;
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-13 14:26:51 +01:00
|
|
|
static void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_state_t state)
|
2020-01-24 14:55:56 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_obj_t * page = ext->page;
|
2020-02-21 16:56:05 +01:00
|
|
|
lv_state_t state_orig = page->state;
|
2020-01-24 14:55:56 +01:00
|
|
|
|
2020-02-22 01:09:29 +01:00
|
|
|
page->state = LV_STATE_DEFAULT;
|
2020-02-21 16:56:05 +01:00
|
|
|
page->state |= state;
|
2020-01-24 14:55:56 +01:00
|
|
|
|
|
|
|
lv_draw_label_dsc_t label_dsc;
|
|
|
|
lv_draw_label_dsc_init(&label_dsc);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_init_draw_label_dsc(ddlist, LV_DROPDOWN_PART_SELECTED, &label_dsc);
|
2020-03-16 16:23:14 +01:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
label_dsc.line_space = lv_obj_get_style_text_line_space(ddlist,
|
|
|
|
LV_DROPDOWN_PART_LIST); /*Line space should come from the page*/
|
2020-01-24 14:55:56 +01:00
|
|
|
|
|
|
|
lv_obj_t * label = get_label(ddlist);
|
2020-03-10 08:34:07 +01:00
|
|
|
if(label == NULL) return;
|
|
|
|
|
2020-03-16 16:23:14 +01:00
|
|
|
lv_label_align_t align = lv_label_get_align(label);
|
|
|
|
|
|
|
|
if(align == LV_LABEL_ALIGN_CENTER) label_dsc.flag |= LV_TXT_FLAG_CENTER;
|
|
|
|
else if(align == LV_LABEL_ALIGN_RIGHT) label_dsc.flag |= LV_TXT_FLAG_RIGHT;
|
|
|
|
|
|
|
|
lv_coord_t font_h = lv_font_get_line_height(label_dsc.font);
|
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_area_t area_sel;
|
|
|
|
area_sel.y1 = label->coords.y1;
|
|
|
|
area_sel.y1 += id * (font_h + label_dsc.line_space);
|
|
|
|
area_sel.y1 -= label_dsc.line_space / 2;
|
|
|
|
|
|
|
|
area_sel.y2 = area_sel.y1 + font_h + label_dsc.line_space - 1;
|
|
|
|
area_sel.x1 = page->coords.x1;
|
|
|
|
area_sel.x2 = page->coords.x2;
|
|
|
|
lv_area_t mask_sel;
|
|
|
|
bool area_ok;
|
|
|
|
area_ok = lv_area_intersect(&mask_sel, clip_area, &area_sel);
|
|
|
|
if(area_ok) {
|
|
|
|
lv_draw_label(&label->coords, &mask_sel, &label_dsc, lv_label_get_text(label), NULL);
|
|
|
|
}
|
2020-02-21 16:56:05 +01:00
|
|
|
page->state = state_orig;
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**
|
|
|
|
* Called when a drop down list is released to open it or set new option
|
2020-01-23 17:16:11 +01:00
|
|
|
* @param page pointer to the drop down list's page
|
|
|
|
* @return LV_RES_INV if the page is not being deleted in the user callback. Else LV_RES_OK
|
2017-02-06 10:06:18 +01:00
|
|
|
*/
|
2020-01-23 17:16:11 +01:00
|
|
|
static lv_res_t page_release_handler(lv_obj_t * page)
|
2017-02-06 10:06:18 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * ddlist = page_ext->ddlist;
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2019-06-27 08:33:14 +02:00
|
|
|
#if LV_USE_GROUP
|
2020-01-23 17:16:11 +01:00
|
|
|
/*Leave edit mode once a new item is selected*/
|
|
|
|
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
|
|
|
|
ext->sel_opt_id_orig = ext->sel_opt_id;
|
|
|
|
lv_group_t * g = lv_obj_get_group(ddlist);
|
|
|
|
if(lv_group_get_editing(g)) {
|
|
|
|
lv_group_set_editing(g, false);
|
2019-02-26 16:07:40 +01:00
|
|
|
}
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
2018-03-01 12:21:49 +01:00
|
|
|
#endif
|
2019-04-22 10:17:21 +02:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
/*Search the clicked option (For KEYPAD and ENCODER the new value should be already set)*/
|
|
|
|
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER || lv_indev_get_type(indev) == LV_INDEV_TYPE_BUTTON) {
|
|
|
|
lv_point_t p;
|
|
|
|
lv_indev_get_point(indev, &p);
|
2020-01-24 14:55:56 +01:00
|
|
|
ext->sel_opt_id = get_id_on_point(ddlist, p.x, p.y);
|
2020-01-23 17:16:11 +01:00
|
|
|
ext->sel_opt_id_orig = ext->sel_opt_id;
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 20:54:02 +02:00
|
|
|
lv_dropdown_close(ddlist);
|
2019-04-22 10:17:21 +02:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
/*Invalidate to refresh the text*/
|
|
|
|
if(ext->show_selected) lv_obj_invalidate(ddlist);
|
2019-03-23 09:20:41 -04:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
uint32_t id = ext->sel_opt_id; /*Just to use uint32_t in event data*/
|
|
|
|
lv_res_t res = lv_event_send(ddlist, LV_EVENT_VALUE_CHANGED, &id);
|
|
|
|
if(res != LV_RES_OK) return res;
|
|
|
|
if(ext->page == NULL) return LV_RES_INV;
|
2019-03-23 09:20:41 -04:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
return LV_RES_OK;
|
2019-03-23 09:20:41 -04:00
|
|
|
}
|
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
static void page_press_handler(lv_obj_t * page)
|
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_obj_t * ddlist = page_ext->ddlist;
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-24 14:55:56 +01:00
|
|
|
|
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
|
|
|
if(indev && (lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER || lv_indev_get_type(indev) == LV_INDEV_TYPE_BUTTON)) {
|
|
|
|
lv_point_t p;
|
|
|
|
lv_indev_get_point(indev, &p);
|
|
|
|
ext->pr_opt_id = get_id_on_point(ddlist, p.x, p.y);
|
|
|
|
lv_obj_invalidate(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y)
|
|
|
|
{
|
|
|
|
lv_obj_t * label = get_label(ddlist);
|
2020-03-10 08:34:07 +01:00
|
|
|
if(label == NULL) return 0;
|
2020-01-24 14:55:56 +01:00
|
|
|
x -= label->coords.x1;
|
|
|
|
y -= label->coords.y1;
|
|
|
|
uint16_t letter_i;
|
|
|
|
|
|
|
|
lv_point_t p = {x, y};
|
|
|
|
letter_i = lv_label_get_letter_on(label, &p);
|
|
|
|
uint16_t opt = 0;
|
|
|
|
const char * txt = lv_label_get_text(label);
|
|
|
|
uint32_t i = 0;
|
|
|
|
uint32_t i_prev = 0;
|
|
|
|
|
|
|
|
uint32_t letter_cnt = 0;
|
|
|
|
for(letter_cnt = 0; letter_cnt < letter_i; letter_cnt++) {
|
2020-02-25 15:32:35 +01:00
|
|
|
uint32_t letter = lv_txt_encoded_next(txt, &i);
|
2020-03-30 15:06:14 -07:00
|
|
|
/*Count the lines to reach the clicked letter. But ignore the last '\n' because it
|
2020-01-24 14:55:56 +01:00
|
|
|
* still belongs to the clicked line*/
|
|
|
|
if(letter == '\n' && i_prev != letter_i) opt++;
|
|
|
|
i_prev = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**
|
|
|
|
* Set the position of list when it is closed to show the selected item
|
|
|
|
* @param ddlist pointer to a drop down list
|
|
|
|
*/
|
2020-04-08 20:54:02 +02:00
|
|
|
static void position_to_selected(lv_obj_t * ddlist)
|
2017-02-06 10:06:18 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ddlist, LV_DROPDOWN_PART_LIST);
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(ext->page);
|
|
|
|
lv_obj_t * label = get_label(ddlist);
|
2020-03-10 08:34:07 +01:00
|
|
|
if(label == NULL) return;
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
lv_coord_t h = lv_obj_get_height(ext->page);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ddlist, LV_DROPDOWN_PART_LIST);
|
2017-10-05 11:29:21 +02:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_coord_t line_y1 = ext->sel_opt_id * (font_h + line_space) + label->coords.y1 - scrl->coords.y1;
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_set_y(scrl, -line_y1 + (h - font_h) / 2);
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_invalidate(ext->page);
|
2017-02-06 10:06:18 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 10:34:39 +01:00
|
|
|
|
2019-10-15 10:32:15 +02:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
static lv_obj_t * get_label(const lv_obj_t * ddlist)
|
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
2020-01-23 17:16:11 +01:00
|
|
|
if(ext->page == NULL) return NULL;
|
2019-10-30 10:34:39 +01:00
|
|
|
|
2020-01-23 17:16:11 +01:00
|
|
|
return lv_obj_get_child(lv_page_get_scrl(ext->page), NULL);
|
2019-04-20 06:37:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
#endif
|