diff --git a/lv_app/lv_app.c b/lv_app/lv_app.c index 31d15dbcd..1c32cf990 100644 --- a/lv_app/lv_app.c +++ b/lv_app/lv_app.c @@ -24,8 +24,8 @@ /*Actions*/ static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * dispi); static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_dispi_t * dispi); -static lv_action_res_t lv_app_sc_area_rel_action(lv_obj_t * sc, lv_dispi_t * dispi); -static lv_action_res_t lv_app_sc_area_pr_action(lv_obj_t * sc, lv_dispi_t * dispi); +static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_dispi_t * dispi); +static lv_action_res_t lv_app_sc_page_pr_action(lv_obj_t * sc, lv_dispi_t * dispi); 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); @@ -42,11 +42,11 @@ static void lv_app_init_style(void); static ll_dsc_t app_dsc_ll; /*Store a pointer to the app descriptors*/ static ll_dsc_t app_inst_ll; /*Store the running apps*/ +static lv_obj_t * app_scr; static lv_obj_t * menuh; /*Holder of timg_bubbleshe menu on the top*/ static lv_obj_t * app_btn; /*The "Apps" button on the menu*/ static lv_obj_t * sys_apph; /*Holder of the system app. buttons*/ static lv_obj_t * app_list; -static lv_obj_t * sc_area; static lv_obj_t * sc_page; static lv_app_style_t app_style; @@ -73,7 +73,6 @@ LV_IMG_DECLARE(img_right); LV_IMG_DECLARE(img_settings); LV_IMG_DECLARE(img_shut_down); LV_IMG_DECLARE(img_star); -LV_IMG_DECLARE(img_test); LV_IMG_DECLARE(img_up); LV_IMG_DECLARE(img_user); LV_IMG_DECLARE(img_video); @@ -95,6 +94,8 @@ void lv_app_init(void) ll_init(&app_dsc_ll, sizeof(lv_app_dsc_t *)); ll_init(&app_inst_ll, sizeof(lv_app_inst_t)); + app_scr = lv_scr_act(); + lv_app_init_icons(); lv_app_init_style(); @@ -105,13 +106,10 @@ void lv_app_init(void) lv_obj_set_style(sc_page, &app_style.sc_page_style); lv_obj_set_size(sc_page, LV_HOR_RES, LV_VER_RES); lv_obj_set_pos(sc_page, 0, 0); - sc_area = lv_btn_create(sc_page, NULL); - lv_obj_set_style(sc_area, &app_style.sc_area_style); - lv_rect_set_fit(sc_area, false, true); - lv_rect_set_layout(sc_area, LV_RECT_LAYOUT_GRID); - lv_btn_set_rel_action(sc_area, lv_app_sc_area_rel_action); - lv_btn_set_pr_action(sc_area, lv_app_sc_area_pr_action); - lv_page_glue_obj(sc_area, true); + lv_rect_set_fit(lv_page_get_scrable(sc_page), false, true); + lv_rect_set_layout(lv_page_get_scrable(sc_page), LV_RECT_LAYOUT_GRID); + lv_page_set_rel_action(sc_page, lv_app_sc_page_rel_action); + lv_page_set_pr_action(sc_page, lv_app_sc_page_pr_action); /*Menu on the top*/ menuh = lv_rect_create(lv_scr_act(), NULL); @@ -197,7 +195,7 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app) /*Save the current position of the scrollable part of the page*/ cord_t scrl_y = lv_obj_get_y(lv_page_get_scrable(sc_page)); - app->sc = lv_btn_create(sc_area, NULL); + app->sc = lv_btn_create(sc_page, NULL); lv_obj_set_free_p(app->sc, app); lv_obj_set_style(app->sc, &app_style.sc_style); lv_obj_set_opa(app->sc, app_style.sc_opa); @@ -281,9 +279,8 @@ void lv_app_refr_style(void) lv_obj_set_opa(menuh, app_style.menu_opa); lv_obj_set_opa(app_btn, app_style.menu_btn_opa); - lv_obj_set_width(sc_area, LV_HOR_RES - 2 * - (app_style.sc_page_style.bg_rects.hpad + - app_style.sc_page_style.scrable_rects.hpad)); + lv_obj_set_width(lv_page_get_scrable(sc_page), + LV_HOR_RES - 2 * (app_style.sc_page_style.bg_rects.hpad)); } void lv_app_rename(lv_app_inst_t * app, const char * name) @@ -297,6 +294,22 @@ void lv_app_rename(lv_app_inst_t * app, const char * name) } } +lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj) +{ + lv_obj_t * par = obj; + lv_obj_t * win; + + do { + win = par; + par = lv_obj_get_parent(win); + } + while(par != app_scr); + + return win; + + +} + const lv_app_dsc_t * lv_app_get_dsc(const char * name) { const lv_app_dsc_t ** dsc; @@ -383,7 +396,7 @@ static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_d return LV_ACTION_RES_INV; } -static lv_action_res_t lv_app_sc_area_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) +static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) { /*Close the list if opened*/ if(app_list != NULL) { @@ -394,7 +407,7 @@ static lv_action_res_t lv_app_sc_area_rel_action(lv_obj_t * sc, lv_dispi_t * dis return LV_ACTION_RES_OK; } -static lv_action_res_t lv_app_sc_area_pr_action(lv_obj_t * sc, lv_dispi_t * dispi) +static lv_action_res_t lv_app_sc_page_pr_action(lv_obj_t * sc, lv_dispi_t * dispi) { /*Close the list if opened*/ if(app_list != NULL) { @@ -650,25 +663,18 @@ static void lv_app_init_style(void) app_style.app_list_style.bg_pages.sb_rects.objs.color = COLOR_GRAY; app_style.app_list_style.bg_pages.sb_rects.gcolor = COLOR_GRAY; - /*Shortcut area styles*/ - lv_btns_get(LV_BTNS_DEF,&app_style.sc_area_style); - app_style.sc_area_style.flags[LV_BTN_STATE_REL].transp = 1; - app_style.sc_area_style.flags[LV_BTN_STATE_PR].transp = 1; - app_style.sc_area_style.rects.hpad = 20 * LV_STYLE_MULT; - app_style.sc_area_style.rects.vpad = 50 * LV_STYLE_MULT; - app_style.sc_area_style.rects.opad = 20 * LV_STYLE_MULT; - + /*Shortcut page styles*/ lv_pages_get(LV_PAGES_DEF,&app_style.sc_page_style); app_style.sc_page_style.bg_rects.empty = 1; app_style.sc_page_style.bg_rects.round = 0; app_style.sc_page_style.bg_rects.bwidth = 0; - app_style.sc_page_style.bg_rects.vpad = 0; + app_style.sc_page_style.bg_rects.vpad = app_style.menu_h; app_style.sc_page_style.bg_rects.hpad = 0; app_style.sc_page_style.bg_rects.opad = 0; app_style.sc_page_style.scrable_rects.objs.transp = 1; - app_style.sc_page_style.scrable_rects.vpad = 0; - app_style.sc_page_style.scrable_rects.hpad = 0; - app_style.sc_page_style.scrable_rects.opad = 0; + app_style.sc_page_style.scrable_rects.hpad = 20 * LV_STYLE_MULT; + app_style.sc_page_style.scrable_rects.vpad = 20 * LV_STYLE_MULT; + app_style.sc_page_style.scrable_rects.opad = 20 * LV_STYLE_MULT; /*Shortcut styles*/ lv_btns_get(LV_BTNS_DEF,&app_style.sc_style); @@ -698,7 +704,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.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; } diff --git a/lv_app/lv_app.h b/lv_app/lv_app.h index 3feac4f30..ade5789c0 100644 --- a/lv_app/lv_app.h +++ b/lv_app/lv_app.h @@ -77,7 +77,6 @@ typedef struct { lv_imgs_t menu_btn_img_style; lv_lists_t app_list_style; lv_pages_t sc_page_style; - lv_btns_t sc_area_style; lv_wins_t win_style; lv_btns_t sc_style; lv_labels_t sc_title_style; @@ -108,6 +107,7 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app); void lv_app_sc_close(lv_app_inst_t * app); lv_obj_t * lv_app_win_open(lv_app_inst_t * app); void lv_app_win_close(lv_app_inst_t * app); +lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj); const lv_app_dsc_t * lv_app_get_dsc(const char * name); lv_app_style_t * lv_app_get_style(void); diff --git a/lv_app/lv_app_spt.c b/lv_app/lv_app_spt.c new file mode 100644 index 000000000..2fba67485 --- /dev/null +++ b/lv_app/lv_app_spt.c @@ -0,0 +1,67 @@ +/** + * @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 VARIABLES + **********************/ +static lv_obj_t * kb_btnm; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +void lv_app_kb_open(lv_obj_t * ta) +{ + if(kb_btnm != NULL) { + lv_app_kb_close(); + } + + 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_ta_add_text(ta, "alma\n\nkorte\n\ncitrom\nbarack\nbanaaaan\n\n"); + lv_ta_set_cursor_pos(ta, LV_TA_CUR_LAST); + + lv_obj_t * win = lv_app_get_win_from_obj(ta); + lv_obj_set_height(win, LV_VER_RES / 2); + lv_obj_set_y(win, 0); + + lv_page_focus(lv_win_get_content(win), ta, true); +} + +void lv_app_kb_close(void) +{ + lv_obj_del(kb_btnm); + kb_btnm = NULL; + +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/lv_app/lv_app_spt.h b/lv_app/lv_app_spt.h new file mode 100644 index 000000000..7a71e4739 --- /dev/null +++ b/lv_app/lv_app_spt.h @@ -0,0 +1,32 @@ +/** + * @file lv_app_spt.h + * + */ + +#ifndef LV_APP_SPT_H +#define LV_APP_SPT_H + +/********************* + * INCLUDES + *********************/ +#include "lv_app.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void lv_app_kb_open(lv_obj_t * ta); +void lv_app_kb_close(void); + +/********************** + * MACROS + **********************/ + +#endif /*LV_APP_SPT*/ diff --git a/lv_appx/lv_app_example.c b/lv_appx/lv_app_example.c index fa0953e7f..016fbff6d 100644 --- a/lv_appx/lv_app_example.c +++ b/lv_appx/lv_app_example.c @@ -7,6 +7,7 @@ * INCLUDES *********************/ #include "lv_app_example.h" +#include "../lv_app/lv_app_spt.h" #include /********************* @@ -147,6 +148,7 @@ static void my_sc_close(lv_app_inst_t * app) } +lv_action_res_t kb_open(lv_obj_t * ta, lv_dispi_t * dispi); /** * Open the application in a window * @param app pointer to an application @@ -155,9 +157,25 @@ static void my_sc_close(lv_app_inst_t * app) */ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) { + + lv_obj_t * label; label = lv_label_create(win, NULL); lv_label_set_text(label, ((app_data_t *)app->app_data)->txt); + + + lv_obj_t * ta; + ta = lv_ta_create(win, NULL); + lv_obj_set_size_us(ta, 200, 300); + lv_obj_set_pos_us(ta, 20, 270); + 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); + return LV_ACTION_RES_OK; } /** diff --git a/lv_misc/anim.c b/lv_misc/anim.c index 4cde83ed7..cdd2bfa59 100644 --- a/lv_misc/anim.c +++ b/lv_misc/anim.c @@ -48,7 +48,7 @@ static anim_path_t anim_path_step[] = {64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192,}; + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192,}; /********************** * MACROS @@ -179,10 +179,10 @@ static void anim_task (void) /* Get the index of the path array based on the elapsed time*/ uint8_t path_i; - if(a->time != 0) { - path_i = a->act_time * (ANIM_PATH_LENGTH - 1) / a->time; + if(a->time == a->act_time) { + path_i = ANIM_PATH_LENGTH - 1; /*Use the last value id the time fully elapsed*/ } else { - path_i = ANIM_PATH_LENGTH - 1; + path_i = a->act_time * (ANIM_PATH_LENGTH - 1) / a->time; } /* Get the new value which will be proportional to the current element of 'path_p' * and the 'start' and 'end' values*/ diff --git a/lv_obj/lv_dispi.h b/lv_obj/lv_dispi.h index 24a1d7656..7d84ada63 100644 --- a/lv_obj/lv_dispi.h +++ b/lv_obj/lv_dispi.h @@ -35,6 +35,15 @@ typedef struct uint8_t long_press_sent :1; }lv_dispi_t; + +typedef enum +{ + LV_ACTION_RES_OK = 0, + LV_ACTION_RES_INV = 0, +}lv_action_res_t; + +typedef lv_action_res_t ( * lv_action_t) (struct __LV_OBJ_T * obj, lv_dispi_t * dispi); + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 4c0d7bf3b..a25f45367 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -6,13 +6,17 @@ /********************* * INCLUDES *********************/ -#include "lv_obj.h" -#include "../lv_draw/lv_draw_rbasic.h" -#include "../lv_draw/lv_draw_vbasic.h" -#include "../lv_misc/anim.h" -#include "lv_dispi.h" -#include "lv_refr.h" -#include "misc/math/math_base.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef LV_IMG_DEF_WALLPAPER #include "../lv_objx/lv_img.h" diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index f0b109d7d..f96599e3a 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -231,7 +231,7 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) * @param btn pointer to a button object * @param pr_action pointer to function */ -void lv_btn_set_pr_action(lv_obj_t * btn, lv_btn_action_t pr_action) +void lv_btn_set_pr_action(lv_obj_t * btn, lv_action_t pr_action) { lv_btn_ext_t * ext = lv_obj_get_ext(btn); @@ -243,7 +243,7 @@ void lv_btn_set_pr_action(lv_obj_t * btn, lv_btn_action_t pr_action) * @param btn pointer to a button object * @param rel_action pointer to functionREL */ -void lv_btn_set_rel_action(lv_obj_t * btn, lv_btn_action_t rel_action) +void lv_btn_set_rel_action(lv_obj_t * btn, lv_action_t rel_action) { lv_btn_ext_t * btn_p = lv_obj_get_ext(btn); @@ -255,7 +255,7 @@ void lv_btn_set_rel_action(lv_obj_t * btn, lv_btn_action_t rel_action) * @param btn pointer to a button object * @param lpr_action pointer to function */ -void lv_btn_set_lpr_action(lv_obj_t * btn, lv_btn_action_t lpr_action) +void lv_btn_set_lpr_action(lv_obj_t * btn, lv_action_t lpr_action) { lv_btn_ext_t * ext = lv_obj_get_ext(btn); @@ -267,7 +267,7 @@ void lv_btn_set_lpr_action(lv_obj_t * btn, lv_btn_action_t lpr_action) * @param btn pointer to a button object * @param lpr_rep_action pointer to function */ -void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_btn_action_t lpr_rep_action) +void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_action_t lpr_rep_action) { lv_btn_ext_t * ext = lv_obj_get_ext(btn); diff --git a/lv_objx/lv_btn.h b/lv_objx/lv_btn.h index fe3460a51..5e4687b10 100644 --- a/lv_objx/lv_btn.h +++ b/lv_objx/lv_btn.h @@ -33,14 +33,6 @@ typedef enum LV_BTN_STATE_NUM, }lv_btn_state_t; -typedef enum -{ - LV_ACTION_RES_OK = 0, - LV_ACTION_RES_INV = 0, -}lv_action_res_t; - -typedef lv_action_res_t (*lv_btn_action_t) (lv_obj_t*, lv_dispi_t *); - typedef struct { uint8_t light_en :1; @@ -73,10 +65,10 @@ typedef struct { lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ /*New data for this type */ - lv_btn_action_t pr_action; - lv_btn_action_t rel_action; - lv_btn_action_t lpr_action; - lv_btn_action_t lpr_rep_action; + lv_action_t pr_action; + lv_action_t rel_action; + lv_action_t lpr_action; + lv_action_t lpr_rep_action; lv_btn_state_t state; uint8_t tgl :1; /*1: Toggle enabled*/ @@ -94,10 +86,10 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy); void lv_btn_set_tgl(lv_obj_t * btn, bool tgl); void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); -void lv_btn_set_pr_action(lv_obj_t * btn, lv_btn_action_t pr_action); -void lv_btn_set_rel_action(lv_obj_t * btn, lv_btn_action_t rel_action); -void lv_btn_set_lpr_action(lv_obj_t * btn, lv_btn_action_t lpr_action); -void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_btn_action_t lpr_rep_action); +void lv_btn_set_pr_action(lv_obj_t * btn, lv_action_t pr_action); +void lv_btn_set_rel_action(lv_obj_t * btn, lv_action_t rel_action); +void lv_btn_set_lpr_action(lv_obj_t * btn, lv_action_t lpr_action); +void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_action_t lpr_rep_action); bool lv_btn_get_tgl(lv_obj_t * btn); lv_btn_state_t lv_btn_get_state(lv_obj_t * btn); diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 4b91c5790..014e448c3 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -28,7 +28,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ #endif static uint8_t lv_btnm_get_width_unit(const char * btn_str); static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map); -static bool lv_btnm_btn_release_action(lv_obj_t * btnm, lv_dispi_t * dispi); +static lv_action_res_t lv_btnm_btn_release_action(lv_obj_t * btnm, lv_dispi_t * dispi); static void lv_btnms_init(void); /********************** @@ -131,6 +131,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) * Use octal numbers (e.g. "\003") to set the relative * width of a button. (max. 9 -> \011) * (e.g. const char * str[] = {"a", "b", "\n", "\004c", "d", ""}). + * The button do not copy the array so it can not be a local variable. */ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) { @@ -379,12 +380,12 @@ static uint8_t lv_btnm_get_width_unit(const char * btn_str) * @param dispi pointer to the caller display input. * @return true: if the button remains valid (the button matrix or the button is not deleted) */ -static bool lv_btnm_btn_release_action(lv_obj_t * btn, lv_dispi_t * dispi) +static lv_action_res_t lv_btnm_btn_release_action(lv_obj_t * btn, lv_dispi_t * dispi) { lv_obj_t * btnm = lv_obj_get_parent(btn); lv_btnm_ext_t * ext = lv_obj_get_ext(btnm); uint8_t id = lv_obj_get_free_num(btn); - bool ret; + lv_action_res_t ret; if(ext->cb != NULL) { ret = ext->cb(btnm, btn, id); /*Call the set callback function*/ } diff --git a/lv_objx/lv_btnm.h b/lv_objx/lv_btnm.h index a957f790d..77d16961c 100644 --- a/lv_objx/lv_btnm.h +++ b/lv_objx/lv_btnm.h @@ -71,6 +71,6 @@ lv_btnm_callback_t lv_btnm_get_cb(lv_obj_t * btnm); * MACROS **********************/ -#endif +#endif /*USE_LV_BTNM*/ -#endif +#endif /*LV_BTNM_H*/ diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 5713e4014..4f4649ffb 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -110,7 +110,7 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) * @param rel_action pointer to release action function (like with lv_btn) * @return pointer to the new list element which can be customized (a button) */ -lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, lv_btn_action_t rel_action) +lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, lv_action_t rel_action) { lv_lists_t * lists = lv_obj_get_style(list); lv_list_ext_t * ext = lv_obj_get_ext(list); diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 423dbf3f6..97755d972 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -65,7 +65,7 @@ typedef struct **********************/ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy); bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param); -lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, lv_btn_action_t rel_action); +lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, lv_action_t rel_action); lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy); void lv_list_down(lv_obj_t * list); diff --git a/lv_objx/lv_mbox.c b/lv_objx/lv_mbox.c index ba0d2211a..62ccfd219 100644 --- a/lv_objx/lv_mbox.c +++ b/lv_objx/lv_mbox.c @@ -91,6 +91,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy) /*Copy an existing message box*/ else { lv_mbox_ext_t * copy_ext = lv_obj_get_ext(copy); + /*TODO*/ } return new_mbox; @@ -173,7 +174,7 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param) * @param rel_action a function which will be called when the button is relesed * @return pointer to the created button (lv_btn) */ -lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_btn_action_t rel_action) +lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t rel_action) { lv_mbox_ext_t * ext = lv_obj_get_ext(mbox); lv_mboxs_t * style = lv_obj_get_style(mbox); diff --git a/lv_objx/lv_mbox.h b/lv_objx/lv_mbox.h index b728af138..840754bd9 100644 --- a/lv_objx/lv_mbox.h +++ b/lv_objx/lv_mbox.h @@ -68,7 +68,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy); bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param); lv_mboxs_t * lv_mboxs_get(lv_mboxs_builtin_t style, lv_mboxs_t * copy); -lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_btn_action_t rel_action); +lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t rel_action); bool lv_mbox_close_action (lv_obj_t * mbox, lv_dispi_t *dispi); void lv_mbox_auto_close(lv_obj_t * mbox, uint16_t tout); void lv_mbox_set_title(lv_obj_t * mbox, const char * title); diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index b4938cfbb..efb4b83eb 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -264,6 +264,18 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa lv_inv_area(&page_ext->sbv); } break; + case LV_SIGNAL_PRESSED: + if(page_ext->pr_action != NULL) { + page_ext->pr_action(page, param); + } + break; + case LV_SIGNAL_RELEASED: + if(lv_dispi_is_dragging(param) == false) { + if(page_ext->rel_action != NULL) { + page_ext->rel_action(page, param); + } + } + break; default: break; @@ -277,6 +289,29 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa * Setter functions *====================*/ +/** + * Set a release action for the page + * @param page pointer to a page object + * @param rel_action a function to call when the page is released + */ +void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action) +{ + lv_page_ext_t * ext = lv_obj_get_ext(page); + ext->rel_action = rel_action; +} + +/** + * Set a press action for the page + * @param page pointer to a page object + * @param pr_action a function to call when the page is pressed + */ +void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action) +{ + lv_page_ext_t * ext = lv_obj_get_ext(page); + ext->pr_action = pr_action; +} + + /** * Glue the object to the page. After it the page can be moved (dragged) with this object too. * @param obj pointer to an object on a page @@ -309,17 +344,17 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en) /*Out of the page on the top*/ if(scrlable_y + obj_y < 0) { - /*Calculate a new position try to align to the middle*/ + /*Calculate a new position and to let scrable_rects.vpad space above*/ scrlable_y = -(obj_y - style->scrable_rects.vpad - style->bg_rects.vpad); - scrlable_y += page_h / 2 - obj_h / 2; + scrlable_y += style->scrable_rects.vpad; refr = true; } /*Out of the page on the bottom*/ else if(scrlable_y + obj_y + obj_h > page_h) { - /*Calculate a new position try to align to the middle*/ + /*Calculate a new position and to let scrable_rects.vpad space below*/ scrlable_y = -obj_y; scrlable_y += page_h - obj_h; - scrlable_y -= page_h / 2 - obj_h / 2; + scrlable_y -= style->scrable_rects.vpad; refr = true; } diff --git a/lv_objx/lv_page.h b/lv_objx/lv_page.h index 942392a6a..691492514 100644 --- a/lv_objx/lv_page.h +++ b/lv_objx/lv_page.h @@ -54,6 +54,8 @@ typedef struct lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * scrolling; /*The scrollable object on the background*/ + lv_action_t rel_action; + lv_action_t pr_action; area_t sbh; /*Horizontal scrollbar*/ area_t sbv; /*Vertical scrollbar*/ uint8_t sbh_draw :1; /*1: horizontal scrollbar is visible now*/ @@ -70,6 +72,8 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy); lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy); bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param); +void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action); +void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action); void lv_page_glue_obj(lv_obj_t * page, bool glue); void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en); lv_obj_t * lv_page_get_scrable(lv_obj_t * page); diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 042bcd820..2c642eb08 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -17,10 +17,6 @@ /********************* * DEFINES *********************/ -#define LV_TA_MAX_LENGTH 512 -#define LV_TA_DEF_WIDTH 120 -#define LV_TA_DEF_HEIGHT 80 -#define LV_TA_CUR_BLINK_TIME 400 /*ms*/ /********************** * TYPEDEFS @@ -93,7 +89,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); lv_label_set_text(ext->label, "Text area"); lv_page_glue_obj(ext->label, true); - lv_obj_set_click(ext->label, true); + lv_obj_set_click(ext->label, false); lv_obj_set_style(new_ta, lv_tas_get(LV_TAS_DEF, NULL)); lv_obj_set_size_us(new_ta, LV_TA_DEF_WIDTH, LV_TA_DEF_HEIGHT); } @@ -115,6 +111,8 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) a.time = LV_TA_CUR_BLINK_TIME; a.act_time = 0; a.end_cb = NULL; + a.start = 0; + a.end= 1; a.repeat = 1; a.repeat_pause = 0; a.playback = 1; @@ -230,7 +228,7 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) } /** - * Set the text os a text area + * Set the text of a text area * @param ta pointer to a text area * @param txt pointer to the text */ @@ -539,10 +537,10 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des static void lv_ta_hide_cursor(lv_obj_t * ta, uint8_t hide) { lv_ta_ext_t * ta_ext = lv_obj_get_ext(ta); - ta_ext->cur_hide = hide == 0 ? 0 : 1; - - lv_obj_inv(ta); - + if(hide != ta_ext->cur_hide) { + ta_ext->cur_hide = hide == 0 ? 0 : 1; + lv_obj_inv(ta); + } } /** diff --git a/lv_objx/lv_ta.h b/lv_objx/lv_ta.h index 0a3e846db..a4f7f3d70 100644 --- a/lv_objx/lv_ta.h +++ b/lv_objx/lv_ta.h @@ -64,6 +64,7 @@ void lv_ta_add_char(lv_obj_t * ta, char c); void lv_ta_add_text(lv_obj_t * ta, const char * txt); void lv_ta_set_text(lv_obj_t * ta, const char * txt); void lv_ta_del(lv_obj_t * ta); + void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos); void lv_ta_cursor_right (lv_obj_t * ta); void lv_ta_cursor_left(lv_obj_t * taj); diff --git a/lv_objx/lv_win.c b/lv_objx/lv_win.c index 8a854f28c..15b9b5225 100644 --- a/lv_objx/lv_win.c +++ b/lv_objx/lv_win.c @@ -212,7 +212,7 @@ bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param) * @param rel_action a function pointer to call when the button is released * @return pointer to the created button object */ -lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img_path, lv_btn_action_t rel_action) +lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img_path, lv_action_t rel_action) { lv_win_ext_t * ext = lv_obj_get_ext(win); lv_wins_t * style = lv_obj_get_style(win); @@ -282,6 +282,18 @@ const char * lv_win_get_title(lv_obj_t * win) return lv_label_get_text(ext->title); } +/** + * Get the content object (lv_page type) of a window + * @param win pointer to a window object + * @return pointer to the content page object of a window + */ +lv_obj_t * lv_win_get_content(lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext(win); + + return ext->content; +} + /** * Get the pointer of a widow from one of its control button. * It is useful in the action of the control buttons where only button is known. diff --git a/lv_objx/lv_win.h b/lv_objx/lv_win.h index 029083c5d..1dacc2894 100644 --- a/lv_objx/lv_win.h +++ b/lv_objx/lv_win.h @@ -71,11 +71,12 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy); bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param); lv_wins_t * lv_wins_get(lv_wins_builtin_t style, lv_wins_t * copy); -lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img, lv_btn_action_t rel_action); +lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img, lv_action_t rel_action); bool lv_win_close_action(lv_obj_t * btn, lv_dispi_t * dispi); void lv_win_set_title(lv_obj_t * win, const char * title); const char * lv_win_get_title(lv_obj_t * win); +lv_obj_t * lv_win_get_content(lv_obj_t * win); lv_obj_t * lv_win_get_from_ctrl_btn(lv_obj_t * ctrl_btn); /********************** * MACROS