/** * Refresh the position of the roller. It uses the id stored in: ext->ddlist.selected_option_id * @param roller pointer to a roller object * @param anim_en true: refresh with animation; false: without animation */ static void refr_position(lv_obj_t *roller, bool anim_en) { lv_obj_t *roller_scrl = lv_page_get_scrl(roller); lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); const lv_font_t * font = style_label->text.font; lv_coord_t font_h = lv_font_get_height_scale(font); lv_coord_t h = lv_obj_get_height(roller); int32_t id = ext->ddlist.sel_opt_id; lv_coord_t line_y1 = id * (font_h + style_label->text.line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1; lv_coord_t new_y = - line_y1 + (h - font_h) / 2; if(ext->ddlist.anim_time == 0 || anim_en == false) { lv_obj_set_y(roller_scrl, new_y); } else { #if USE_LV_ANIMATION lv_anim_t a; a.var = roller_scrl; a.start = lv_obj_get_y(roller_scrl); a.end = new_y; a.fp = (lv_anim_fp_t)lv_obj_set_y; a.path = lv_anim_path_linear; a.end_cb = NULL; a.act_time = 0; a.time = ext->ddlist.anim_time; a.playback = 0; a.playback_pause = 0; a.repeat = 0; a.repeat_pause = 0; lv_anim_create(&a); #endif } }
/** * Focus on an object. It ensures that the object will be visible on the page. * @param page pointer to a page object * @param obj pointer to an object to focus (must be on the page) * @param anim_time scroll animation time in milliseconds (0: no animation) */ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time) { lv_page_ext_t * ext = lv_obj_get_ext_attr(page); lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG); lv_style_t * style_scrl = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); lv_coord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1; lv_coord_t obj_h = lv_obj_get_height(obj); lv_coord_t scrlable_y = lv_obj_get_y(ext->scrl); lv_coord_t page_h = lv_obj_get_height(page); lv_coord_t top_err = -(scrlable_y + obj_y); lv_coord_t bot_err = scrlable_y + obj_y + obj_h - page_h; /*If obj is higher then the page focus where the "error" is smaller*/ /*Out of the page on the top*/ if((obj_h <= page_h && top_err > 0) || (obj_h > page_h && top_err < bot_err)) { /*Calculate a new position and let some space above*/ scrlable_y = -(obj_y - style_scrl->body.padding.ver - style->body.padding.ver); scrlable_y += style_scrl->body.padding.ver; } /*Out of the page on the bottom*/ else if((obj_h <= page_h && bot_err > 0) || (obj_h > page_h && top_err >= bot_err)) { /*Calculate a new position and let some space below*/ scrlable_y = -obj_y; scrlable_y += page_h - obj_h; scrlable_y -= style_scrl->body.padding.ver; } else { /*Already in focus*/ return; } if(anim_time == 0) { lv_obj_set_y(ext->scrl, scrlable_y); } else { #if USE_LV_ANIMATION lv_anim_t a; a.act_time = 0; a.start = lv_obj_get_y(ext->scrl); a.end = scrlable_y; a.time = anim_time; a.end_cb = NULL; a.playback = 0; a.repeat = 0; a.var = ext->scrl; a.path = lv_anim_path_linear; a.fp = (lv_anim_fp_t) lv_obj_set_y; lv_anim_create(&a); #endif } }
/** * 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) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_style_t * style = lv_obj_get_style(ddlist); const lv_font_t * font = style->text.font; lv_coord_t font_h = lv_font_get_height(font); lv_style_t * label_style = lv_obj_get_style(ext->label); lv_obj_t * scrl = lv_page_get_scrl(ddlist); lv_coord_t h = lv_obj_get_height(ddlist); lv_coord_t line_y1 = ext->sel_opt_id * (font_h + label_style->text.line_space) + ext->label->coords.y1 - scrl->coords.y1; lv_obj_set_y(scrl, - line_y1 + (h - font_h) / 2); }
/** * Load the file list from the current path on the window * @param app pointer to a Files application */ static void win_load_file_list(lv_app_inst_t * app) { my_app_data_t * app_data = app->app_data; my_win_data_t * win_data = app->win_data; /*Create a new list*/ win_create_list(app); fs_res_t res = FS_RES_OK; /*At empty path show the drivers */ lv_obj_t * liste; if(app_data->path[0] == '\0') { char drv[16]; char buf[2]; fs_get_letters(drv); uint8_t i; for(i = 0; drv[i] != '\0'; i++) { buf[0] = drv[i]; buf[1] = '\0'; liste = lv_list_add(win_data->file_list, SYMBOL_DRIVE, buf, win_drv_action); lv_obj_set_free_p(liste, app); } } /*List the files/folders with fs interface*/ else { liste = lv_list_add(win_data->file_list, SYMBOL_UP, "Up", win_up_action); lv_obj_set_free_p(liste, app); fs_readdir_t rd; res = fs_readdir_init(&rd, app_data->path); if(res != FS_RES_OK) { lv_app_notice_add("Can not read the\npath in Files"); return; } /*At not first page add prev. page button */ if(app_data->file_cnt != 0) { liste = lv_list_add(win_data->file_list, SYMBOL_LEFT, "Previous page", win_prev_action); lv_obj_set_free_p(liste, app); } char fn[LV_APP_FILES_FN_MAX_LEN]; /*Read the files from the previous pages*/ uint16_t file_cnt = 0; while(file_cnt <= app_data->file_cnt) { res = fs_readdir(&rd, fn); if(res != FS_RES_OK ){ lv_app_notice_add("Can not read\nthe path in Files"); return; } file_cnt ++; } /*Add list elements from the files and folders*/ while(res == FS_RES_OK && fn[0] != '\0') { if(fn[0] == '/') { /*Add a folder*/ lv_obj_t * liste; liste = lv_list_add(win_data->file_list, SYMBOL_FOLDER, &fn[1], win_folder_action); lv_obj_set_free_p(liste, app); app_data->file_cnt ++; } /*Add a file*/ else { liste = lv_list_add(win_data->file_list, SYMBOL_FILE, fn, win_file_action); lv_obj_set_free_p(liste, app); app_data->file_cnt ++; } /*Get the next element*/ res = fs_readdir(&rd, fn); /*Show only LV_APP_FSEL_MAX_FILE elements and add a Next page button*/ if(app_data->file_cnt != 0 && app_data->file_cnt % LV_APP_FILES_PAGE_SIZE == 0) { liste = lv_list_add(win_data->file_list, SYMBOL_RIGHT, "Next page", win_next_action); lv_obj_set_free_p(liste, app); break; } } /*Close the read directory*/ fs_readdir_close(&rd); } if(res != FS_RES_OK) { lv_app_notice_add("Can not read\nthe path in Files"); } /*Focus to the top of the list*/ lv_obj_set_y(lv_page_get_scrl(win_data->file_list), 0); return; }