diff --git a/lv_app/lv_app.c b/lv_app/lv_app.c index d4c5e5485..695afa907 100644 --- a/lv_app/lv_app.c +++ b/lv_app/lv_app.c @@ -30,9 +30,10 @@ static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi); static lv_action_res_t lv_app_sc_pr_action(lv_obj_t * sc, lv_dispi_t * dispi); static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t * dispi); static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_btn, lv_dispi_t * dispi); - +#if LV_APP_ANIM_LEVEL == 2 && LV_APP_ANIM_WIN != 0 static void lv_app_win_close_anim_cb(lv_obj_t * app_win); static void lv_app_win_minim_anim_cb(lv_obj_t * app_win); +#endif static void lv_app_init_icons(void); static void lv_app_init_style(void); @@ -216,7 +217,11 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app) /*Restore position of the scrollable part of the page*/ lv_obj_set_y(lv_page_get_scrable(sc_page), scrl_y); +#if LV_APP_ANIM_LEVEL != 0 lv_page_focus(sc_page, app->sc, true); +#else + lv_page_focus(sc_page, app->sc, false); +#endif return app->sc; } @@ -252,6 +257,9 @@ lv_obj_t * lv_app_win_open(lv_app_inst_t * app) app->win = lv_win_create(lv_scr_act(), NULL); lv_obj_set_free_p(app->win, app); lv_obj_set_style(app->win, &app_style.win_style); + lv_obj_t * win_content = lv_page_get_scrable(lv_win_get_content(app->win)); + lv_rect_set_fit(win_content, false, true); + lv_obj_set_width(win_content, LV_HOR_RES - 2 * app_style.win_style.content.bg_rects.hpad); lv_win_add_ctrl_btn(app->win, "U:/icon_down", lv_app_win_minim_action); lv_win_add_ctrl_btn(app->win, "U:/icon_close", lv_app_win_close_action); @@ -267,14 +275,12 @@ void lv_app_win_close(lv_app_inst_t * app) { if(app->win == NULL) return; - - lv_app_kb_close(); + lv_app_kb_close(false); lv_obj_del(app->win); app->win = NULL; dm_free(app->win_data); app->win_data = NULL; - } @@ -310,8 +316,6 @@ lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj) while(par != app_scr); return win; - - } const lv_app_dsc_t * lv_app_get_dsc(const char * name) @@ -393,6 +397,10 @@ static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_d lv_app_inst_t * app = lv_app_run(dsc, ""); lv_app_sc_open(app); +#if LV_APP_ANIM_LEVEL == 2 && LV_APP_ANIM_SC != 0 + lv_obj_anim(app->sc, LV_ANIM_FADE | ANIM_IN, LV_APP_ANIM_SC, 0, NULL); +#endif + /*Close the app list*/ lv_obj_del(app_list); app_list = NULL; @@ -424,8 +432,11 @@ static lv_action_res_t lv_app_sc_page_pr_action(lv_obj_t * sc, lv_dispi_t * disp static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) { +#if LV_APP_ANIM_LEVEL != 0 lv_page_focus(sc_page, sc, true); - +#else + lv_page_focus(sc_page, sc, false); +#endif /*Close the list if opened*/ if(app_list != NULL) { lv_obj_del(app_list); @@ -438,19 +449,30 @@ static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) app->dsc->win_open(app, app->win); - /*Make an animation on window open*/ -#if LV_APP_ANIM_WIN_OPEN != 0 +/*Make an animation on window open*/ +#if LV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0 + +#if LV_APP_ANIM_LEVEL == 1 + lv_obj_anim(app->win, LV_ANIM_FLOAT_LEFT | ANIM_IN, LV_APP_ANIM_WIN, 0, NULL); +#else /*LV_APP_ANIM_LEVEL == 2*/ + area_t cords; + if(app->sc == NULL) { + cords.x1 = LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2; + cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2; + cords.x2 = cords.x1 + LV_APP_SC_WIDTH; + cords.y2 = cords.y1 + LV_APP_SC_HEIGHT; + } else { + lv_obj_get_cords(app->sc, &cords); + } + anim_t a; a.act_time = 0; - a.time = LV_APP_ANIM_WIN_OPEN; + a.time = LV_APP_ANIM_WIN; a.end_cb = NULL; a.playback = 0; a.repeat = 0; a.var = app->win; a.path = anim_get_path(ANIM_PATH_LIN); -#if LV_APP_ANIM_WIN_COMPLEX != 0 - area_t cords; - lv_obj_get_cords(app->sc, &cords); a.start = lv_obj_get_width(app->sc); a.end = LV_HOR_RES; @@ -471,13 +493,13 @@ static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) a.end = 0; a.fp = (anim_fp_t) lv_obj_set_y; anim_create(&a); -#endif /*LV_APP_ANIM_WIN_OPEN_COMPLEX*/ a.start = OPA_TRANSP; a.end = OPA_COVER; a.fp = (anim_fp_t) lv_obj_set_opar; anim_create(&a); -#endif /*LV_APP_ANIM_WIN_OPEN*/ +#endif /*LV_APP_ANIM_LEVEL == 2*/ +#endif /*LLV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0*/ } return LV_ACTION_RES_OK; @@ -501,14 +523,18 @@ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t lv_app_kb_close(); -#if LV_APP_ANIM_WIN_CLOSE != 0 - lv_obj_anim(app->win, LV_ANIM_FADE | ANIM_OUT, LV_APP_ANIM_WIN_CLOSE, 0, lv_app_win_close_anim_cb); +#if LV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0 + #if LV_APP_ANIM_LEVEL == 1 + lv_obj_anim(app->win, LV_ANIM_FLOAT_LEFT | ANIM_OUT, LV_APP_ANIM_WIN, 0, lv_app_win_close_anim_cb); lv_app_sc_close(app); -#else - lv_app_close(app); + #else /*LV_APP_ANIM_LEVEL == 2*/ + lv_obj_anim(app->win, LV_ANIM_FADE | ANIM_OUT, LV_APP_ANIM_WIN, 0, lv_app_win_close_anim_cb); + lv_app_sc_close(app); + #endif /*LV_APP_ANIM_LEVEL*/ +#else /*LV_APP_ANIM_WIN == 0 && LV_APP_ANIM_LEVEL != 0*/ + lv_app_close(app); return LV_ACTION_RES_INV; -#endif - +#endif /*LV_APP_ANIM_WIN*/ return LV_ACTION_RES_OK; } @@ -522,47 +548,58 @@ static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_btn, lv_dispi_t lv_app_kb_close(); /*Make an animation on window open*/ - #if LV_APP_ANIM_WIN_OPEN != 0 - anim_t a; - a.act_time = 0; - a.time = LV_APP_ANIM_WIN_OPEN; - a.end_cb = NULL; - a.playback = 0; - a.repeat = 0; - a.var = app->win; - a.path = anim_get_path(ANIM_PATH_LIN); - #if LV_APP_ANIM_WIN_COMPLEX != 0 - area_t cords; - lv_obj_get_cords(app->sc, &cords); +#if LV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0 + #if LV_APP_ANIM_LEVEL == 1 + lv_obj_anim(app->win, LV_ANIM_FLOAT_BOTTOM | ANIM_OUT, LV_APP_ANIM_WIN, 0, lv_app_win_minim_anim_cb); + #else /*LV_APP_ANIM_LEVEL == 2*/ + area_t cords; + if(app->sc == NULL) { + cords.x1 = LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2; + cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2; + cords.x2 = cords.x1 + LV_APP_SC_WIDTH; + cords.y2 = cords.y1 + LV_APP_SC_HEIGHT; + } else { + lv_obj_get_cords(app->sc, &cords); + } - a.end = lv_obj_get_width(app->sc); - a.start = LV_HOR_RES; - a.fp = (anim_fp_t) lv_obj_set_width; - anim_create(&a); + anim_t a; + a.act_time = 0; + a.time = LV_APP_ANIM_WIN; + a.end_cb = NULL; + a.playback = 0; + a.repeat = 0; + a.var = app->win; + a.path = anim_get_path(ANIM_PATH_LIN); - a.end = lv_obj_get_height(app->sc); - a.start = LV_VER_RES; - a.fp = (anim_fp_t) lv_obj_set_height; - anim_create(&a); - a.end = cords.x1; - a.start = 0; - a.fp = (anim_fp_t) lv_obj_set_x; - anim_create(&a); + a.end = lv_obj_get_width(app->sc); + a.start = LV_HOR_RES; + a.fp = (anim_fp_t) lv_obj_set_width; + anim_create(&a); - a.end = cords.y1; - a.start = 0; - a.fp = (anim_fp_t) lv_obj_set_y; - anim_create(&a); - #endif /*LV_APP_ANIM_WIN_COMPLEX*/ + a.end = lv_obj_get_height(app->sc); + a.start = LV_VER_RES; + a.fp = (anim_fp_t) lv_obj_set_height; + anim_create(&a); - a.end = OPA_TRANSP; - a.start = OPA_COVER; - a.fp = (anim_fp_t) lv_obj_set_opar; - a.end_cb = (void (*)(void *))lv_app_win_minim_anim_cb; - //a.time = 500; - anim_create(&a); -#else + a.end = cords.x1; + a.start = 0; + a.fp = (anim_fp_t) lv_obj_set_x; + anim_create(&a); + + a.end = cords.y1; + a.start = 0; + a.fp = (anim_fp_t) lv_obj_set_y; + anim_create(&a); + + a.end = OPA_TRANSP; + a.start = OPA_COVER; + a.fp = (anim_fp_t) lv_obj_set_opar; + a.end_cb = (void (*)(void *))lv_app_win_minim_anim_cb; + //a.time = 500; + anim_create(&a); + #endif /*LV_APP_ANIM_LEVEL*/ +#else /*LV_APP_ANIM_WIN == 0 || LV_APP_ANIM_LEVEL == 0*/ lv_app_win_close(app); return LV_ACTION_RES_INV; #endif @@ -715,8 +752,8 @@ static void lv_app_init_style(void) app_style.win_style.header.vpad = 5 * LV_STYLE_MULT; app_style.win_style.header.hpad = 5 * LV_STYLE_MULT; app_style.win_style.header.opad = 5 * LV_STYLE_MULT; - //app_style.win_style.content.scrable_rects.vpad = app_style.win_style.ctrl_btn_h + 30; - app_style.win_style.content.bg_rects.vpad = app_style.win_style.ctrl_btn_h + 2 * app_style.win_style.header.vpad; + app_style.win_style.content.bg_rects.vpad = app_style.win_style.ctrl_btn_h + + 2 * app_style.win_style.header.vpad; } diff --git a/lv_app/lv_app_spt.c b/lv_app/lv_app_spt.c deleted file mode 100644 index 6758eaac7..000000000 --- a/lv_app/lv_app_spt.c +++ /dev/null @@ -1,106 +0,0 @@ -/** - * @file lv_app_spt.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "lv_app_spt.h" -#include "../lv_objx/lv_btnm.h" -#include "../lv_objx/lv_ta.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i); - -/********************** - * STATIC VARIABLES - **********************/ -static lv_obj_t * kb_btnm; -static lv_obj_t * kb_win; -static lv_obj_t * kb_ta; -static const char * kb_map_lc[] = { -"\0021#", "\002q", "\002w", "\002e", "\002r", "\002t", "\002y", "\002u", "\002i", "\002o", "\002p", "\003Del", "\n", -"\002ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", "\003Enter", "\n", -"*", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ";", "\n", -"\002Free", "\002<", "\006 ", "\002>", "\002Free", "" -}; -static lv_btnms_t kb_btnms; -static bool kb_inited; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -void lv_app_kb_open(lv_obj_t * ta) -{ - if(kb_inited == false) { - lv_btnms_get(LV_BTNMS_DEF, &kb_btnms); - kb_btnms.rects.opad = 4 + LV_STYLE_MULT; - kb_btnms.rects.vpad = 3 + LV_STYLE_MULT; - kb_btnms.rects.hpad = 3 + LV_STYLE_MULT; - kb_inited = true; - } - - if(kb_btnm != NULL) { - lv_app_kb_close(); - } - - kb_ta = ta; - - kb_btnm = lv_btnm_create(lv_scr_act(), NULL); - lv_obj_set_size(kb_btnm, LV_HOR_RES, LV_VER_RES / 2); - lv_obj_align(kb_btnm, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - lv_obj_set_style(kb_btnm, &kb_btnms); - lv_btnm_set_map(kb_btnm, kb_map_lc); - lv_btnm_set_cb(kb_btnm, lv_app_kb_action); - - kb_win = lv_app_get_win_from_obj(kb_ta); - lv_obj_set_height(kb_win, LV_VER_RES / 2); - lv_obj_set_y(kb_win, 0); - - // lv_obj_set_height(kb_ta, LV_VER_RES / 2 - 50); - - lv_ta_add_text(kb_ta, "alma\n\nkorte\n\ncitrom\nbarack\nbanaaaan\n\n"); - lv_ta_set_cursor_pos(kb_ta, LV_TA_CUR_LAST); - - lv_page_focus(lv_win_get_content(kb_win), kb_ta, true); -} - -void lv_app_kb_close(void) -{ - if(kb_btnm == NULL) return; - - lv_obj_set_size(kb_win, LV_HOR_RES, LV_VER_RES); - kb_win = NULL; - - lv_obj_del(kb_btnm); - kb_btnm = NULL; - - kb_ta = NULL; -} - -static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i) -{ - lv_ta_add_text(kb_ta, kb_map_lc[i]); - lv_page_focus(lv_win_get_content(kb_win), kb_ta, true); - return LV_ACTION_RES_OK; -} - -/********************** - * STATIC FUNCTIONS - **********************/ diff --git a/lv_app/lv_app_sup.c b/lv_app/lv_app_sup.c new file mode 100644 index 000000000..4893a5268 --- /dev/null +++ b/lv_app/lv_app_sup.c @@ -0,0 +1,202 @@ +/** + * @file lv_app_sup.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include +#include "../lv_objx/lv_btnm.h" +#include "../lv_objx/lv_ta.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_obj_t * kb_btnm; +static lv_obj_t * kb_win; +static lv_obj_t * kb_ta; +static const char * kb_map_lc[] = { +"\0061#", "\004q", "\004w", "\004e", "\004r", "\004t", "\004y", "\004u", "\004i", "\004o", "\004p", "\010Del", "\n", +"\007ABC", "\004a", "\004s", "\004d", "\004f", "\004g", "\004h", "\004j", "\004k", "\004l", "\010Enter", "\n", +"*", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ";", "\n", +"\002Hide", "\002Left", "\006 ", "\002Right", "\002Ok", "" +}; + +static const char * kb_map_uc[] = { +"\0061#", "\004Q", "\004W", "\004E", "\004R", "\004T", "\004Y", "\004U", "\004I", "\004O", "\004P", "\010Del", "\n", +"\007abc", "\004A", "\004S", "\004D", "\004F", "\004G", "\004H", "\004J", "\004K", "\004L", "\010Enter", "\n", +"*", "/", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ";", "\n", +"\002Hide", "\002Left", "\006 ", "\002Right", "\002Ok", "" +}; + +static const char * kb_map_spec[] = { +"0", "1", "2", "3", "4", "5", "6", "4", "8", "9", "\002Del", "\n", +"\002abc", "+", "-", "=", "%", "!", "?", "#", "<", ">", "\002Enter", "\n", +"\\", "@", "$", "_", "(", ")", "{", "}", "[", "]", ":", "\"", "'", "\n", +"\002Hide", "\002Left", "\006 ", "\002Right", "\002Ok", "" +}; + +static const char * kb_map_num[] = { +"1", "2", "3", "\002Hide","\n", +"4", "5", "6", "\002Ok", "\n", +"7", "8", "9", "\002Del", "\n", +"+/-", "0", ".", "Left", "Right", "" +}; + +static cord_t kb_ta_ori_size; +static uint8_t kb_mode; +static void (*kb_close_action)(lv_obj_t *); +static void (*kb_ok_action)(lv_obj_t *); +static lv_btnms_t kb_btnms; +static bool kb_inited; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +void lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t *), void (*ok)(lv_obj_t *)) +{ + if(kb_inited == false) { + lv_btnms_get(LV_BTNMS_DEF, &kb_btnms); + kb_btnms.rects.opad = 4 + LV_STYLE_MULT; + kb_btnms.rects.vpad = 3 + LV_STYLE_MULT; + kb_btnms.rects.hpad = 3 + LV_STYLE_MULT; + kb_inited = true; + } + + if(kb_btnm != NULL) { + lv_app_kb_close(false); + } + + kb_ta = ta; + kb_mode = mode; + kb_close_action = close; + kb_ok_action = ok; + + kb_btnm = lv_btnm_create(lv_scr_act(), NULL); + lv_obj_set_size(kb_btnm, LV_HOR_RES, LV_VER_RES / 2); + lv_obj_align(kb_btnm, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_obj_set_style(kb_btnm, &kb_btnms); + lv_btnm_set_cb(kb_btnm, lv_app_kb_action); + if(mode & LV_APP_KB_MODE_TXT) lv_btnm_set_map(kb_btnm, kb_map_lc); + else if(mode & LV_APP_KB_MODE_NUM) lv_btnm_set_map(kb_btnm, kb_map_num); + + kb_win = lv_app_get_win_from_obj(kb_ta); + lv_obj_set_height(kb_win, LV_VER_RES / 2); + lv_obj_set_y(kb_win, 0); + + lv_app_style_t * app_style = lv_app_get_style(); + cord_t win_cont_h = lv_obj_get_height(lv_win_get_content(kb_win)) - 2 * app_style->win_style.content.scrable_rects.vpad; + kb_ta_ori_size = lv_obj_get_height(kb_ta); + if(lv_obj_get_height(kb_ta) > win_cont_h) { + lv_obj_set_height(kb_ta, win_cont_h); + } + + lv_ta_set_cursor_pos(kb_ta, LV_TA_CUR_LAST); + +#if LV_APP_ANIM_LEVEL != 0 + lv_page_focus(lv_win_get_content(kb_win), kb_ta, true); +#else + lv_page_focus(lv_win_get_content(kb_win), kb_ta, false); +#endif +} + +void lv_app_kb_close(bool ok) +{ + if(kb_btnm == NULL) return; + + if(ok == false) { + if(kb_close_action != NULL) kb_close_action(kb_ta); + } else { + if(kb_ok_action != NULL) kb_ok_action(kb_ta); + } + + lv_obj_set_height(kb_ta, kb_ta_ori_size); + + lv_obj_set_size(kb_win, LV_HOR_RES, LV_VER_RES); + kb_win = NULL; + + lv_obj_del(kb_btnm); + kb_btnm = NULL; + + kb_ta = NULL; +} + +static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i) +{ + const char ** map = lv_btnm_get_map(btnm); + const char * txt = map[i]; + + if(txt[0] <= '\011') txt++; + + if(strcmp(txt, "abc") == 0) { + lv_btnm_set_map(btnm, kb_map_lc); + } else if(strcmp(txt, "ABC") == 0) { + lv_btnm_set_map(btnm, kb_map_uc); + } else if(strcmp(txt, "1#") == 0) { + lv_btnm_set_map(btnm, kb_map_spec); + } else if(strcmp(txt, "Enter") == 0) { + lv_ta_add_char(kb_ta, '\n'); + } else if(strcmp(txt, "Left") == 0) { + lv_ta_cursor_left(kb_ta); + } else if(strcmp(txt, "Right") == 0) { + lv_ta_cursor_right(kb_ta); + } else if(strcmp(txt, "Del") == 0) { + lv_ta_del(kb_ta); + } else if(strcmp(txt, "+/-") == 0) { + uint16_t cur = lv_ta_get_cursor_pos(kb_ta); + const char * ta_txt = lv_ta_get_txt(kb_ta); + if(ta_txt[0] == '-') { + lv_ta_set_cursor_pos(kb_ta, 1); + lv_ta_del(kb_ta); + lv_ta_add_char(kb_ta, '+'); + lv_ta_set_cursor_pos(kb_ta, cur); + } else if(ta_txt[0] == '+') { + lv_ta_set_cursor_pos(kb_ta, 1); + lv_ta_del(kb_ta); + lv_ta_add_char(kb_ta, '-'); + lv_ta_set_cursor_pos(kb_ta, cur); + } else { + lv_ta_set_cursor_pos(kb_ta, 0); + lv_ta_add_char(kb_ta, '-'); + lv_ta_set_cursor_pos(kb_ta, cur + 1); + } + } else if(strcmp(txt, "Hide") == 0) { + lv_app_kb_close(false); + return LV_ACTION_RES_INV; + } else if(strcmp(txt, "Ok") == 0) { + lv_app_kb_close(true); + return LV_ACTION_RES_INV; + } else { + lv_ta_add_text(kb_ta, txt); + } + +#if LV_APP_ANIM_LEVEL != 0 + lv_page_focus(lv_win_get_content(kb_win), kb_ta, true); +#else + lv_page_focus(lv_win_get_content(kb_win), kb_ta, false); +#endif + return LV_ACTION_RES_OK; +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/lv_app/lv_app_spt.h b/lv_app/lv_app_sup.h similarity index 53% rename from lv_app/lv_app_spt.h rename to lv_app/lv_app_sup.h index 7a71e4739..c7ca34de1 100644 --- a/lv_app/lv_app_spt.h +++ b/lv_app/lv_app_sup.h @@ -1,10 +1,10 @@ /** - * @file lv_app_spt.h + * @file lv_app_sup.h * */ -#ifndef LV_APP_SPT_H -#define LV_APP_SPT_H +#ifndef LV_APP_SUP_H +#define LV_APP_SUP_H /********************* * INCLUDES @@ -18,15 +18,20 @@ /********************** * TYPEDEFS **********************/ +typedef enum +{ + LV_APP_KB_MODE_TXT = 0x01, + LV_APP_KB_MODE_NUM = 0x02, +}lv_app_kb_mode_t; /********************** * GLOBAL PROTOTYPES **********************/ -void lv_app_kb_open(lv_obj_t * ta); -void lv_app_kb_close(void); +void lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t *), void (*ok)(lv_obj_t *)); +void lv_app_kb_close(bool ok); /********************** * MACROS **********************/ -#endif /*LV_APP_SPT*/ +#endif /*LV_APP_SUP_H*/ diff --git a/lv_appx/lv_app_example.c b/lv_appx/lv_app_example.c index 42d3c9151..ce65dc7af 100644 --- a/lv_appx/lv_app_example.c +++ b/lv_appx/lv_app_example.c @@ -6,8 +6,8 @@ /********************* * INCLUDES *********************/ +#include #include "lv_app_example.h" -#include "../lv_app/lv_app_spt.h" #include /********************* @@ -167,14 +167,14 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) lv_obj_t * ta; ta = lv_ta_create(win, NULL); lv_obj_set_size_us(ta, 200, 100); - lv_obj_set_pos_us(ta, 20, 270); + lv_obj_set_pos_us(ta, 20, 200); // lv_rect_set_fit(ta, false, true); lv_page_set_rel_action(ta, kb_open); } lv_action_res_t kb_open(lv_obj_t * ta, lv_dispi_t * dispi) { - lv_app_kb_open(ta); + lv_app_kb_open(ta, LV_APP_KB_MODE_NUM, NULL, NULL); return LV_ACTION_RES_OK; } diff --git a/lv_misc/text.c b/lv_misc/text.c index 914f0f9ae..90601e877 100644 --- a/lv_misc/text.c +++ b/lv_misc/text.c @@ -60,6 +60,10 @@ void txt_get_size(point_t * size_res, const char * text, const font_t * font, line_start = new_line_start; } + if(line_start != 0 && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) { + size_res->y += letter_height + line_space; + } + /*Correction with the last line space*/ if(size_res->y >= 0) { size_res->y -= line_space; diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 5c071a295..92a4f0edc 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -225,20 +225,24 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) /*Only deal with the non empty lines*/ if(btn_cnt != 0) { - /*Calculate the unit width*/ - cord_t unit_w = max_w - ((btn_cnt-1) * btnms->rects.opad); - unit_w = unit_w / unit_cnt; + /*Calculate the width of all units*/ + cord_t all_unit_w = max_w - ((btn_cnt-1) * btnms->rects.opad); /*Set the button size and positions and set the texts*/ uint16_t i; cord_t act_x = btnms->rects.hpad; + cord_t act_unit_w; for(i = 0; i < btn_cnt; i++) { + /* one_unit_w = all_unit_w / unit_cnt + * act_unit_w = one_unit_w * button_width + * do this two operation but the multiplications first to divide a greater number */ + act_unit_w = (all_unit_w * lv_btnm_get_width_unit(map_p_tmp[i])) / unit_cnt; area_set(&ext->btn_areas[btn_i], act_x, act_y, - act_x + unit_w * lv_btnm_get_width_unit(map_p_tmp[i]), + act_x + act_unit_w, act_y + btn_h); - act_x += unit_w * lv_btnm_get_width_unit(map_p_tmp[i]) + btnms->rects.opad; + act_x += act_unit_w + btnms->rects.opad; i_tot ++; btn_i ++; diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 77c03a767..838e27997 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -162,7 +162,6 @@ void lv_label_set_text(lv_obj_t * label, const char * text) cord_t max_w = lv_obj_get_width(label); lv_labels_t * style = lv_obj_get_style(label); const font_t * font = font_get(style->font); - uint8_t letter_height = font_get_height(font); ext->dot_end = LV_LABEL_DOT_END_INV; /*Initialize the dot end index*/ @@ -331,7 +330,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) lv_label_ext_t * ext = lv_obj_get_ext(label); uint32_t line_start = 0; uint32_t new_line_start = 0; - cord_t max_length = lv_obj_get_width(label); + cord_t max_w = lv_obj_get_width(label); lv_labels_t * labels = lv_obj_get_style(label); const font_t * font = font_get(labels->font); uint8_t letter_height = font_get_height(font); @@ -339,18 +338,23 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) /*If the width will be expanded the set the max length to very big */ if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) { - max_length = LV_CORD_MAX; + max_w = LV_CORD_MAX; } /*Search the line of the index letter */; while (text[new_line_start] != '\0') { - new_line_start += txt_get_next_line(&text[line_start], font, labels->letter_space, max_length); + new_line_start += txt_get_next_line(&text[line_start], font, labels->letter_space, max_w); if(index < new_line_start || text[new_line_start] == '\0') break; /*The line of 'index' letter begins at 'line_start'*/ y += letter_height + labels->line_space; line_start = new_line_start; } + if((text[index - 1] == '\n' || text[index - 1] == '\r') && text[index] == '\0') { + y += letter_height + labels->line_space; + line_start = index; + } + /*Calculate the x coordinate*/ cord_t x = 0; uint32_t i; @@ -382,37 +386,37 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos) lv_label_ext_t * ext = lv_obj_get_ext(label); uint32_t line_start = 0; uint32_t new_line_start = 0; - cord_t max_length = lv_obj_get_width(label); - lv_labels_t * labels = lv_obj_get_style(label); - const font_t * font = font_get(labels->font); + cord_t max_w = lv_obj_get_width(label); + lv_labels_t * style = lv_obj_get_style(label); + const font_t * font = font_get(style->font); uint8_t letter_height = font_get_height(font); cord_t y = 0; /*If the width will be expanded set the max length to very big */ if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) { - max_length = LV_CORD_MAX; + max_w = LV_CORD_MAX; } /*Search the line of the index letter */; while (text[line_start] != '\0') { - new_line_start += txt_get_next_line(&text[line_start], font, labels->letter_space, max_length); - if(pos->y <= y + letter_height + labels->line_space) break; /*The line is found ('line_start')*/ - y += letter_height + labels->line_space; + new_line_start += txt_get_next_line(&text[line_start], font, style->letter_space, max_w); + if(pos->y <= y + letter_height + style->line_space) break; /*The line is found ('line_start')*/ + y += letter_height + style->line_space; line_start = new_line_start; } /*Calculate the x coordinate*/ cord_t x = 0; - if(labels->mid != 0) { + if(style->mid != 0) { cord_t line_w; line_w = txt_get_width(&text[line_start], new_line_start - line_start, - font, labels->letter_space); + font, style->letter_space); x += lv_obj_get_width(label) / 2 - line_w / 2; } uint16_t i; for(i = line_start; i < new_line_start-1; i++) { - x += font_get_width(font, text[i]) + labels->letter_space; + x += font_get_width(font, text[i]) + style->letter_space; if(pos->x < x) break; } diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index be2b25028..0e0051750 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -154,7 +154,10 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) break; case LV_SIGNAL_CORD_CHG: - lv_page_sb_refresh(page); + if(ext->scrolling != NULL) { + ext->scrolling->signal_f(ext->scrolling, LV_SIGNAL_CORD_CHG, &ext->scrolling->cords); + lv_page_sb_refresh(page); + } break; default: break;