mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Release: Version 2.0
This commit is contained in:
parent
aa8c80c2a8
commit
53cd8bfd70
@ -183,19 +183,21 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app)
|
||||
lv_btn_set_rel_action(app->sc, lv_app_sc_rel_action);
|
||||
lv_btn_set_lpr_action(app->sc, lv_app_sc_lpr_action);
|
||||
lv_page_glue_obj(app->sc, true);
|
||||
|
||||
/*Create a title on top of the shortcut*/
|
||||
app->sc_title = lv_label_create(app->sc, NULL);
|
||||
lv_obj_set_style(app->sc_title, &app_style.sc_title_style);
|
||||
#if LV_APP_EFFECT_ANIM != 0
|
||||
lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_SCROLL);
|
||||
#else
|
||||
lv_obj_set_size(app->sc_title, LV_APP_SC_WIDTH, font_get_height(font_get(app_style.sc_title_style.font)));
|
||||
lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_DOTS);
|
||||
#endif
|
||||
lv_label_set_text(app->sc_title, app->name);
|
||||
lv_obj_align_us(app->sc_title, NULL, LV_ALIGN_IN_TOP_MID, 0, app_style.sc_title_margin);
|
||||
|
||||
if((app->dsc->mode & LV_APP_MODE_NO_SC_TITLE) == 0) {
|
||||
/*Create a title on top of the shortcut*/
|
||||
app->sc_title = lv_label_create(app->sc, NULL);
|
||||
lv_obj_set_style(app->sc_title, &app_style.sc_title_style);
|
||||
#if LV_APP_EFFECT_ANIM != 0
|
||||
lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_SCROLL);
|
||||
#else
|
||||
lv_obj_set_size(app->sc_title, LV_APP_SC_WIDTH, font_get_height(font_get(app_style.sc_title_style.font)));
|
||||
lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_DOTS);
|
||||
#endif
|
||||
lv_label_set_text(app->sc_title, app->name);
|
||||
lv_obj_align_us(app->sc_title, NULL, LV_ALIGN_IN_TOP_MID, 0, app_style.sc_title_margin);
|
||||
} else {
|
||||
app->sc_title = NULL;
|
||||
}
|
||||
/*Allocate data and call the app specific sc_open function*/
|
||||
app->sc_data = dm_alloc(app->dsc->sc_data_size);
|
||||
app->dsc->sc_open(app, app->sc);
|
||||
@ -301,7 +303,7 @@ uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , cons
|
||||
* @param receiver pointer to an application which receives data
|
||||
* @return false: no connection, true: there is connection
|
||||
*/
|
||||
bool lv_app_check_con(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
bool lv_app_con_check(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
{
|
||||
lv_app_con_t * con;
|
||||
|
||||
@ -319,9 +321,9 @@ bool lv_app_check_con(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
* @param sender pointer to a data sender application
|
||||
* @param receiver pointer to a data receiver application
|
||||
*/
|
||||
void lv_app_set_con(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
void lv_app_con_set(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
{
|
||||
if(lv_app_check_con(sender, receiver) == false) {
|
||||
if(lv_app_con_check(sender, receiver) == false) {
|
||||
lv_app_con_t * con;
|
||||
con = ll_ins_head(&app_con_ll);
|
||||
con->sender = sender;
|
||||
@ -334,7 +336,7 @@ void lv_app_set_con(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
* @param sender pointer to a data sender application
|
||||
* @param receiver pointer to a data receiver application
|
||||
*/
|
||||
void lv_app_del_con(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
void lv_app_con_del(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
{
|
||||
lv_app_con_t * con;
|
||||
|
||||
@ -351,7 +353,7 @@ void lv_app_del_con(lv_app_inst_t * sender, lv_app_inst_t * receiver)
|
||||
* @param name name of the app. dsc.
|
||||
* @return pointer to the app. dsc.
|
||||
*/
|
||||
const lv_app_dsc_t * lv_app_get_dsc(const char * name)
|
||||
const lv_app_dsc_t * lv_app_dsc_get(const char * name)
|
||||
{
|
||||
const lv_app_dsc_t ** dsc;
|
||||
LL_READ(app_dsc_ll, dsc) {
|
||||
@ -374,7 +376,7 @@ void lv_app_rename(lv_app_inst_t * app, const char * name)
|
||||
app->name = dm_alloc(strlen(name) + 1);
|
||||
strcpy(app->name, name);
|
||||
|
||||
if(app->sc != NULL) {
|
||||
if(app->sc_title != NULL) {
|
||||
lv_label_set_text(app->sc_title, app->name);
|
||||
}
|
||||
}
|
||||
@ -384,7 +386,7 @@ void lv_app_rename(lv_app_inst_t * app, const char * name)
|
||||
* @param obj pointer to an object on the window
|
||||
* @return pointer to the window of 'obj'
|
||||
*/
|
||||
lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj)
|
||||
lv_obj_t * lv_app_win_get_from_obj(lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_t * par = obj;
|
||||
lv_obj_t * win;
|
||||
@ -398,14 +400,13 @@ lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj)
|
||||
return win;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the list of the running applications. (Get he next element)
|
||||
* @param prev the previous application (at the first call give NULL to get the first application)
|
||||
* @param dsc pointer to an application descriptor to filer the applications (NULL to do not filter)
|
||||
* @return pointer to the next running application or NULL if no more
|
||||
*/
|
||||
lv_app_inst_t * lv_app_get_next_app(lv_app_inst_t * prev, lv_app_dsc_t * dsc)
|
||||
lv_app_inst_t * lv_app_get_next(lv_app_inst_t * prev, lv_app_dsc_t * dsc)
|
||||
{
|
||||
lv_app_inst_t * next;
|
||||
|
||||
@ -492,7 +493,6 @@ static void lv_app_init_desktop(void)
|
||||
lv_app_refr_style();
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------
|
||||
APP. MENU ACTIONS
|
||||
------------------------*/
|
||||
@ -513,7 +513,6 @@ static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * d
|
||||
/*Create the app. list*/
|
||||
else {
|
||||
app_list = lv_list_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_hidden(app_list, true);
|
||||
lv_obj_set_style(app_list, &app_style.app_list_style);
|
||||
lv_obj_set_opa(app_list, app_style.menu_opa);
|
||||
lv_obj_set_size(app_list, app_style.app_list_w, app_style.app_list_h);
|
||||
@ -522,36 +521,12 @@ static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * d
|
||||
lv_app_dsc_t ** dsc;
|
||||
lv_obj_t * elem;
|
||||
LL_READ(app_dsc_ll, dsc) {
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
|
||||
if(((*dsc)->mode & LV_APP_MODE_NOT_LIST) == 0) {
|
||||
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
|
||||
lv_obj_set_free_p(elem, *dsc);
|
||||
lv_obj_set_opa(elem, app_style.menu_btn_opa);
|
||||
}
|
||||
}
|
||||
lv_obj_set_hidden(app_list, false);
|
||||
}
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
@ -573,7 +548,7 @@ 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_EFFECT_ANIM != 0 && LV_APP_EFFECT_OPA != 0 && LV_APP_ANIM_SC != 0
|
||||
#if LV_APP_EFFECT_ANIM != 0 && LV_APP_EFFECT_OPA_ANIM != 0 && LV_APP_ANIM_SC != 0
|
||||
anim_t a;
|
||||
a.act_time = 0;
|
||||
a.time = LV_APP_ANIM_SC;
|
||||
@ -586,7 +561,6 @@ static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_d
|
||||
a.start = OPA_TRANSP;
|
||||
a.fp = (anim_fp_t) lv_obj_set_opa;
|
||||
anim_create(&a);
|
||||
|
||||
#endif
|
||||
|
||||
return LV_ACTION_RES_INV;
|
||||
@ -660,10 +634,10 @@ static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi)
|
||||
/*Add connection to this application*/
|
||||
if(style == &app_style.sc_style) {
|
||||
lv_obj_set_style(sc, &app_style.sc_rec_style);
|
||||
lv_app_set_con(con_send, app);
|
||||
lv_app_con_set(con_send, app);
|
||||
} else { /*Remove the applications connection*/
|
||||
lv_obj_set_style(sc, &app_style.sc_style);
|
||||
lv_app_del_con(con_send, app);
|
||||
lv_app_con_del(con_send, app);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -699,7 +673,7 @@ static lv_action_res_t lv_app_sc_lpr_action(lv_obj_t * sc, lv_dispi_t * dispi)
|
||||
lv_obj_set_style(sc, &app_style.sc_send_style);
|
||||
lv_app_inst_t * i;
|
||||
LL_READ(app_inst_ll, i) {
|
||||
if(i->sc != NULL && lv_app_check_con(con_send, i) != false) {
|
||||
if(i->sc != NULL && lv_app_con_check(con_send, i) != false) {
|
||||
lv_obj_set_style(i->sc, &app_style.sc_rec_style);
|
||||
}
|
||||
}
|
||||
@ -809,7 +783,7 @@ static lv_action_res_t lv_app_win_open_anim_create(lv_app_inst_t * app)
|
||||
a.fp = (anim_fp_t) lv_obj_set_y;
|
||||
anim_create(&a);
|
||||
|
||||
#if LV_APP_EFFECT_OPA != 0
|
||||
#if LV_APP_EFFECT_OPA_ANIM != 0
|
||||
a.start = OPA_TRANSP;
|
||||
a.end = OPA_COVER;
|
||||
a.fp = (anim_fp_t) lv_obj_set_opar;
|
||||
@ -871,7 +845,7 @@ static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app)
|
||||
#endif
|
||||
anim_create(&a);
|
||||
|
||||
#if LV_APP_EFFECT_OPA != 0
|
||||
#if LV_APP_EFFECT_OPA_ANIM != 0
|
||||
a.end = OPA_TRANSP;
|
||||
a.start = OPA_COVER;
|
||||
a.fp = (anim_fp_t) lv_obj_set_opar;
|
||||
|
@ -23,13 +23,8 @@
|
||||
typedef enum
|
||||
{
|
||||
LV_APP_MODE_NONE = 0x0000,
|
||||
LV_APP_MODE_RUN_ONCE = 0x0001,
|
||||
LV_APP_MODE_NO_SC = 0x0002, /*No short cut*/
|
||||
LV_APP_MODE_NO_WIN = 0x0004, /*No window mode*/
|
||||
LV_APP_MODE_NO_CON = 0x0008, /*No connection to other apps*/
|
||||
LV_APP_MODE_NO_CLOSE = 0x0010, /*No close control button*/
|
||||
LV_APP_MODE_NO_FIX = 0x0020, /*No fix control button*/
|
||||
LV_APP_MODE_NO_SC_TITLE = 0x0040, /*No short cut*/
|
||||
LV_APP_MODE_NOT_LIST = 0x0001, /*Do not list the application*/
|
||||
LV_APP_MODE_NO_SC_TITLE = 0x0002, /*No short cut title*/
|
||||
}lv_app_mode_t;
|
||||
|
||||
typedef enum
|
||||
@ -39,6 +34,7 @@ typedef enum
|
||||
LV_APP_COM_TYPE_SYS, /*System level event*/
|
||||
LV_APP_COM_TYPE_LOG, /*String about an event to log*/
|
||||
LV_APP_COM_TYPE_NOTE, /*String to display to the user as a notification*/
|
||||
LV_APP_COM_TYPE_TRIG, /*A trigger to do some specific action (data is ignored)*/
|
||||
}lv_app_com_type_t;
|
||||
|
||||
struct __LV_APP_DSC_T;
|
||||
@ -106,15 +102,15 @@ 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_obj_t * lv_app_win_get_from_obj(lv_obj_t * obj);
|
||||
const lv_app_dsc_t * lv_app_dsc_get(const char * name);
|
||||
|
||||
void lv_app_set_con(lv_app_inst_t * sender, lv_app_inst_t * receiver);
|
||||
void lv_app_con_set(lv_app_inst_t * sender, lv_app_inst_t * receiver);
|
||||
lv_app_style_t * lv_app_get_style(void);
|
||||
void lv_app_rename(lv_app_inst_t * app, const char * name);
|
||||
void lv_app_refr_style(void);
|
||||
|
||||
lv_app_inst_t * lv_app_get_next_app(lv_app_inst_t * prev, lv_app_dsc_t * dsc);
|
||||
lv_app_inst_t * lv_app_get_next(lv_app_inst_t * prev, lv_app_dsc_t * dsc);
|
||||
|
||||
const lv_app_dsc_t * lv_app_example_init(void);
|
||||
|
||||
|
@ -61,6 +61,7 @@ static const char * kb_map_num[] = {
|
||||
|
||||
static cord_t kb_ta_ori_size;
|
||||
static uint8_t kb_mode;
|
||||
static bool kb_first;
|
||||
static void (*kb_close_action)(lv_obj_t *);
|
||||
static void (*kb_ok_action)(lv_obj_t *);
|
||||
static lv_btnms_t kb_btnms;
|
||||
@ -74,26 +75,39 @@ static bool kb_inited;
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Open a keyboard for a text area object
|
||||
* @param ta pointer to a text area object
|
||||
* @param mode 'OR'd values of 'lv_app_kb_mode_t' enum
|
||||
* @param close a function to call when the keyboard is closed
|
||||
* @param ok a function to called when the "Ok" button is pressed
|
||||
*/
|
||||
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 *))
|
||||
{
|
||||
/*Init the style*/
|
||||
if(kb_inited == false) {
|
||||
lv_btnms_get(LV_BTNMS_DEF, &kb_btnms);
|
||||
kb_btnms.rects.opad = 4 + LV_DOWNSCALE;
|
||||
kb_btnms.rects.vpad = 3 + LV_DOWNSCALE;
|
||||
kb_btnms.rects.hpad = 3 + LV_DOWNSCALE;
|
||||
kb_btnms.rects.round = 0;
|
||||
|
||||
kb_inited = true;
|
||||
}
|
||||
|
||||
/*Close the previous keyboard*/
|
||||
if(kb_btnm != NULL) {
|
||||
lv_app_kb_close(false);
|
||||
}
|
||||
|
||||
/*Save some parameters*/
|
||||
kb_ta = ta;
|
||||
kb_mode = mode;
|
||||
kb_close_action = close;
|
||||
kb_ok_action = ok;
|
||||
kb_first = false;
|
||||
|
||||
/*Create a button matrix for the keyboard */
|
||||
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);
|
||||
@ -108,10 +122,12 @@ void lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t
|
||||
}
|
||||
lv_obj_set_style(kb_btnm, &kb_btnms);
|
||||
|
||||
kb_win = lv_app_get_win_from_obj(kb_ta);
|
||||
/*Reduce teh size of the window and align it to the top*/
|
||||
kb_win = lv_app_win_get_from_obj(kb_ta);
|
||||
lv_obj_set_height(kb_win, LV_VER_RES / 2);
|
||||
lv_obj_set_y(kb_win, 0);
|
||||
|
||||
/*If the text area is higher then the new size of the window redus its size too*/
|
||||
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);
|
||||
@ -128,6 +144,10 @@ void lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the keyboard
|
||||
* @param ok true: call the ok function, false: call the close function
|
||||
*/
|
||||
void lv_app_kb_close(bool ok)
|
||||
{
|
||||
if(kb_btnm == NULL) return;
|
||||
@ -138,6 +158,8 @@ void lv_app_kb_close(bool ok)
|
||||
if(kb_ok_action != NULL) kb_ok_action(kb_ta);
|
||||
}
|
||||
|
||||
/*Reset the modified sizes*/
|
||||
|
||||
lv_obj_set_height(kb_ta, kb_ta_ori_size);
|
||||
|
||||
lv_obj_set_size(kb_win, LV_HOR_RES, LV_VER_RES);
|
||||
@ -176,14 +198,34 @@ static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i)
|
||||
} else if(strcmp(txt, "1#") == 0) {
|
||||
lv_btnm_set_map(btnm, kb_map_spec);
|
||||
} else if(strcmp(txt, "Enter") == 0) {
|
||||
if((kb_mode & LV_APP_KB_MODE_CLR) != 0 && kb_first == false) {
|
||||
lv_ta_set_text(kb_ta, "");
|
||||
kb_first = true;
|
||||
}
|
||||
lv_ta_add_char(kb_ta, '\n');
|
||||
} else if(strcmp(txt, "Left") == 0) {
|
||||
if((kb_mode & LV_APP_KB_MODE_CLR) != 0 && kb_first == false) {
|
||||
lv_ta_set_text(kb_ta, "");
|
||||
kb_first = true;
|
||||
}
|
||||
lv_ta_cursor_left(kb_ta);
|
||||
} else if(strcmp(txt, "Right") == 0) {
|
||||
if((kb_mode & LV_APP_KB_MODE_CLR) != 0 && kb_first == false) {
|
||||
lv_ta_set_text(kb_ta, "");
|
||||
kb_first = true;
|
||||
}
|
||||
lv_ta_cursor_right(kb_ta);
|
||||
} else if(strcmp(txt, "Del") == 0) {
|
||||
if((kb_mode & LV_APP_KB_MODE_CLR) != 0 && kb_first == false) {
|
||||
lv_ta_set_text(kb_ta, "");
|
||||
kb_first = true;
|
||||
}
|
||||
lv_ta_del(kb_ta);
|
||||
} else if(strcmp(txt, "+/-") == 0) {
|
||||
if((kb_mode & LV_APP_KB_MODE_CLR) != 0 && kb_first == false) {
|
||||
lv_ta_set_text(kb_ta, "");
|
||||
kb_first = true;
|
||||
}
|
||||
uint16_t cur = lv_ta_get_cursor_pos(kb_ta);
|
||||
const char * ta_txt = lv_ta_get_txt(kb_ta);
|
||||
if(ta_txt[0] == '-') {
|
||||
@ -208,6 +250,10 @@ static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i)
|
||||
lv_app_kb_close(true);
|
||||
return LV_ACTION_RES_INV;
|
||||
} else {
|
||||
if((kb_mode & LV_APP_KB_MODE_CLR) != 0 && kb_first == false) {
|
||||
lv_ta_set_text(kb_ta, "");
|
||||
kb_first = true;
|
||||
}
|
||||
lv_ta_add_text(kb_ta, txt);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ typedef enum
|
||||
{
|
||||
LV_APP_KB_MODE_TXT = 0x01,
|
||||
LV_APP_KB_MODE_NUM = 0x02,
|
||||
LV_APP_KB_MODE_CLR = 0x04, /*Clear when the first character is pressed*/
|
||||
}lv_app_kb_mode_t;
|
||||
|
||||
/**********************
|
||||
|
@ -24,7 +24,7 @@
|
||||
/*Application specific data for an instance of this application*/
|
||||
typedef struct
|
||||
{
|
||||
const char * txt;
|
||||
|
||||
}my_app_data_t;
|
||||
|
||||
/*Application specific data a window of this application*/
|
||||
@ -50,7 +50,8 @@ static void my_sc_close(lv_app_inst_t * app);
|
||||
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win);
|
||||
static void my_win_close(lv_app_inst_t * app);
|
||||
|
||||
static void task(void);
|
||||
static lv_action_res_t ta_rel_action(lv_obj_t * ta, lv_dispi_t * dispi);
|
||||
static void kb_ok_action(lv_obj_t * ta);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -81,8 +82,6 @@ static lv_app_dsc_t my_app_dsc =
|
||||
|
||||
const lv_app_dsc_t * lv_app_example_init(void)
|
||||
{
|
||||
ptask_create(task, 200, PTASK_PRIO_MID);
|
||||
|
||||
return &my_app_dsc;
|
||||
}
|
||||
|
||||
@ -98,16 +97,12 @@ const lv_app_dsc_t * lv_app_example_init(void)
|
||||
*/
|
||||
static void my_app_run(lv_app_inst_t * app, const char * cstr)
|
||||
{
|
||||
/*Check the create string*/
|
||||
if(cstr == NULL || cstr[0] == '\0') {
|
||||
cstr = "No create\nstring";
|
||||
/*Initialize the application*/
|
||||
if(cstr != NULL && cstr[0] != '\0') {
|
||||
char buf[256];
|
||||
sprintf(buf,"%s - %s", my_app_dsc.name, cstr);
|
||||
lv_app_rename(app, buf);
|
||||
}
|
||||
|
||||
/*Initialize the application*/
|
||||
((my_app_data_t *)app->app_data)->txt = cstr; /*Save the create string*/
|
||||
char buf[256];
|
||||
sprintf(buf,"%s - %s", my_app_dsc.name, cstr);
|
||||
lv_app_rename(app, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +113,7 @@ static void my_app_run(lv_app_inst_t * app, const char * cstr)
|
||||
*/
|
||||
static void my_app_close(lv_app_inst_t * app)
|
||||
{
|
||||
|
||||
/*No dynamically allocated data in 'my_app_data'*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,12 +132,14 @@ static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
|
||||
if (sc_data->label != NULL) {
|
||||
lv_label_set_text(sc_data->label, data);
|
||||
lv_obj_align(sc_data->label , NULL,LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
}
|
||||
}
|
||||
else if(type == LV_APP_COM_TYPE_BIN) { /*data: array of 'int32_t' */
|
||||
|
||||
}
|
||||
else if(type == LV_APP_COM_TYPE_TRIG) { /*data: ignored' */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,7 +153,7 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
|
||||
my_sc_data_t * sc_data = app->sc_data;
|
||||
|
||||
sc_data->label = lv_label_create(sc, NULL);
|
||||
lv_label_set_text(sc_data->label, ((my_app_data_t *)app->app_data)->txt);
|
||||
lv_label_set_text(sc_data->label, "Empty");
|
||||
lv_obj_set_style(sc_data->label, lv_labels_get(LV_LABELS_DEF, NULL));
|
||||
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
}
|
||||
@ -167,10 +164,10 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
|
||||
*/
|
||||
static void my_sc_close(lv_app_inst_t * app)
|
||||
{
|
||||
|
||||
/*No dynamically allocated data in 'my_sc_data'*/
|
||||
}
|
||||
|
||||
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
|
||||
@ -179,31 +176,13 @@ lv_action_res_t kb_open(lv_obj_t * ta, lv_dispi_t * dispi);
|
||||
*/
|
||||
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
|
||||
{
|
||||
my_sc_data_t * win_data = app->win_data;
|
||||
|
||||
|
||||
win_data->label = lv_label_create(win, NULL);
|
||||
lv_label_set_text(win_data->label, ((my_app_data_t *)app->app_data)->txt);
|
||||
|
||||
|
||||
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, 200);
|
||||
lv_page_set_rel_action(ta, kb_open);
|
||||
lv_obj_set_free_p(ta, app);
|
||||
}
|
||||
|
||||
void kb_ok(lv_obj_t * ta) {
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(ta);
|
||||
const char * txt = lv_ta_get_txt(ta);
|
||||
lv_app_com_send(app, LV_APP_COM_TYPE_STR, txt, strlen(txt) + 1);
|
||||
}
|
||||
|
||||
lv_action_res_t kb_open(lv_obj_t * ta, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT, NULL, kb_ok);
|
||||
return LV_ACTION_RES_OK;
|
||||
lv_obj_set_pos_us(ta, 0, 0);
|
||||
lv_obj_set_free_p(ta, app);
|
||||
lv_page_set_rel_action(ta, ta_rel_action);
|
||||
lv_ta_set_text(ta, "Write a text to send to the other applications");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,39 +194,31 @@ static void my_win_close(lv_app_inst_t * app)
|
||||
|
||||
}
|
||||
|
||||
/*--------------------
|
||||
* OTHER FUNCTIONS
|
||||
---------------------*/
|
||||
|
||||
static void task(void)
|
||||
/**
|
||||
* Called when the text area on the window is released to open the app. keyboard
|
||||
* @param ta pointer to the text area on the window
|
||||
* @param dispi pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK because the text area is not deleted
|
||||
*/
|
||||
static lv_action_res_t ta_rel_action(lv_obj_t * ta, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_CLR, NULL, kb_ok_action);
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
return;
|
||||
dm_defrag();
|
||||
|
||||
dm_mon_t mon;
|
||||
dm_monitor(&mon);
|
||||
|
||||
lv_app_inst_t * app;
|
||||
app = lv_app_get_next_app(NULL, &my_app_dsc);
|
||||
|
||||
while(app != NULL) {
|
||||
char buf[256];
|
||||
sprintf(buf, "Mem. total: %d\nMem. free: %d (%d)\nFrag: %d%%",
|
||||
DM_MEM_SIZE, mon.size_free, mon.size_free * 100 / DM_MEM_SIZE, mon.pct_frag);
|
||||
|
||||
if(app->sc_data != NULL) {
|
||||
my_sc_data_t * sc_data = app->sc_data;
|
||||
lv_label_set_text(sc_data->label, buf);
|
||||
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
}
|
||||
|
||||
if(app->win_data != NULL) {
|
||||
my_sc_data_t * win_data = app->win_data;
|
||||
lv_label_set_text(win_data->label, buf);
|
||||
// lv_obj_align(win_data->label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||
}
|
||||
app = lv_app_get_next_app(app, &my_app_dsc);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the "Ok" button is pressed on the app. keyboard
|
||||
* @param ta pointer to the text area assigned to the app. kexboard
|
||||
*/
|
||||
static void kb_ok_action(lv_obj_t * ta)
|
||||
{
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(ta);
|
||||
const char * txt = lv_ta_get_txt(ta);
|
||||
lv_app_com_send(app, LV_APP_COM_TYPE_STR, txt, strlen(txt) + 1);
|
||||
}
|
||||
|
||||
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
|
||||
|
@ -456,13 +456,6 @@ static void lv_win_realign(lv_obj_t * win)
|
||||
lv_obj_set_height(ext->ctrl_holder, style->ctrl_btn_h + 2 * style->ctrl_holder.vpad * 2);
|
||||
lv_obj_set_width(ext->header, lv_obj_get_width(win));
|
||||
|
||||
if(style->header_on_content == 0) {
|
||||
lv_obj_set_size(ext->content, lv_obj_get_width(win), lv_obj_get_height(win) - lv_obj_get_height(ext->header));
|
||||
}
|
||||
else {
|
||||
lv_obj_set_size(ext->content, lv_obj_get_width(win), lv_obj_get_height(win));
|
||||
}
|
||||
|
||||
/*Align the higher object first to make the correct header size first*/
|
||||
if(lv_obj_get_height(ext->title) > lv_obj_get_height(ext->ctrl_holder)) {
|
||||
lv_obj_align(ext->title, NULL, LV_ALIGN_IN_LEFT_MID, style->header.hpad, 0);
|
||||
@ -475,8 +468,10 @@ static void lv_win_realign(lv_obj_t * win)
|
||||
lv_obj_set_pos_us(ext->header, 0, 0);
|
||||
|
||||
if(style->header_on_content == 0) {
|
||||
lv_obj_set_size(ext->content, lv_obj_get_width(win), lv_obj_get_height(win) - lv_obj_get_height(ext->header));
|
||||
lv_obj_align_us(ext->content, ext->header, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0);
|
||||
} else {
|
||||
lv_obj_set_size(ext->content, lv_obj_get_width(win), lv_obj_get_height(win));
|
||||
lv_obj_set_pos(ext->content, 0, 0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user