1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00
lvgl/src/lv_objx/lv_ddlist.c

995 lines
34 KiB
C
Raw Normal View History

/**
* @file lv_ddlist.c
2018-06-19 09:49:58 +02:00
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_ddlist.h"
#if LV_USE_DDLIST != 0
2019-09-24 16:30:38 +02:00
#include "../lv_core/lv_debug.h"
#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"
#include "../lv_themes/lv_theme.h"
#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"
#include <string.h>
/*********************
* DEFINES
*********************/
#define LV_OBJX_NAME "lv_ddlist"
2019-06-19 00:35:35 +02:00
#if LV_USE_ANIMATION == 0
2019-04-04 07:15:40 +02:00
#undef LV_DDLIST_DEF_ANIM_TIME
#define LV_DDLIST_DEF_ANIM_TIME 0 /*No animation*/
2017-11-27 17:48:54 +01:00
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2019-09-06 19:53:39 +02:00
static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * clip_area, lv_design_mode_t mode);
2017-11-16 10:20:30 +01:00
static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param);
static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
static lv_style_dsc_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part);
static lv_res_t release_handler(lv_obj_t * ddlist);
2019-06-11 13:51:14 +02:00
static void lv_ddlist_refr_size(lv_obj_t * ddlist, lv_anim_enable_t anim);
static void lv_ddlist_pos_current_option(lv_obj_t * ddlist);
2019-06-06 06:05:40 +02:00
static void lv_ddlist_refr_width(lv_obj_t * ddlist);
#if LV_USE_ANIMATION
2019-04-22 10:17:21 +02:00
static void lv_ddlist_anim_ready_cb(lv_anim_t * a);
2019-06-06 06:05:40 +02:00
static void lv_ddlist_anim_finish(lv_obj_t * ddlist);
static void lv_ddlist_adjust_height(lv_obj_t * ddlist, lv_anim_value_t height);
#endif
/**********************
* STATIC VARIABLES
**********************/
2019-04-04 07:15:40 +02:00
static lv_signal_cb_t ancestor_signal;
static lv_signal_cb_t ancestor_scrl_signal;
static lv_design_cb_t ancestor_design;
/**********************
* 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
* @return pointer to the created drop down list
*/
lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy)
{
2018-10-05 17:22:49 +02:00
LV_LOG_TRACE("drop down list create started");
2018-07-25 17:57:08 +02:00
/*Create the ancestor drop down list*/
lv_obj_t * new_ddlist = lv_page_create(par, copy);
2019-09-24 23:14:17 +02:00
LV_ASSERT_MEM(new_ddlist);
if(new_ddlist == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_ddlist);
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_ddlist));
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(new_ddlist);
2018-06-19 09:49:58 +02:00
/*Allocate the drop down list type specific extended data*/
lv_ddlist_ext_t * ext = lv_obj_allocate_ext_attr(new_ddlist, sizeof(lv_ddlist_ext_t));
2019-09-24 23:14:17 +02:00
LV_ASSERT_MEM(ext);
if(ext == NULL) {
lv_obj_del(new_ddlist);
return NULL;
}
/*Initialize the allocated 'ext' */
2019-04-04 07:15:40 +02:00
ext->label = NULL;
ext->symbol = NULL;
2019-04-04 07:15:40 +02:00
ext->opened = 0;
ext->fix_height = 0;
ext->sel_opt_id = 0;
ext->sel_opt_id_ori = 0;
2019-04-04 07:15:40 +02:00
ext->option_cnt = 0;
ext->stay_open = 0;
lv_style_dsc_init(&ext->style_sel);
2018-11-09 20:32:08 +08:00
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_cb(new_ddlist, lv_ddlist_signal);
lv_obj_set_signal_cb(lv_page_get_scrl(new_ddlist), lv_ddlist_scrl_signal);
lv_obj_set_design_cb(new_ddlist, lv_ddlist_design);
/*Init the new drop down list drop down list*/
if(copy == NULL) {
2019-06-19 00:35:35 +02:00
lv_page_set_anim_time(new_ddlist, LV_DDLIST_DEF_ANIM_TIME);
lv_obj_t * scrl = lv_page_get_scrl(new_ddlist);
lv_obj_set_drag(scrl, false);
lv_page_set_scrl_fit2(new_ddlist, LV_FIT_FILL, LV_FIT_TIGHT);
2017-02-06 16:05:02 +01:00
/*Save (a later restore) the original X coordinate because it changes as the FITs applies*/
lv_coord_t x;
if(lv_obj_get_base_dir(new_ddlist) == LV_BIDI_DIR_RTL) x = lv_obj_get_x(new_ddlist) + lv_obj_get_width(new_ddlist);
else x = lv_obj_get_x(new_ddlist);
2017-11-16 10:20:30 +01:00
ext->label = lv_label_create(new_ddlist, NULL);
lv_cont_set_fit2(new_ddlist, LV_FIT_TIGHT, LV_FIT_NONE);
lv_page_set_sb_mode(new_ddlist, LV_SB_MODE_HIDE);
2017-11-05 22:37:03 +01:00
lv_ddlist_set_options(new_ddlist, "Option 1\nOption 2\nOption 3");
lv_obj_reset_style(new_ddlist, LV_DDLIST_PART_SCRL);
_ot(new_ddlist, LV_DDLIST_PART_SCRL, DDLIST_SCRL);
_ot(new_ddlist, LV_DDLIST_PART_SEL, DDLIST_SEL);
/*Restore the original X coordinate*/
if(lv_obj_get_base_dir(new_ddlist) == LV_BIDI_DIR_RTL) lv_obj_set_x(new_ddlist, x - lv_obj_get_width(new_ddlist));
else lv_obj_set_x(new_ddlist, x);
}
/*Copy an existing drop down list*/
else {
2018-06-19 09:49:58 +02:00
lv_ddlist_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
2019-04-04 07:15:40 +02:00
ext->label = lv_label_create(new_ddlist, copy_ext->label);
2017-11-16 10:20:30 +01:00
lv_label_set_text(ext->label, lv_label_get_text(copy_ext->label));
2019-04-04 07:15:40 +02:00
ext->sel_opt_id = copy_ext->sel_opt_id;
2019-03-15 22:51:49 +01:00
ext->sel_opt_id_ori = copy_ext->sel_opt_id;
2019-04-04 07:15:40 +02:00
ext->fix_height = copy_ext->fix_height;
ext->option_cnt = copy_ext->option_cnt;
ext->symbol = copy_ext->symbol;
2019-04-04 07:15:40 +02:00
ext->stay_open = copy_ext->stay_open;
}
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
return new_ddlist;
}
/*=====================
* Setter functions
*====================*/
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"
*/
2017-11-05 22:37:03 +01:00
void lv_ddlist_set_options(lv_obj_t * ddlist, const char * options)
2017-06-07 12:38:43 +02:00
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
LV_ASSERT_STR(options);
lv_ddlist_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++;
}
2019-04-19 07:15:39 +02:00
ext->option_cnt++; /*Last option has no `\n`*/
2019-04-04 07:15:40 +02:00
ext->sel_opt_id = 0;
2019-03-17 04:32:37 +01:00
ext->sel_opt_id_ori = 0;
2017-11-16 10:20:30 +01:00
lv_label_set_text(ext->label, options);
2019-04-19 07:15:39 +02:00
2019-04-20 06:37:06 +02:00
lv_ddlist_refr_width(ddlist);
lv_label_align_t align = lv_label_get_align(ext->label);
switch(align) {
2019-06-06 06:05:40 +02:00
case LV_LABEL_ALIGN_LEFT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0); break;
case LV_LABEL_ALIGN_CENTER: lv_obj_align(ext->label, NULL, LV_ALIGN_CENTER, 0, 0); break;
case LV_LABEL_ALIGN_RIGHT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); break;
2019-04-19 07:28:48 +02:00
}
2019-04-19 07:15:39 +02:00
lv_ddlist_refr_size(ddlist, false);
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);
*/
void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
if(ext->sel_opt_id == sel_opt) return;
2017-02-06 16:05:02 +01:00
2019-04-04 07:15:40 +02:00
ext->sel_opt_id = sel_opt < ext->option_cnt ? sel_opt : ext->option_cnt - 1;
2019-03-08 15:48:44 +01:00
ext->sel_opt_id_ori = ext->sel_opt_id;
2017-02-06 16:05:02 +01:00
/*Move the list to show the current option*/
if(ext->opened == 0) {
lv_ddlist_pos_current_option(ddlist);
2017-10-05 11:29:21 +02:00
} else {
lv_obj_invalidate(ddlist);
2017-02-06 16:05:02 +01:00
}
}
/**
2019-06-17 16:05:30 +02:00
* Set a fix height for the drop down list
2017-10-05 11:29:21 +02:00
* If 0 then the opened ddlist will be auto. sized else the set height will be applied.
2017-02-06 16:05:02 +01:00
* @param ddlist pointer to a drop down list
2017-10-05 11:29:21 +02:00
* @param h the height when the list is opened (0: auto size)
2017-02-06 16:05:02 +01:00
*/
2017-11-23 21:28:36 +01:00
void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h)
2017-02-06 16:05:02 +01:00
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
if(ext->fix_height == h) return;
2017-10-05 11:29:21 +02:00
ext->fix_height = h;
lv_ddlist_refr_size(ddlist, false);
2017-02-06 16:05:02 +01:00
}
/**
2019-06-17 16:05:30 +02:00
* Set a fix width for the drop down list
* @param ddlist pointer to a drop down list
2019-06-17 16:05:30 +02:00
* @param w the width when the list is opened (0: auto size)
*/
2019-06-17 16:05:30 +02:00
void lv_ddlist_set_fix_width(lv_obj_t * ddlist, lv_coord_t w)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-06-17 16:05:30 +02:00
if(w == 0) {
lv_cont_set_fit2(ddlist, LV_FIT_TIGHT, lv_cont_get_fit_bottom(ddlist));
} else {
lv_cont_set_fit2(ddlist, LV_FIT_NONE, lv_cont_get_fit_bottom(ddlist));
lv_obj_set_width(ddlist, w);
}
switch(lv_label_get_align(ext->label)) {
case LV_LABEL_ALIGN_LEFT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0); break;
case LV_LABEL_ALIGN_CENTER: lv_obj_align(ext->label, NULL, LV_ALIGN_CENTER, 0, 0); break;
case LV_LABEL_ALIGN_RIGHT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); break;
}
lv_ddlist_refr_size(ddlist, false);
}
/**
* Set an arrow or other symbol to display when the drop-down list is closed.
* @param ddlist pointer to drop down list object
* @param symbol a text like `LV_SYMBOL_DOWN` or NULL to not draw icon
*/
void lv_ddlist_set_symbol(lv_obj_t * ddlist, const char * symbol)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
ext->symbol = symbol;
lv_obj_invalidate(ddlist);
}
/**
* Leave the list opened when a new value is selected
* @param ddlist pointer to drop down list object
* @param en enable/disable "stay open" feature
*/
void lv_ddlist_set_stay_open(lv_obj_t * ddlist, bool en)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
/*Set the flag*/
ext->stay_open = en ? 1 : 0;
}
2019-04-04 07:15:40 +02:00
void lv_ddlist_set_align(lv_obj_t * ddlist, lv_label_align_t align)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
2019-04-04 07:15:40 +02:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-04-04 07:15:40 +02:00
lv_label_set_align(ext->label, align);
2019-04-19 07:28:48 +02:00
switch(align) {
2019-06-06 06:05:40 +02:00
case LV_LABEL_ALIGN_LEFT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0); break;
case LV_LABEL_ALIGN_CENTER: lv_obj_align(ext->label, NULL, LV_ALIGN_CENTER, 0, 0); break;
case LV_LABEL_ALIGN_RIGHT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); break;
2019-04-19 07:28:48 +02:00
}
}
/*=====================
* Getter functions
*====================*/
/**
* 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")
*/
const char * lv_ddlist_get_options(const lv_obj_t * ddlist)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2017-11-16 10:20:30 +01:00
return lv_label_get_text(ext->label);
}
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);
*/
uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist)
2017-02-06 16:05:02 +01:00
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_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
}
/**
* Get the total number of options
* @param ddlist pointer to drop down list object
* @return the total number of options in the list
*/
uint16_t lv_ddlist_get_option_cnt(const lv_obj_t * ddlist)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
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
*/
2019-03-29 16:10:18 +01:00
void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf, uint16_t buf_size)
2017-06-07 12:38:43 +02:00
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_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;
2017-11-16 10:20:30 +01:00
const char * opt_txt = lv_label_get_text(ext->label);
2019-12-02 12:20:01 +01:00
size_t txt_len = strlen(opt_txt);
2018-06-19 09:49:58 +02:00
2017-11-16 10:20:30 +01:00
for(i = 0; i < txt_len && line != ext->sel_opt_id; i++) {
2019-04-04 07:15:40 +02:00
if(opt_txt[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;
2019-03-29 16:10:18 +01:00
for(c = 0; opt_txt[i] != '\n' && i < txt_len; c++, i++) {
if(buf_size && c >= buf_size - 1) {
LV_LOG_WARN("lv_ddlist_get_selected_str: the buffer was too small")
break;
}
buf[c] = opt_txt[i];
}
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.
* @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
*/
lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist)
2017-02-06 16:05:02 +01:00
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2017-10-05 11:29:21 +02:00
return ext->fix_height;
2017-02-06 16:05:02 +01:00
}
/**
* Get the symbol to draw when the drop-down list is closed
* @param ddlist pointer to drop down list object
* @return the symbol or NULL if not enabled
*/
const char * lv_ddlist_get_symbol(lv_obj_t * ddlist)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
return ext->symbol;
}
/**
* Get whether the drop down list stay open after selecting a value or not
* @param ddlist pointer to drop down list object
*/
bool lv_ddlist_get_stay_open(lv_obj_t * ddlist)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
return ext->stay_open ? true : false;
}
/**
* Get the alignment of the labels in a drop down list
* @param ddlist pointer to a drop down list object
* @return alignment of labels
*/
2019-04-04 07:15:40 +02:00
lv_label_align_t lv_ddlist_get_align(const lv_obj_t * ddlist)
{
2019-04-04 07:15:40 +02:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-04-04 07:15:40 +02:00
return lv_label_get_align(ext->label);
}
2017-11-10 15:01:40 +01:00
/*=====================
* Other functions
*====================*/
/**
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
2019-06-11 13:51:14 +02:00
* @param anim_en LV_ANIM_EN: use animation; LV_ANIM_OFF: not use animations
*/
2019-06-11 13:51:14 +02:00
void lv_ddlist_open(lv_obj_t * ddlist, lv_anim_enable_t anim)
{
#if LV_USE_ANIMATION == 0
anim = false;
#endif
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-04-04 07:15:40 +02:00
ext->opened = 1;
2017-11-10 15:01:40 +01:00
lv_obj_set_drag(lv_page_get_scrl(ddlist), true);
2019-06-11 13:51:14 +02:00
lv_ddlist_refr_size(ddlist, anim);
2017-11-10 15:01:40 +01:00
}
/**
* Close (Collapse) the drop down list
* @param ddlist pointer to drop down list object
2019-06-11 13:51:14 +02:00
* @param anim_en LV_ANIM_ON: use animation; LV_ANIM_OFF: not use animations
2017-11-10 15:01:40 +01:00
*/
2019-06-11 13:51:14 +02:00
void lv_ddlist_close(lv_obj_t * ddlist, lv_anim_enable_t anim)
2017-11-10 15:01:40 +01:00
{
#if LV_USE_ANIMATION == 0
anim = false;
#endif
2017-11-10 15:01:40 +01:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-04-04 07:15:40 +02:00
ext->opened = 0;
2017-11-10 15:01:40 +01:00
lv_obj_set_drag(lv_page_get_scrl(ddlist), false);
2019-06-11 13:51:14 +02:00
lv_ddlist_refr_size(ddlist, anim);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the drop down lists
* @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
* @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`
*/
2019-09-06 19:53:39 +02:00
static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * clip_area, lv_design_mode_t mode)
{
/*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);
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
2019-09-06 19:53:39 +02:00
ancestor_design(ddlist, clip_area, mode);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2017-11-19 20:45:40 +01:00
/*If the list is opened draw a rectangle under the selected item*/
2019-03-23 09:20:41 -04:00
if(ext->opened != 0 || ext->force_sel) {
const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_BG, LV_STYLE_FONT);
2020-01-06 22:14:04 +01:00
lv_style_int_t line_space = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_LINE_SPACE);
2019-04-23 15:56:59 +02:00
lv_coord_t font_h = lv_font_get_line_height(font);
2017-11-19 20:45:40 +01:00
/*Draw the selected*/
2017-11-23 21:28:36 +01:00
lv_area_t rect_area;
2017-11-16 10:20:30 +01:00
rect_area.y1 = ext->label->coords.y1;
rect_area.y1 += ext->sel_opt_id * (font_h + line_space);
rect_area.y1 -= line_space / 2;
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
2017-11-05 22:37:03 +01:00
rect_area.x1 = ddlist->coords.x1;
rect_area.x2 = ddlist->coords.x2;
lv_draw_rect_dsc_t sel_rect;
lv_draw_rect_dsc_init(&sel_rect);
lv_obj_init_draw_rect_dsc(ddlist, LV_DDLIST_PART_SEL, &sel_rect);
lv_draw_rect(&rect_area, clip_area, &sel_rect);
}
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
2017-12-17 20:11:14 +01:00
/*Redraw the text on the selected area with a different color*/
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
/*Redraw only in opened state*/
2019-03-23 09:20:41 -04:00
if(ext->opened || ext->force_sel) {
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(ddlist, LV_DDLIST_PART_SEL, &label_dsc);
lv_coord_t font_h = lv_font_get_line_height(label_dsc.font);
2018-10-05 17:22:49 +02:00
lv_area_t area_sel;
area_sel.y1 = ext->label->coords.y1;
area_sel.y1 += ext->sel_opt_id * (font_h + label_dsc.line_space);
area_sel.y1 -= label_dsc.line_space / 2;
2018-10-05 17:22:49 +02:00
area_sel.y2 = area_sel.y1 + font_h + label_dsc.line_space - 1;
2018-10-05 17:22:49 +02:00
area_sel.x1 = ddlist->coords.x1;
area_sel.x2 = ddlist->coords.x2;
lv_area_t mask_sel;
bool area_ok;
2019-09-06 19:53:39 +02:00
area_ok = lv_area_intersect(&mask_sel, clip_area, &area_sel);
2018-10-05 17:22:49 +02:00
if(area_ok) {
lv_draw_label(&ext->label->coords, &mask_sel, &label_dsc, lv_label_get_text(ext->label), NULL);
2018-10-05 17:22:49 +02:00
}
2017-12-17 20:11:14 +01:00
}
2018-11-09 20:25:48 +08:00
/*Closed...*/
2019-04-04 07:15:40 +02:00
else {
/*Draw the symbol if enabled*/
if(ext->symbol) {
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(ddlist, LV_DDLIST_PART_BG, &label_dsc);
lv_coord_t font_h = lv_font_get_line_height(label_dsc.font);
lv_area_t area_icon;
lv_coord_t icon_width = lv_txt_get_width(ext->symbol, (uint16_t)strlen(ext->symbol), label_dsc.font, 0, 0);
2019-12-02 16:09:35 +01:00
if(lv_label_get_align(ext->label) != LV_LABEL_ALIGN_RIGHT) {
2020-01-06 22:14:04 +01:00
area_icon.x2 = ddlist->coords.x2 - lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_RIGHT);
area_icon.x1 = area_icon.x2 - icon_width;
} else {
2020-01-06 22:14:04 +01:00
area_icon.x1 = ddlist->coords.x1 + lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_LEFT);
area_icon.x2 = area_icon.x1 + icon_width;
}
2019-04-04 07:15:40 +02:00
area_icon.y1 = ddlist->coords.y1 + label_dsc.line_space;
area_icon.y2 = area_icon.y1 + font_h;
2019-04-04 07:15:40 +02:00
lv_area_t mask_icon;
2019-04-04 07:15:40 +02:00
bool area_ok;
area_ok = lv_area_intersect(&mask_icon, clip_area, &area_icon);
2019-04-04 07:15:40 +02:00
if(area_ok) {
lv_draw_label(&area_icon, &mask_icon, &label_dsc, ext->symbol, NULL);
2019-04-04 07:15:40 +02:00
}
}
}
2018-08-10 01:11:20 +02:00
/*Draw the scrollbar in the ancestor page design function*/
2019-09-06 19:53:39 +02:00
ancestor_design(ddlist, clip_area, mode);
}
2019-09-06 19:53:39 +02:00
return LV_DESIGN_RES_OK;
}
/**
* 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
*/
2017-11-16 10:20:30 +01:00
static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
{
lv_res_t res;
if(sign == LV_SIGNAL_GET_STYLE) {
uint8_t ** type_p = param;
lv_style_dsc_t ** style_dsc_p = param;
*style_dsc_p = lv_ddlist_get_style(ddlist, **type_p);
return LV_RES_OK;
}
/* Include the ancient signal function */
res = ancestor_signal(ddlist, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
2017-12-03 00:35:39 +01:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_ddlist_refr_width(ddlist);
lv_ddlist_refr_size(ddlist, 0);
} else if(sign == LV_SIGNAL_BASE_DIR_CHG) {
lv_label_align_t align = lv_label_get_align(ext->label);
switch(align) {
case LV_LABEL_ALIGN_LEFT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0); break;
case LV_LABEL_ALIGN_CENTER: lv_obj_align(ext->label, NULL, LV_ALIGN_CENTER, 0, 0); break;
case LV_LABEL_ALIGN_RIGHT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); break;
}
lv_ddlist_refr_size(ddlist, 0);
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_CLEANUP) {
2017-12-03 00:35:39 +01:00
ext->label = NULL;
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_FOCUS) {
#if LV_USE_GROUP
2019-04-04 07:15:40 +02:00
lv_group_t * g = lv_obj_get_group(ddlist);
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-11-08 22:39:08 +08:00
2018-09-24 22:59:48 +02:00
/*Encoders need special handling*/
if(indev_type == LV_INDEV_TYPE_ENCODER) {
/*Open the list if editing*/
if(editing) {
2019-04-04 07:15:40 +02:00
ext->opened = true;
2018-09-24 22:59:48 +02:00
ext->sel_opt_id_ori = ext->sel_opt_id;
lv_ddlist_refr_size(ddlist, true);
}
/*Close the lift if navigating*/
else {
2019-04-04 07:15:40 +02:00
ext->opened = false;
2018-09-24 22:59:48 +02:00
ext->sel_opt_id = ext->sel_opt_id_ori;
lv_ddlist_refr_size(ddlist, true);
}
2018-10-05 17:22:49 +02:00
} else {
2018-09-24 22:59:48 +02:00
/*Open the list if closed*/
if(!ext->opened) {
2019-04-04 07:15:40 +02:00
ext->opened = true;
ext->sel_opt_id_ori = ext->sel_opt_id; /*Save the current value. Used to revert this
state if ENER wont't be pressed*/
2018-09-24 22:59:48 +02:00
lv_ddlist_refr_size(ddlist, true);
}
}
#endif
2019-04-04 07:15:40 +02:00
} else if(sign == LV_SIGNAL_RELEASED) {
release_handler(ddlist);
2019-04-04 07:15:40 +02:00
} else if(sign == LV_SIGNAL_DEFOCUS) {
2018-09-24 22:59:48 +02:00
if(ext->opened) {
2019-04-04 07:15:40 +02:00
ext->opened = false;
ext->sel_opt_id = ext->sel_opt_id_ori;
lv_ddlist_refr_size(ddlist, true);
}
} 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) {
if(!ext->opened) {
ext->opened = 1;
lv_ddlist_refr_size(ddlist, true);
}
if(ext->sel_opt_id + 1 < ext->option_cnt) {
2019-04-04 07:15:40 +02:00
ext->sel_opt_id++;
lv_ddlist_pos_current_option(ddlist);
lv_obj_invalidate(ddlist);
}
2019-04-08 14:36:20 +02:00
} else if(c == LV_KEY_LEFT || c == LV_KEY_UP) {
if(!ext->opened) {
ext->opened = 1;
lv_ddlist_refr_size(ddlist, true);
}
2017-11-16 10:20:30 +01:00
if(ext->sel_opt_id > 0) {
2019-04-04 07:15:40 +02:00
ext->sel_opt_id--;
lv_ddlist_pos_current_option(ddlist);
lv_obj_invalidate(ddlist);
}
2019-04-08 14:36:20 +02:00
} else if(c == LV_KEY_ESC) {
if(ext->opened) {
2019-04-04 07:15:40 +02:00
ext->opened = 0;
ext->sel_opt_id = ext->sel_opt_id_ori;
lv_ddlist_refr_size(ddlist, true);
}
}
} 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
}
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
*/
static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_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, "");
2018-06-19 09:49:58 +02:00
lv_obj_t * ddlist = lv_obj_get_parent(scrl);
2017-12-03 00:35:39 +01:00
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)*/
2020-01-06 22:14:04 +01:00
lv_style_int_t left = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_LEFT);
lv_style_int_t right = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_RIGHT);
ddlist->ext_draw_pad = LV_MATH_MAX(ddlist->ext_draw_pad, LV_MATH_MAX(left, right));
2019-04-04 07:15:40 +02:00
} else if(sign == LV_SIGNAL_RELEASED) {
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
release_handler(ddlist);
}
2019-04-04 07:15:40 +02:00
} else if(sign == LV_SIGNAL_CLEANUP) {
2018-06-19 09:49:58 +02:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-04-04 07:15:40 +02:00
ext->label = NULL; /*The label is already deleted*/
2017-12-03 00:35:39 +01:00
}
return res;
}
/**
* Get the style descriptor of a part of the object
* @param page pointer the object
* @param part the part from `lv_ddlist_part_t`. (LV_DDLIST_PART_...)
* @return pointer to the style descriptor of the specified part
*/
static lv_style_dsc_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part)
{
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
lv_style_dsc_t * style_dsc_p;
switch(part) {
case LV_DDLIST_PART_BG:
style_dsc_p = &ddlist->style_dsc;
break;
case LV_DDLIST_PART_SCRL:
style_dsc_p = lv_obj_get_style(ext->page.scrl, LV_CONT_PART_MAIN);
break;
2020-01-01 18:46:22 +01:00
case LV_DDLIST_PART_SCRLBAR:
style_dsc_p = &ext->page.sb.style;
break;
case LV_DDLIST_PART_SEL:
style_dsc_p = &ext->style_sel;
break;
default:
style_dsc_p = NULL;
}
return style_dsc_p;
}
/**
* Called when a drop down list is released to open it or set new option
* @param ddlist pointer to a drop down list object
* @return LV_ACTION_RES_INV if the ddlist it deleted in the user callback else LV_ACTION_RES_OK
*/
static lv_res_t release_handler(lv_obj_t * ddlist)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
if(ext->opened == 0) { /*Open the list*/
ext->opened = 1;
lv_obj_set_drag(lv_page_get_scrl(ddlist), true);
lv_ddlist_refr_size(ddlist, true);
} else {
2017-02-06 16:05:02 +01:00
2018-06-19 09:49:58 +02:00
lv_indev_t * indev = lv_indev_get_act();
2019-06-27 08:33:14 +02:00
#if LV_USE_GROUP
/*Leave edit mode once a new item is selected*/
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
ext->sel_opt_id_ori = ext->sel_opt_id;
2019-06-06 06:05:40 +02:00
lv_group_t * g = lv_obj_get_group(ddlist);
if(lv_group_get_editing(g)) {
lv_group_set_editing(g, false);
}
}
2019-06-27 08:33:14 +02:00
#endif
/*Search the clicked option (For KEYPAD and ENCODER the new value should be already set)*/
2019-06-06 06:05:40 +02:00
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER || lv_indev_get_type(indev) == LV_INDEV_TYPE_BUTTON) {
2019-03-12 14:29:37 +01:00
lv_point_t p;
lv_indev_get_point(indev, &p);
p.y -= ext->label->coords.y1;
p.x -= ext->label->coords.x1;
2019-03-12 14:29:37 +01:00
uint16_t letter_i;
letter_i = lv_label_get_letter_on(ext->label, &p);
2019-04-04 07:15:40 +02:00
uint16_t new_opt = 0;
const char * txt = lv_label_get_text(ext->label);
uint32_t i = 0;
uint32_t i_prev = 0;
uint32_t letter_cnt = 0;
2019-03-12 14:29:37 +01:00
uint32_t letter;
for(letter_cnt = 0; letter_cnt < letter_i; letter_cnt++) {
2019-03-12 14:29:37 +01:00
letter = lv_txt_encoded_next(txt, &i);
2019-04-04 07:15:40 +02:00
/*Count he lines to reach the clicked letter. But ignore the last '\n' because it
* still belongs to the clicked line*/
if(letter == '\n' && i_prev != letter_i) new_opt++;
i_prev = i;
2019-03-12 14:29:37 +01:00
}
2019-06-06 06:05:40 +02:00
ext->sel_opt_id = new_opt;
ext->sel_opt_id_ori = ext->sel_opt_id;
}
2019-06-27 07:16:15 +02:00
uint32_t id = ext->sel_opt_id; /*Just to use uint32_t in event data*/
2019-06-17 16:05:30 +02:00
lv_res_t res = lv_event_send(ddlist, LV_EVENT_VALUE_CHANGED, &id);
2019-03-07 00:42:08 +01:00
if(res != LV_RES_OK) return res;
if(ext->stay_open == 0) {
ext->opened = 0;
lv_obj_set_drag(lv_page_get_scrl(ddlist), false);
lv_ddlist_refr_size(ddlist, true);
} else {
lv_obj_invalidate(ddlist);
}
}
2018-11-08 22:39:08 +08:00
return LV_RES_OK;
}
/**
2017-10-05 11:29:21 +02:00
* Refresh the size of drop down list according to its status (open or closed)
* @param ddlist pointer to a drop down list object
2019-06-11 13:51:14 +02:00
* @param anim Change the size (open/close) with or without animation (true/false)
*/
2019-06-11 13:51:14 +02:00
static void lv_ddlist_refr_size(lv_obj_t * ddlist, lv_anim_enable_t anim)
{
#if LV_USE_ANIMATION == 0
anim = false;
#endif
2019-04-11 19:59:55 +08:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2017-11-23 21:28:36 +01:00
lv_coord_t new_height;
2019-04-22 10:17:21 +02:00
/*Open the list*/
if(ext->opened) {
if(ext->fix_height == 0) {
2020-01-06 22:14:04 +01:00
lv_style_int_t top = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_TOP);
lv_style_int_t bottom = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_BOTTOM);
new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + top + bottom;
2019-04-22 10:17:21 +02:00
} else {
2019-04-04 07:15:40 +02:00
new_height = ext->fix_height;
2019-04-22 10:17:21 +02:00
}
2019-04-22 10:17:21 +02:00
}
/*Close the list*/
else {
const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_BG, LV_STYLE_FONT);
2019-04-23 15:56:59 +02:00
lv_coord_t font_h = lv_font_get_line_height(font);
2020-01-06 22:14:04 +01:00
new_height = font_h + 2 * lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_LINE_SPACE);
lv_page_set_sb_mode(ddlist, LV_SB_MODE_HIDE);
}
2019-06-11 13:51:14 +02:00
if(anim == LV_ANIM_OFF) {
lv_obj_set_height(ddlist, new_height);
lv_ddlist_pos_current_option(ddlist);
if(ext->opened) lv_page_set_sb_mode(ddlist, LV_SB_MODE_UNHIDE);
#if LV_USE_ANIMATION
2019-06-12 23:10:54 +02:00
lv_anim_del(ddlist, (lv_anim_exec_xcb_t)lv_ddlist_adjust_height); /*If an animation is in progress then
2019-04-04 07:15:40 +02:00
it will overwrite this changes*/
2019-04-22 10:17:21 +02:00
/*Force animation complete to fix highlight selection*/
lv_ddlist_anim_finish(ddlist);
} else {
/*Run the animation only if the the size will be different*/
if(lv_obj_get_height(ddlist) != new_height) {
lv_anim_t a;
a.var = ddlist;
a.start = lv_obj_get_height(ddlist);
a.end = new_height;
2019-06-12 23:10:54 +02:00
a.exec_cb = (lv_anim_exec_xcb_t)lv_ddlist_adjust_height;
a.path_cb = lv_anim_path_linear;
a.ready_cb = lv_ddlist_anim_ready_cb;
a.act_time = 0;
2019-06-19 00:35:35 +02:00
a.time = lv_ddlist_get_anim_time(ddlist);
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
ext->force_sel = 1; /*Keep the list item selected*/
lv_anim_create(&a);
}
2017-11-27 17:48:54 +01:00
#endif
}
}
#if LV_USE_ANIMATION
2019-03-23 09:20:41 -04:00
/**
* Position the list and remove the selection highlight if it's closed.
* Called at end of list animation.
2019-04-22 10:17:21 +02:00
* @param a pointer to the animation
*/
static void lv_ddlist_anim_ready_cb(lv_anim_t * a)
{
lv_obj_t * ddlist = a->var;
lv_ddlist_anim_finish(ddlist);
}
/**
* Clean up after the open animation
* @param ddlist
2019-03-23 09:20:41 -04:00
*/
2019-06-06 06:05:40 +02:00
static void lv_ddlist_anim_finish(lv_obj_t * ddlist)
2019-04-04 07:15:40 +02:00
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-03-23 09:20:41 -04:00
2019-04-04 07:15:40 +02:00
lv_ddlist_pos_current_option(ddlist);
ext->force_sel = 0; /*Turn off drawing of selection*/
if(ext->opened) lv_page_set_sb_mode(ddlist, LV_SB_MODE_UNHIDE);
2019-03-23 09:20:41 -04:00
}
/**
* Adjusts the ddlist's height and then positions the option within it's new height.
* This keeps the option visible during animation.
* @param ddlist Drop down list object
* @param height New drop down list height
*/
static void lv_ddlist_adjust_height(lv_obj_t * ddlist, lv_anim_value_t height)
2019-04-04 07:15:40 +02:00
{
lv_obj_set_height(ddlist, height);
lv_ddlist_pos_current_option(ddlist);
2019-03-23 09:20:41 -04:00
}
#endif
2019-03-23 09:20:41 -04:00
/**
* Set the position of list when it is closed to show the selected item
* @param ddlist pointer to a drop down list
*/
static void lv_ddlist_pos_current_option(lv_obj_t * ddlist)
{
2019-04-11 19:59:55 +08:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_BG, LV_STYLE_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_obj_t * scrl = lv_page_get_scrl(ddlist);
2017-10-05 11:29:21 +02:00
2019-06-06 06:05:40 +02:00
lv_coord_t h = lv_obj_get_height(ddlist);
2020-01-06 22:14:04 +01:00
lv_style_int_t line_space = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_BG, LV_STYLE_LINE_SPACE);
2019-06-06 06:05:40 +02:00
lv_coord_t line_y1 =
ext->sel_opt_id * (font_h + line_space) + ext->label->coords.y1 - scrl->coords.y1;
2019-04-04 07:15:40 +02:00
lv_obj_set_y(scrl, -line_y1 + (h - font_h) / 2);
lv_obj_invalidate(ddlist);
}
2019-04-20 06:37:06 +02:00
/**
* Be sure the width of the scrollable exactly fits the ddlist
* @param ddlist pointer to a ddlist
*/
2019-06-06 06:05:40 +02:00
static void lv_ddlist_refr_width(lv_obj_t * ddlist)
2019-04-20 06:37:06 +02:00
{
/*Save the current x coordinate because it should be kept after the refrsh*/
lv_coord_t x;
if(lv_obj_get_base_dir(ddlist) == LV_BIDI_DIR_RTL) x = lv_obj_get_x(ddlist) + lv_obj_get_width(ddlist);
else x = lv_obj_get_x(ddlist);
2019-10-30 10:34:39 +01:00
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
2019-04-20 06:37:06 +02:00
/*Set the TIGHT fit horizontally the set the width to the content*/
2019-04-22 10:17:21 +02:00
lv_page_set_scrl_fit2(ddlist, LV_FIT_TIGHT, lv_page_get_scrl_fit_bottom(ddlist));
2019-04-20 06:37:06 +02:00
/*Revert FILL fit to fill the parent with the options area. It allows to RIGHT/CENTER align the text*/
2019-04-22 10:17:21 +02:00
lv_page_set_scrl_fit2(ddlist, LV_FIT_FILL, lv_page_get_scrl_fit_bottom(ddlist));
if(lv_obj_get_base_dir(ddlist) == LV_BIDI_DIR_RTL) lv_obj_set_x(ddlist, x - lv_obj_get_width(ddlist));
else lv_obj_set_x(ddlist, x);
2019-10-30 10:34:39 +01:00
switch(lv_label_get_align(ext->label)) {
case LV_LABEL_ALIGN_LEFT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0); break;
case LV_LABEL_ALIGN_CENTER: lv_obj_align(ext->label, NULL, LV_ALIGN_CENTER, 0, 0); break;
case LV_LABEL_ALIGN_RIGHT: lv_obj_align(ext->label, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); break;
}
2019-04-20 06:37:06 +02:00
}
#endif