Lines Matching +full:- +full:- +full:include

9 #include "lv_dropdown_private.h"
10 #include "../../misc/lv_area_private.h"
11 #include "../../core/lv_obj_class_private.h"
12 #include "../../core/lv_obj.h"
15 #include "../../misc/lv_assert.h"
16 #include "../../draw/lv_draw_private.h"
17 #include "../../core/lv_group.h"
18 #include "../../indev/lv_indev.h"
19 #include "../../display/lv_display.h"
20 #include "../../font/lv_symbol_def.h"
21 #include "../../misc/lv_anim.h"
22 #include "../../misc/lv_math.h"
23 #include "../../misc/lv_text_ap.h"
24 #include "../../misc/lv_text_private.h"
25 #include "../../stdlib/lv_string.h"
145 .name = "dropdown-list",
172 if(dropdown->text == txt) return; in lv_dropdown_set_text()
174 dropdown->text = txt; in lv_dropdown_set_text()
186 /*Count the '\n'-s to determine the number of options*/ in lv_dropdown_set_options()
187 dropdown->option_cnt = 0; in lv_dropdown_set_options()
190 if(options[i] == '\n') dropdown->option_cnt++; in lv_dropdown_set_options()
192 dropdown->option_cnt++; /*Last option has no `\n`*/ in lv_dropdown_set_options()
193 dropdown->sel_opt_id = 0; in lv_dropdown_set_options()
194 dropdown->sel_opt_id_orig = 0; in lv_dropdown_set_options()
203 if(dropdown->options != NULL && dropdown->static_txt == 0) { in lv_dropdown_set_options()
204 lv_free(dropdown->options); in lv_dropdown_set_options()
205 dropdown->options = NULL; in lv_dropdown_set_options()
208 dropdown->options = lv_malloc(len); in lv_dropdown_set_options()
210 LV_ASSERT_MALLOC(dropdown->options); in lv_dropdown_set_options()
211 if(dropdown->options == NULL) return; in lv_dropdown_set_options()
214 lv_strcpy(dropdown->options, options); in lv_dropdown_set_options()
216 lv_text_ap_proc(options, dropdown->options); in lv_dropdown_set_options()
220 dropdown->static_txt = 0; in lv_dropdown_set_options()
223 if(dropdown->list) lv_obj_invalidate(dropdown->list); in lv_dropdown_set_options()
233 /*Count the '\n'-s to determine the number of options*/ in lv_dropdown_set_options_static()
234 dropdown->option_cnt = 0; in lv_dropdown_set_options_static()
237 if(options[i] == '\n') dropdown->option_cnt++; in lv_dropdown_set_options_static()
239 dropdown->option_cnt++; /*Last option has no `\n`*/ in lv_dropdown_set_options_static()
240 dropdown->sel_opt_id = 0; in lv_dropdown_set_options_static()
241 dropdown->sel_opt_id_orig = 0; in lv_dropdown_set_options_static()
243 if(dropdown->static_txt == 0 && dropdown->options != NULL) { in lv_dropdown_set_options_static()
244 lv_free(dropdown->options); in lv_dropdown_set_options_static()
245 dropdown->options = NULL; in lv_dropdown_set_options_static()
248 dropdown->static_txt = 1; in lv_dropdown_set_options_static()
249 dropdown->options = (char *)options; in lv_dropdown_set_options_static()
252 if(dropdown->list) lv_obj_invalidate(dropdown->list); in lv_dropdown_set_options_static()
263 if(dropdown->static_txt != 0) { in lv_dropdown_add_option()
264 char * static_options = dropdown->options; in lv_dropdown_add_option()
265 dropdown->options = lv_strdup(static_options); in lv_dropdown_add_option()
266 LV_ASSERT_MALLOC(dropdown->options); in lv_dropdown_add_option()
267 if(dropdown->options == NULL) return; in lv_dropdown_add_option()
268 dropdown->static_txt = 0; in lv_dropdown_add_option()
272 size_t old_len = (dropdown->options == NULL) ? 0 : lv_strlen(dropdown->options); in lv_dropdown_add_option()
280 dropdown->options = lv_realloc(dropdown->options, new_len + 1); in lv_dropdown_add_option()
281 LV_ASSERT_MALLOC(dropdown->options); in lv_dropdown_add_option()
282 if(dropdown->options == NULL) return; in lv_dropdown_add_option()
284 dropdown->options[old_len] = '\0'; in lv_dropdown_add_option()
290 for(insert_pos = 0; dropdown->options[insert_pos] != 0; insert_pos++) { in lv_dropdown_add_option()
293 if(dropdown->options[insert_pos] == '\n') in lv_dropdown_add_option()
299 if((insert_pos > 0) && (pos >= dropdown->option_cnt)) in lv_dropdown_add_option()
300 …lv_text_ins(dropdown->options, lv_text_encoded_get_char_id(dropdown->options, insert_pos++), "\n"); in lv_dropdown_add_option()
311 if(pos < dropdown->option_cnt) lv_strcat(ins_buf, "\n"); in lv_dropdown_add_option()
313 …lv_text_ins(dropdown->options, lv_text_encoded_get_char_id(dropdown->options, insert_pos), ins_buf… in lv_dropdown_add_option()
316 dropdown->option_cnt++; in lv_dropdown_add_option()
319 if(dropdown->list) lv_obj_invalidate(dropdown->list); in lv_dropdown_add_option()
326 if(dropdown->options == NULL) return; in lv_dropdown_clear_options()
328 if(dropdown->static_txt == 0) in lv_dropdown_clear_options()
329 lv_free(dropdown->options); in lv_dropdown_clear_options()
331 dropdown->options = NULL; in lv_dropdown_clear_options()
332 dropdown->static_txt = 0; in lv_dropdown_clear_options()
333 dropdown->option_cnt = 0; in lv_dropdown_clear_options()
336 if(dropdown->list) lv_obj_invalidate(dropdown->list); in lv_dropdown_clear_options()
344 if(dropdown->sel_opt_id == sel_opt) return; in lv_dropdown_set_selected()
346 dropdown->sel_opt_id = sel_opt < dropdown->option_cnt ? sel_opt : dropdown->option_cnt - 1; in lv_dropdown_set_selected()
347 dropdown->sel_opt_id_orig = dropdown->sel_opt_id; in lv_dropdown_set_selected()
349 if(dropdown->list) { in lv_dropdown_set_selected()
361 if(dropdown->dir == dir) return; in lv_dropdown_set_dir()
363 dropdown->dir = dir; in lv_dropdown_set_dir()
373 dropdown->symbol = symbol; in lv_dropdown_set_symbol()
382 dropdown->selected_highlight = en; in lv_dropdown_set_selected_highlight()
383 if(dropdown->list) lv_obj_invalidate(dropdown->list); in lv_dropdown_set_selected_highlight()
395 return dropdown->list; in lv_dropdown_get_list()
403 return dropdown->text; in lv_dropdown_get_text()
411 return dropdown->options == NULL ? "" : dropdown->options; in lv_dropdown_get_options()
420 return dropdown->sel_opt_id; in lv_dropdown_get_selected()
429 return dropdown->option_cnt; in lv_dropdown_get_option_count()
442 if(dropdown->options) { in lv_dropdown_get_selected_str()
443 txt_len = lv_strlen(dropdown->options); in lv_dropdown_get_selected_str()
450 for(i = 0; i < txt_len && line != dropdown->sel_opt_id_orig; i++) { in lv_dropdown_get_selected_str()
451 if(dropdown->options[i] == '\n') line++; in lv_dropdown_get_selected_str()
455 for(c = 0; i < txt_len && dropdown->options[i] != '\n'; c++, i++) { in lv_dropdown_get_selected_str()
456 if(buf_size && c >= buf_size - 1) { in lv_dropdown_get_selected_str()
460 buf[c] = dropdown->options[i]; in lv_dropdown_get_selected_str()
487 return -1; in lv_dropdown_get_option_index()
494 return dropdown->symbol; in lv_dropdown_get_symbol()
501 return dropdown->selected_highlight; in lv_dropdown_get_selected_highlight()
508 return dropdown->dir; in lv_dropdown_get_dir()
522 lv_obj_set_parent(dropdown->list, lv_obj_get_screen(dropdown_obj)); in lv_dropdown_open()
523 lv_obj_move_to_index(dropdown->list, -1); in lv_dropdown_open()
524 lv_obj_remove_flag(dropdown->list, LV_OBJ_FLAG_HIDDEN); in lv_dropdown_open()
530 lv_label_set_text_static(label, dropdown->options); in lv_dropdown_open()
531 lv_obj_set_width(dropdown->list, LV_SIZE_CONTENT); in lv_dropdown_open()
535 if(lv_obj_get_width(dropdown->list) <= lv_obj_get_width(dropdown_obj) && in lv_dropdown_open()
536 (dropdown->dir == LV_DIR_TOP || dropdown->dir == LV_DIR_BOTTOM)) { in lv_dropdown_open()
537 lv_obj_set_width(dropdown->list, lv_obj_get_width(dropdown_obj)); in lv_dropdown_open()
541 int32_t border_width = lv_obj_get_style_border_width(dropdown->list, LV_PART_MAIN); in lv_dropdown_open()
542 int32_t top = lv_obj_get_style_pad_top(dropdown->list, LV_PART_MAIN) + border_width; in lv_dropdown_open()
543 int32_t bottom = lv_obj_get_style_pad_bottom(dropdown->list, LV_PART_MAIN) + border_width; in lv_dropdown_open()
548 lv_dir_t dir = dropdown->dir; in lv_dropdown_open()
550 if(dropdown->dir == LV_DIR_BOTTOM) { in lv_dropdown_open()
551 if(dropdown_obj->coords.y2 + list_h > LV_VER_RES) { in lv_dropdown_open()
552 if(dropdown_obj->coords.y1 > LV_VER_RES - dropdown_obj->coords.y2) { in lv_dropdown_open()
555 list_h = dropdown_obj->coords.y1 - 1; in lv_dropdown_open()
558 list_h = LV_VER_RES - dropdown_obj->coords.y2 - 1 ; in lv_dropdown_open()
563 else if(dropdown->dir == LV_DIR_TOP) { in lv_dropdown_open()
564 if(dropdown_obj->coords.y1 - list_h < 0) { in lv_dropdown_open()
565 if(dropdown_obj->coords.y1 < LV_VER_RES - dropdown_obj->coords.y2) { in lv_dropdown_open()
568 list_h = LV_VER_RES - dropdown_obj->coords.y2; in lv_dropdown_open()
571 list_h = dropdown_obj->coords.y1; in lv_dropdown_open()
577 lv_obj_set_height(dropdown->list, list_h); in lv_dropdown_open()
581 …if(dir == LV_DIR_BOTTOM) lv_obj_align_to(dropdown->list, dropdown_obj, LV_ALIGN_OUT_BOTTOM_LEF… in lv_dropdown_open()
582 …else if(dir == LV_DIR_TOP) lv_obj_align_to(dropdown->list, dropdown_obj, LV_ALIGN_OUT_TOP_LEFT, … in lv_dropdown_open()
583 …else if(dir == LV_DIR_LEFT) lv_obj_align_to(dropdown->list, dropdown_obj, LV_ALIGN_OUT_LEFT_TOP, … in lv_dropdown_open()
584 …else if(dir == LV_DIR_RIGHT) lv_obj_align_to(dropdown->list, dropdown_obj, LV_ALIGN_OUT_RIGHT_TOP,… in lv_dropdown_open()
586 lv_obj_update_layout(dropdown->list); in lv_dropdown_open()
588 if(dropdown->dir == LV_DIR_LEFT || dropdown->dir == LV_DIR_RIGHT) { in lv_dropdown_open()
589 int32_t y1 = lv_obj_get_y(dropdown->list); in lv_dropdown_open()
590 int32_t y2 = lv_obj_get_y2(dropdown->list); in lv_dropdown_open()
592 lv_obj_set_y(dropdown->list, y1 - (y2 - LV_VER_RES) - 1); in lv_dropdown_open()
596 … lv_text_align_t align = lv_obj_calculate_style_text_align(label, LV_PART_MAIN, dropdown->options); in lv_dropdown_open()
620 dropdown->pr_opt_id = LV_DROPDOWN_PR_NONE; in lv_dropdown_close()
621 lv_obj_add_flag(dropdown->list, LV_OBJ_FLAG_HIDDEN); in lv_dropdown_close()
631 return lv_obj_has_flag(dropdown->list, LV_OBJ_FLAG_HIDDEN) ? false : true; in lv_dropdown_is_open()
654 dropdown->list = NULL; in lv_dropdown_constructor()
655 dropdown->options = NULL; in lv_dropdown_constructor()
656 dropdown->symbol = LV_SYMBOL_DOWN; in lv_dropdown_constructor()
657 dropdown->text = NULL; in lv_dropdown_constructor()
658 dropdown->static_txt = 1; in lv_dropdown_constructor()
659 dropdown->selected_highlight = 1; in lv_dropdown_constructor()
660 dropdown->sel_opt_id = 0; in lv_dropdown_constructor()
661 dropdown->sel_opt_id_orig = 0; in lv_dropdown_constructor()
662 dropdown->pr_opt_id = LV_DROPDOWN_PR_NONE; in lv_dropdown_constructor()
663 dropdown->option_cnt = 0; in lv_dropdown_constructor()
664 dropdown->dir = LV_DIR_BOTTOM; in lv_dropdown_constructor()
671 dropdown->list = lv_dropdown_list_create(lv_obj_get_screen(obj)); in lv_dropdown_constructor()
672 lv_dropdown_list_t * list = (lv_dropdown_list_t *)dropdown->list; in lv_dropdown_constructor()
673 list->dropdown = obj; in lv_dropdown_constructor()
683 if(dropdown->list) { in lv_dropdown_destructor()
684 lv_obj_delete(dropdown->list); in lv_dropdown_destructor()
685 dropdown->list = NULL; in lv_dropdown_destructor()
688 if(!dropdown->static_txt) { in lv_dropdown_destructor()
689 lv_free(dropdown->options); in lv_dropdown_destructor()
690 dropdown->options = NULL; in lv_dropdown_destructor()
713 lv_obj_t * dropdown_obj = list->dropdown; in lv_dropdownlist_destructor()
715 dropdown->list = NULL; in lv_dropdownlist_destructor()
745 dropdown->sel_opt_id = dropdown->sel_opt_id_orig; in lv_dropdown_event()
766 p->y = lv_font_get_line_height(font); in lv_dropdown_event()
774 else if(dropdown->sel_opt_id + 1 < dropdown->option_cnt) { in lv_dropdown_event()
775 dropdown->sel_opt_id++; in lv_dropdown_event()
784 else if(dropdown->sel_opt_id > 0) { in lv_dropdown_event()
785 dropdown->sel_opt_id--; in lv_dropdown_event()
790 dropdown->sel_opt_id = dropdown->sel_opt_id_orig; in lv_dropdown_event()
809 int32_t new_id = dropdown->sel_opt_id + r; in lv_dropdown_event()
810 new_id = LV_CLAMP(0, new_id, (int32_t)dropdown->option_cnt - 1); in lv_dropdown_event()
812 dropdown->sel_opt_id = new_id; in lv_dropdown_event()
834 lv_obj_t * dropdown_obj = ((lv_dropdown_list_t *)list)->dropdown; in lv_dropdown_list_event()
846 dropdown->pr_opt_id = LV_DROPDOWN_PR_NONE; in lv_dropdown_list_event()
874 if(dropdown->text) opt_txt = dropdown->text; in draw_main()
881 if(dropdown->dir == LV_DIR_LEFT) symbol_to_left = true; in draw_main()
884 if(dropdown->symbol) { in draw_main()
885 lv_image_src_t symbol_type = lv_image_src_get_type(dropdown->symbol); in draw_main()
890 …lv_text_get_size(&size, dropdown->symbol, symbol_dsc.font, symbol_dsc.letter_space, symbol_dsc.lin… in draw_main()
897 lv_result_t res = lv_image_decoder_get_info(dropdown->symbol, &header); in draw_main()
903 symbol_w = -1; in draw_main()
904 symbol_h = -1; in draw_main()
909 symbol_area.y1 = obj->coords.y1; in draw_main()
910 symbol_area.y2 = symbol_area.y1 + symbol_h - 1; in draw_main()
911 symbol_area.x1 = obj->coords.x1; in draw_main()
912 symbol_area.x2 = symbol_area.x1 + symbol_w - 1; in draw_main()
914 lv_area_align(&obj->coords, &symbol_area, LV_ALIGN_LEFT_MID, left, 0); in draw_main()
917 lv_area_align(&obj->coords, &symbol_area, LV_ALIGN_RIGHT_MID, -right, 0); in draw_main()
921 symbol_dsc.text = dropdown->symbol; in draw_main()
931 img_dsc.src = dropdown->symbol; in draw_main()
946 txt_area.x1 = obj->coords.x1; in draw_main()
947 txt_area.x2 = txt_area.x1 + size.x - 1; in draw_main()
948 txt_area.y1 = obj->coords.y1; in draw_main()
949 txt_area.y2 = txt_area.y1 + size.y - 1; in draw_main()
951 if(dropdown->symbol == NULL) { in draw_main()
952 lv_area_align(&obj->coords, &txt_area, LV_ALIGN_CENTER, 0, 0); in draw_main()
957 lv_area_align(&obj->coords, &txt_area, LV_ALIGN_RIGHT_MID, -right, 0); in draw_main()
960 lv_area_align(&obj->coords, &txt_area, LV_ALIGN_LEFT_MID, left, 0); in draw_main()
965 if(dropdown->text == NULL) { in draw_main()
976 lv_obj_t * dropdown_obj = list->dropdown; in draw_list()
984 has_common = lv_area_intersect(&clip_area_core, &layer->_clip_area, &dropdown->list->coords); in draw_list()
986 const lv_area_t clip_area_ori = layer->_clip_area; in draw_list()
987 layer->_clip_area = clip_area_core; in draw_list()
988 if(dropdown->selected_highlight) { in draw_list()
989 if(dropdown->pr_opt_id == dropdown->sel_opt_id) { in draw_list()
990 … draw_box(dropdown_obj, layer, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED); in draw_list()
991 … draw_box_label(dropdown_obj, layer, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED); in draw_list()
994 draw_box(dropdown_obj, layer, dropdown->pr_opt_id, LV_STATE_PRESSED); in draw_list()
995 draw_box_label(dropdown_obj, layer, dropdown->pr_opt_id, LV_STATE_PRESSED); in draw_list()
996 draw_box(dropdown_obj, layer, dropdown->sel_opt_id, LV_STATE_CHECKED); in draw_list()
997 draw_box_label(dropdown_obj, layer, dropdown->sel_opt_id, LV_STATE_CHECKED); in draw_list()
1001 draw_box(dropdown_obj, layer, dropdown->pr_opt_id, LV_STATE_PRESSED); in draw_list()
1002 draw_box_label(dropdown_obj, layer, dropdown->pr_opt_id, LV_STATE_PRESSED); in draw_list()
1004 layer->_clip_area = clip_area_ori; in draw_list()
1013 lv_obj_t * list_obj = dropdown->list; in draw_box()
1014 lv_state_t state_ori = list_obj->state; in draw_box()
1016 if(state != list_obj->state) { in draw_box()
1017 list_obj->state = state; in draw_box()
1018 list_obj->skip_trans = 1; in draw_box()
1029 rect_area.y1 = label->coords.y1; in draw_box()
1031 rect_area.y1 -= line_space / 2; in draw_box()
1033 rect_area.y2 = rect_area.y1 + font_h + line_space - 1; in draw_box()
1034 rect_area.x1 = dropdown->list->coords.x1; in draw_box()
1035 rect_area.x2 = dropdown->list->coords.x2; in draw_box()
1043 list_obj->state = state_ori; in draw_box()
1044 list_obj->skip_trans = 0; in draw_box()
1052 lv_obj_t * list_obj = dropdown->list; in draw_box_label()
1053 lv_state_t state_orig = list_obj->state; in draw_box_label()
1055 if(state != list_obj->state) { in draw_box_label()
1056 list_obj->state = state; in draw_box_label()
1057 list_obj->skip_trans = 1; in draw_box_label()
1074 area_sel.y1 = label->coords.y1; in draw_box_label()
1076 area_sel.y1 -= label_dsc.line_space / 2; in draw_box_label()
1078 area_sel.y2 = area_sel.y1 + font_h + label_dsc.line_space - 1; in draw_box_label()
1079 area_sel.x1 = list_obj->coords.x1; in draw_box_label()
1080 area_sel.x2 = list_obj->coords.x2; in draw_box_label()
1083 area_ok = lv_area_intersect(&mask_sel, &layer->_clip_area, &area_sel); in draw_box_label()
1085 const lv_area_t clip_area_ori = layer->_clip_area; in draw_box_label()
1086 layer->_clip_area = mask_sel; in draw_box_label()
1088 lv_draw_label(layer, &label_dsc, &label->coords); in draw_box_label()
1089 layer->_clip_area = clip_area_ori; in draw_box_label()
1091 list_obj->state = state_orig; in draw_box_label()
1092 list_obj->skip_trans = 0; in draw_box_label()
1102 if(dropdown->sel_opt_id_orig != dropdown->sel_opt_id) { in btn_release_handler()
1103 dropdown->sel_opt_id_orig = dropdown->sel_opt_id; in btn_release_handler()
1105 uint32_t id = dropdown->sel_opt_id; /*Just to use uint32_t in event data*/ in btn_release_handler()
1120 dropdown->sel_opt_id = dropdown->sel_opt_id_orig; in btn_release_handler()
1134 lv_obj_t * dropdown_obj = list->dropdown; in list_release_handler()
1140 dropdown->sel_opt_id_orig = dropdown->sel_opt_id; in list_release_handler()
1151 dropdown->sel_opt_id = get_id_on_point(dropdown_obj, p.y); in list_release_handler()
1152 dropdown->sel_opt_id_orig = dropdown->sel_opt_id; in list_release_handler()
1158 if(dropdown->text == NULL) lv_obj_invalidate(dropdown_obj); in list_release_handler()
1160 uint32_t id = dropdown->sel_opt_id; /*Just to use uint32_t in event data*/ in list_release_handler()
1170 lv_obj_t * dropdown_obj = list->dropdown; in list_press_handler()
1177 dropdown->pr_opt_id = get_id_on_point(dropdown_obj, p.y); in list_press_handler()
1187 y -= label->coords.y1; in get_id_on_point()
1198 if(opt >= dropdown->option_cnt) opt = dropdown->option_cnt - 1; in get_id_on_point()
1219 int32_t line_y1 = dropdown->sel_opt_id * unit_h; in position_to_selected()
1222 lv_obj_scroll_to_y(dropdown->list, line_y1, anim_en); in position_to_selected()
1223 lv_obj_invalidate(dropdown->list); in position_to_selected()
1229 if(dropdown->list == NULL) return NULL; in get_label()
1231 return lv_obj_get_child(dropdown->list, 0); in get_label()