1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_app/lv_app.c

804 lines
24 KiB
C
Raw Normal View History

/**
* @file lv_app.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app.h"
#if LV_APP_ENABLE != 0
2016-12-21 15:34:01 +01:00
#include "lv_app_sup.h"
#include "lvgl/lv_misc/anim.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2016-12-17 10:50:28 +01:00
/*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_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);
2016-12-17 10:50:28 +01:00
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);
2016-12-21 15:34:01 +01:00
#if LV_APP_ANIM_LEVEL != 0 && 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);
2016-12-20 15:02:23 +01:00
#endif
2016-12-17 10:50:28 +01:00
static void lv_app_init_icons(void);
2016-12-17 10:50:28 +01:00
static void lv_app_init_style(void);
/**********************
* STATIC VARIABLES
**********************/
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*/
2016-12-17 10:50:28 +01:00
static lv_obj_t * app_scr;
static lv_obj_t * menuh; /*Holder of timg_bubbleshe menu on the top*/
2016-12-17 10:50:28 +01:00
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 * clock; /*Clock on the menu bar (right top)*/
2016-12-17 10:50:28 +01:00
static lv_obj_t * app_list;
static lv_obj_t * sc_page;
2016-12-17 10:50:28 +01:00
static lv_app_style_t app_style;
#include "lvgl/lv_objx/lv_img.h"
/*Declare icons*/
LV_IMG_DECLARE(img_add);
LV_IMG_DECLARE(img_battery_empty);
LV_IMG_DECLARE(img_battery_full);
LV_IMG_DECLARE(img_battery_half);
LV_IMG_DECLARE(img_bubble);
LV_IMG_DECLARE(img_calendar);
LV_IMG_DECLARE(img_clock);
LV_IMG_DECLARE(img_close);
LV_IMG_DECLARE(img_down);
LV_IMG_DECLARE(img_driver);
LV_IMG_DECLARE(img_eject);
LV_IMG_DECLARE(img_folder);
LV_IMG_DECLARE(img_image);
LV_IMG_DECLARE(img_left);
LV_IMG_DECLARE(img_music);
LV_IMG_DECLARE(img_ok);
LV_IMG_DECLARE(img_play);
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_up);
LV_IMG_DECLARE(img_user);
LV_IMG_DECLARE(img_video);
LV_IMG_DECLARE(img_volume);
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application system
*/
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();
2016-12-17 10:50:28 +01:00
lv_app_init_style();
/*Create the desktop elements*/
/*Shortcut area*/
sc_page = lv_page_create(lv_scr_act(), NULL);
2016-12-17 10:50:28 +01:00
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);
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);
2016-12-17 10:50:28 +01:00
/*Menu on the top*/
menuh = lv_rect_create(lv_scr_act(), NULL);
lv_obj_set_size(menuh, LV_HOR_RES, app_style.menu_h);
lv_obj_set_pos(menuh, 0, 0);
lv_obj_set_style(menuh, &app_style.menu_style);
app_btn = lv_btn_create(menuh, NULL);
lv_obj_set_style(app_btn, &app_style.menu_btn_style);
lv_obj_set_height(app_btn, app_style.menu_h);
lv_rect_set_fit(app_btn, true, false);
lv_btn_set_rel_action(app_btn, lv_app_menu_rel_action);
lv_obj_t * app_label = lv_label_create(app_btn, NULL);
lv_obj_set_style(app_label, &app_style.menu_btn_label_style);
lv_label_set_text(app_label, "Apps");
lv_obj_set_pos(app_btn, 0, 0);
sys_apph = lv_rect_create(menuh, NULL);
lv_rect_set_layout(sys_apph, LV_RECT_LAYOUT_ROW_M);
lv_rect_set_fit(sys_apph, true, false);
lv_obj_set_height(sys_apph, app_style.menu_h);
lv_obj_set_style(sys_apph, lv_rects_get(LV_RECTS_TRANSP, NULL));
clock = lv_label_create(sys_apph, NULL);
lv_obj_set_style(clock, &app_style.menu_btn_label_style);
lv_label_set_text(clock, "20:17");
lv_obj_align(sys_apph, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0);
2016-12-17 10:50:28 +01:00
lv_app_refr_style();
/*Initialize all application descriptors*/
const lv_app_dsc_t ** dsc;
2016-12-17 10:50:28 +01:00
#if USE_LV_APP_EXAMPLE != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_example_init();
#endif
}
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param cstr a Create STRing which can give initial parameters to the application (NULL or "" if unused)
* @return pointer to the opened application or NULL if any error occurred
*/
lv_app_inst_t * lv_app_run(const lv_app_dsc_t * app_dsc, const char * cstr)
{
/*Add a new application and initialize it*/
lv_app_inst_t * app;
app = ll_ins_head(&app_inst_ll);
app->dsc = app_dsc;
app->app_data = dm_alloc(app_dsc->app_data_size);
app->name = NULL;
lv_app_rename(app, app_dsc->name);
/*Call the application specific run function*/
app_dsc->app_run(app, cstr);
return app;
}
/**
* Close a running application. Close the Window and the Shortcut too if opened.
* @param app pointer to an application
*/
void lv_app_close(lv_app_inst_t * app)
{
lv_app_win_close(app);
lv_app_sc_close(app);
app->dsc->app_close(app);
dm_free(app->app_data);
dm_free(app->name);
}
/**
* Send data to other applications
* @param app_send pointer to the application which is sending the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param len length of 'data' in bytes
* @return number application which were received the message
*/
uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , void * data, uint32_t len)
{
return 0;
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @return pointer to the shortcut
*/
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_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);
lv_obj_set_size(app->sc, LV_APP_SC_WIDTH, LV_APP_SC_HEIGHT);
lv_rect_set_layout(app->sc, LV_RECT_LAYOUT_OFF);
lv_btn_set_rel_action(app->sc, lv_app_sc_rel_action);
2016-12-17 10:50:28 +01:00
lv_btn_set_pr_action(app->sc, lv_app_sc_pr_action);
lv_page_glue_obj(app->sc, true);
app->sc_data = dm_alloc(app->dsc->sc_data_size);
app->dsc->sc_open(app, app->sc);
app->sc_title = lv_label_create(app->sc, NULL);
lv_obj_set_style(app->sc_title, &app_style.sc_title_style);
//lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_SCROLL);
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);
/*Restore position of the scrollable part of the page*/
lv_obj_set_y(lv_page_get_scrable(sc_page), scrl_y);
2016-12-20 15:02:23 +01:00
#if LV_APP_ANIM_LEVEL != 0
lv_page_focus(sc_page, app->sc, true);
2016-12-20 15:02:23 +01:00
#else
lv_page_focus(sc_page, app->sc, false);
#endif
return app->sc;
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
void lv_app_sc_close(lv_app_inst_t * app)
{
if(app->sc == NULL) return;
lv_obj_del(app->sc);
app->sc = NULL;
app->sc_title = NULL;
dm_free(app->sc_data);
app->sc_data = NULL;
}
/**
* Open the application in a window
* @param app pointer to an application
* @return pointer to the shortcut
*/
lv_obj_t * lv_app_win_open(lv_app_inst_t * app)
{
2016-12-17 10:50:28 +01:00
/*Close the app list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
app->win = lv_win_create(lv_scr_act(), NULL);
lv_obj_set_free_p(app->win, app);
2016-12-17 10:50:28 +01:00
lv_obj_set_style(app->win, &app_style.win_style);
2016-12-20 15:02:23 +01:00
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);
2016-12-17 10:50:28 +01:00
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);
app->win_data = dm_alloc(app->dsc->win_data_size);
app->dsc->win_open(app, app->win);
return app->win;
}
/**
* Close the window of an application
* @param app pointer to an application
*/
void lv_app_win_close(lv_app_inst_t * app)
{
if(app->win == NULL) return;
2016-12-20 15:02:23 +01:00
lv_app_kb_close(false);
lv_obj_del(app->win);
app->win = NULL;
dm_free(app->win_data);
app->win_data = NULL;
}
2016-12-17 10:50:28 +01:00
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(lv_page_get_scrable(sc_page),
LV_HOR_RES - 2 * (app_style.sc_page_style.bg_rects.hpad));
2016-12-17 10:50:28 +01:00
}
void lv_app_rename(lv_app_inst_t * app, const char * name)
{
dm_free(app->name);
app->name = dm_alloc(strlen(name) + 1);
strcpy(app->name, name);
if(app->sc != NULL) {
lv_label_set_text(app->sc_title, app->name);
}
}
2016-12-17 10:50:28 +01:00
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;
}
2016-12-17 10:50:28 +01:00
const lv_app_dsc_t * lv_app_get_dsc(const char * name)
{
const lv_app_dsc_t ** dsc;
LL_READ(app_dsc_ll, dsc) {
if(strcmp((*dsc)->name, name) == 0) {
return *dsc;
}
}
return NULL;
}
/**
* 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 * next;
while(1) {
if(prev == NULL) next = ll_get_head(&app_inst_ll);
else next = ll_get_next(&app_inst_ll, prev);
if(next == NULL) break;
if(next->dsc == dsc || dsc == NULL) return next;
};
return NULL;
}
2016-12-17 10:50:28 +01:00
lv_app_style_t * lv_app_get_style(void)
{
return &app_style;
}
/**********************
* STATIC FUNCTIONS
**********************/
2016-12-17 10:50:28 +01:00
static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * dispi)
{
2016-12-17 10:50:28 +01:00
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
/*Create the app. list*/
else {
app_list = lv_list_create(lv_scr_act(), NULL);
lv_obj_set_hidden(app_list, true);
2016-12-17 10:50:28 +01:00
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);
lv_obj_set_y(app_list, app_style.menu_h);
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);
}
lv_obj_set_hidden(app_list, false);
2016-12-17 10:50:28 +01:00
}
return LV_ACTION_RES_OK;
}
2016-12-17 10:50:28 +01:00
static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_dispi_t * dispi)
{
lv_app_dsc_t * dsc = lv_obj_get_free_p(app_elem_btn);
/*Close the app list*/
lv_obj_del(app_list);
app_list = NULL;
2016-12-17 10:50:28 +01:00
lv_app_inst_t * app = lv_app_run(dsc, "");
lv_app_sc_open(app);
2016-12-20 15:02:23 +01:00
#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
2016-12-17 10:50:28 +01:00
return LV_ACTION_RES_INV;
}
static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_dispi_t * dispi)
2016-12-17 10:50:28 +01:00
{
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
return LV_ACTION_RES_OK;
}
static lv_action_res_t lv_app_sc_page_pr_action(lv_obj_t * sc, lv_dispi_t * dispi)
2016-12-17 10:50:28 +01:00
{
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
return LV_ACTION_RES_OK;
}
static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi)
{
2016-12-20 15:02:23 +01:00
#if LV_APP_ANIM_LEVEL != 0
lv_page_focus(sc_page, sc, true);
2016-12-20 15:02:23 +01:00
#else
lv_page_focus(sc_page, sc, false);
#endif
2016-12-17 10:50:28 +01:00
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
/*Else open the window of the shortcut*/
else {
lv_app_inst_t * app = lv_obj_get_free_p(sc);
lv_app_win_open(app);
2016-12-17 22:09:25 +01:00
2016-12-20 15:02:23 +01:00
/*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);
}
2016-12-17 22:09:25 +01:00
anim_t a;
a.act_time = 0;
2016-12-20 15:02:23 +01:00
a.time = LV_APP_ANIM_WIN;
2016-12-17 22:09:25 +01:00
a.end_cb = NULL;
a.playback = 0;
a.repeat = 0;
a.var = app->win;
a.path = anim_get_path(ANIM_PATH_LIN);
a.start = lv_obj_get_width(app->sc);
a.end = LV_HOR_RES;
a.fp = (anim_fp_t) lv_obj_set_width;
anim_create(&a);
a.start = lv_obj_get_height(app->sc);
a.end = LV_VER_RES;
a.fp = (anim_fp_t) lv_obj_set_height;
anim_create(&a);
a.start = cords.x1;
a.end = 0;
a.fp = (anim_fp_t) lv_obj_set_x;
anim_create(&a);
a.start = cords.y1;
a.end = 0;
a.fp = (anim_fp_t) lv_obj_set_y;
anim_create(&a);
a.start = OPA_TRANSP;
a.end = OPA_COVER;
a.fp = (anim_fp_t) lv_obj_set_opar;
anim_create(&a);
2016-12-20 15:02:23 +01:00
#endif /*LV_APP_ANIM_LEVEL == 2*/
#endif /*LLV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0*/
2016-12-17 10:50:28 +01:00
}
return LV_ACTION_RES_OK;
}
static lv_action_res_t lv_app_sc_pr_action(lv_obj_t * sc, lv_dispi_t * dispi)
{
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
return LV_ACTION_RES_OK;
}
static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t * dispi)
{
lv_obj_t * win = lv_win_get_from_ctrl_btn(close_btn);
lv_app_inst_t * app = lv_obj_get_free_p(win);
2016-12-21 15:34:01 +01:00
lv_app_kb_close(false);
2016-12-20 15:02:23 +01:00
#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);
2016-12-20 15:02:23 +01:00
#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;
2016-12-20 15:02:23 +01:00
#endif /*LV_APP_ANIM_WIN*/
return LV_ACTION_RES_OK;
}
static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_btn, lv_dispi_t * dispi)
{
lv_obj_t * win = lv_win_get_from_ctrl_btn(close_btn);
lv_app_inst_t * app = lv_obj_get_free_p(win);
2016-12-21 15:34:01 +01:00
lv_app_kb_close(false);
2016-12-17 22:09:25 +01:00
/*Make an animation on window open*/
2016-12-20 15:02:23 +01:00
#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);
}
2016-12-17 22:09:25 +01:00
2016-12-20 15:02:23 +01:00
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_width(app->sc);
a.start = LV_HOR_RES;
a.fp = (anim_fp_t) lv_obj_set_width;
anim_create(&a);
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 = 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);
2016-12-17 10:50:28 +01:00
return LV_ACTION_RES_INV;
#endif
return LV_ACTION_RES_OK;
}
2016-12-21 15:34:01 +01:00
#if LV_APP_ANIM_LEVEL != 0 && LV_APP_ANIM_WIN != 0
static void lv_app_win_close_anim_cb(lv_obj_t * app_win)
{
lv_app_inst_t * app = lv_obj_get_free_p(app_win);
lv_app_close(app);
}
static void lv_app_win_minim_anim_cb(lv_obj_t * app_win)
{
lv_app_inst_t * app = lv_obj_get_free_p(app_win);
lv_app_win_close(app);
}
2016-12-21 15:34:01 +01:00
#endif
static void lv_app_init_icons(void)
{
lv_img_create_file("icon_add", img_add);
lv_img_create_file("icon_battery_empty", img_battery_empty);
lv_img_create_file("icon_battery_full", img_battery_full);
lv_img_create_file("icon_battery_half", img_battery_half);
lv_img_create_file("icon_bubble", img_bubble);
lv_img_create_file("icon_calendar", img_calendar);
lv_img_create_file("icon_clock", img_clock);
lv_img_create_file("icon_close", img_close);
lv_img_create_file("icon_down", img_down);
lv_img_create_file("icon_driver", img_driver);
lv_img_create_file("icon_eject", img_eject);
lv_img_create_file("icon_folder", img_folder);
lv_img_create_file("icon_image", img_image);
lv_img_create_file("icon_left", img_left);
lv_img_create_file("icon_music", img_music);
lv_img_create_file("icon_ok", img_ok);
lv_img_create_file("icon_play", img_play);
lv_img_create_file("icon_right", img_right);
lv_img_create_file("icon_settings", img_settings);
lv_img_create_file("icon_shut_down", img_shut_down);
lv_img_create_file("icon_star", img_star);
lv_img_create_file("icon_up", img_up);
lv_img_create_file("icon_user", img_user);
lv_img_create_file("icon_video", img_video);
lv_img_create_file("icon_volume", img_volume);
2016-12-17 10:50:28 +01:00
}
static void lv_app_init_style(void)
{
/*Coordinates*/
app_style.menu_h = 40 * LV_DOWNSCALE;
app_style.app_list_w = LV_HOR_RES / 3;
app_style.app_list_h = (2 * LV_VER_RES) / 3;
app_style.sc_title_margin = 2 * LV_DOWNSCALE;
2016-12-17 10:50:28 +01:00
/*Opacity*/
app_style.menu_opa = OPA_80;
2016-12-17 10:50:28 +01:00
app_style.menu_btn_opa = OPA_50;
app_style.sc_opa = OPA_70;
/*Menu style*/
lv_rects_get(LV_RECTS_DEF,&app_style.menu_style);
app_style.menu_style.objs.color = COLOR_BLACK;
app_style.menu_style.gcolor = COLOR_BLACK;
app_style.menu_style.round = 0;
app_style.menu_style.bwidth = 0;
app_style.menu_style.light = 0;
lv_btns_get(LV_BTNS_DEF,&app_style.menu_btn_style);
memcpy(&app_style.menu_btn_style.rects, &app_style.menu_style, sizeof(lv_rects_t));
app_style.menu_btn_style.flags[LV_BTN_STATE_REL].light_en = 0;
app_style.menu_btn_style.flags[LV_BTN_STATE_PR].light_en = 0;
app_style.menu_btn_style.flags[LV_BTN_STATE_REL].empty = 1;
app_style.menu_btn_style.flags[LV_BTN_STATE_PR].empty = 0;
app_style.menu_btn_style.mcolor[LV_BTN_STATE_REL] = COLOR_BLACK;
app_style.menu_btn_style.gcolor[LV_BTN_STATE_REL] = COLOR_BLACK;
app_style.menu_btn_style.mcolor[LV_BTN_STATE_PR] = COLOR_GRAY;
app_style.menu_btn_style.gcolor[LV_BTN_STATE_PR] = COLOR_GRAY;
lv_labels_get(LV_LABELS_BTN,&app_style.menu_btn_label_style);
app_style.menu_btn_label_style.font = LV_APP_FONT_LARGE;
app_style.menu_btn_label_style.objs.color = COLOR_MAKE(0xd0, 0xe0, 0xf0);
2016-12-17 10:50:28 +01:00
lv_imgs_get(LV_IMGS_DEF,&app_style.menu_btn_img_style);
app_style.menu_btn_img_style.objs.color = COLOR_WHITE;
app_style.menu_btn_img_style.recolor_opa = OPA_90;
2016-12-17 10:50:28 +01:00
/*App list styles*/
lv_lists_get(LV_LISTS_DEF,&app_style.app_list_style);
memcpy(&app_style.app_list_style.liste_btns, &app_style.menu_btn_style, sizeof(lv_btns_t));
memcpy(&app_style.app_list_style.bg_pages.bg_rects, &app_style.menu_style, sizeof(lv_rects_t));
memcpy(&app_style.app_list_style.liste_labels, &app_style.menu_btn_label_style, sizeof(lv_labels_t));
app_style.app_list_style.bg_pages.bg_rects.vpad = 0;
app_style.app_list_style.bg_pages.bg_rects.hpad = 0;
app_style.app_list_style.bg_pages.bg_rects.opad = 0;
app_style.app_list_style.bg_pages.scrable_rects.objs.transp = 1;
app_style.app_list_style.bg_pages.scrable_rects.vpad = 0;
app_style.app_list_style.bg_pages.scrable_rects.hpad = 0;
app_style.app_list_style.bg_pages.scrable_rects.opad = 0;
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;
app_style.app_list_style.bg_pages.sb_width = 8 * LV_DOWNSCALE;
2016-12-17 10:50:28 +01:00
/*Shortcut page styles*/
2016-12-17 10:50:28 +01:00
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 = app_style.menu_h;
2016-12-17 10:50:28 +01:00
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.hpad = 20 * LV_DOWNSCALE;
app_style.sc_page_style.scrable_rects.vpad = 20 * LV_DOWNSCALE;
app_style.sc_page_style.scrable_rects.opad = 20 * LV_DOWNSCALE;
2016-12-17 10:50:28 +01:00
/*Shortcut styles*/
lv_btns_get(LV_BTNS_DEF,&app_style.sc_style);
app_style.sc_style.mcolor[LV_BTN_STATE_REL] = COLOR_WHITE;
app_style.sc_style.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x20, 0x30, 0x40);
app_style.sc_style.bcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x40, 0x60, 0x80);
app_style.sc_style.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xB0, 0xD0, 0xF0);
app_style.sc_style.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x00, 0x00, 0x00);
app_style.sc_style.bcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xB0, 0xD0, 0xF0);
app_style.sc_style.rects.bopa = 70;
app_style.sc_style.rects.bwidth = 1 * LV_DOWNSCALE;
2016-12-17 10:50:28 +01:00
lv_labels_get(LV_LABELS_DEF,&app_style.sc_title_style);
app_style.sc_title_style.font = LV_APP_FONT_SMALL;
app_style.sc_title_style.objs.color = COLOR_MAKE(0x20, 0x30, 0x40);
app_style.sc_title_style.mid = 1;
2016-12-17 10:50:28 +01:00
/*Window styles*/
lv_wins_get(LV_WINS_DEF,&app_style.win_style);
memcpy(&app_style.win_style.header, &app_style.menu_style, sizeof(lv_rects_t));
memcpy(&app_style.win_style.title, &app_style.menu_btn_label_style, sizeof(lv_labels_t));
memcpy(&app_style.win_style.ctrl_btn, &app_style.menu_btn_style, sizeof(lv_btns_t));
memcpy(&app_style.win_style.ctrl_img, &app_style.menu_btn_img_style, sizeof(lv_imgs_t));
2016-12-17 10:50:28 +01:00
app_style.win_style.header_on_content = 1;
app_style.win_style.header_opa = app_style.menu_opa;
app_style.win_style.ctrl_btn_opa = app_style.menu_btn_opa;
app_style.win_style.header.vpad = 5 * LV_DOWNSCALE;
app_style.win_style.header.hpad = 5 * LV_DOWNSCALE;
app_style.win_style.header.opad = 5 * LV_DOWNSCALE;
2016-12-20 15:02:23 +01:00
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.hpad = 5 * LV_DOWNSCALE;
app_style.win_style.content.scrable_rects.objs.transp = 1;
}
#endif /*LV_APP_ENABLE != 0*/