From 4c14c4c762e81b81f5a145508060187a8957e56d Mon Sep 17 00:00:00 2001 From: Gabor Date: Mon, 10 Apr 2017 11:33:38 +0200 Subject: [PATCH] BIG UPDTAE: Style renames in the whole library --- lv_app/lv_app.c | 396 ++++++++++++++--------------- lv_app/lv_app.h | 24 +- lv_app/lv_app_util/lv_app_fsel.c | 2 +- lv_app/lv_app_util/lv_app_kb.c | 31 +-- lv_app/lv_app_util/lv_app_notice.c | 7 +- lv_appx/lv_app_files.c | 10 +- lv_appx/lv_app_sysmon.c | 19 +- lv_appx/lv_app_terminal.c | 27 +- lv_conf_temp.h | 1 + lv_draw/lv_draw.c | 223 ++++++++-------- lv_draw/lv_draw.h | 17 +- lv_obj/lv_obj.c | 102 +++----- lv_obj/lv_obj.h | 29 +-- lv_obj/lv_refr.c | 7 +- lv_objx/lv_btn.c | 234 ++++++----------- lv_objx/lv_btn.h | 22 +- lv_objx/lv_btnm.c | 53 ++-- lv_objx/lv_btnm.h | 8 +- lv_objx/lv_cb.c | 55 +--- lv_objx/lv_chart.c | 81 +++--- lv_objx/lv_chart.h | 26 +- lv_objx/lv_ddlist.c | 68 +++-- lv_objx/lv_ddlist.h | 6 +- lv_objx/lv_gauge.c | 4 +- lv_objx/lv_img.c | 20 +- lv_objx/lv_img.h | 4 +- lv_objx/lv_label.c | 72 ++---- lv_objx/lv_label.h | 13 +- lv_objx/lv_led.c | 2 +- lv_objx/lv_line.c | 35 +-- lv_objx/lv_line.h | 6 +- lv_objx/lv_list.c | 149 +++-------- lv_objx/lv_list.h | 12 +- lv_objx/lv_mbox.c | 56 ++-- lv_objx/lv_mbox.h | 2 +- lv_objx/lv_page.c | 136 +++++----- lv_objx/lv_page.h | 16 +- lv_objx/lv_pb.c | 26 +- lv_objx/lv_rect.c | 153 ++++++----- lv_objx/lv_rect.h | 17 +- lv_objx/lv_ta.c | 58 ++--- lv_objx/lv_ta.h | 6 +- lv_objx/lv_win.c | 67 ++--- lv_objx/lv_win.h | 4 +- 44 files changed, 977 insertions(+), 1329 deletions(-) diff --git a/lv_app/lv_app.c b/lv_app/lv_app.c index 0a12f1e17..65617572b 100644 --- a/lv_app/lv_app.c +++ b/lv_app/lv_app.c @@ -40,12 +40,16 @@ typedef struct { * STATIC PROTOTYPES **********************/ +#if LV_APP_DESKTOP != 0 static void lv_app_init_desktop(void); +#endif /*Actions*/ +#if LV_APP_DESKTOP != 0 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); +#endif 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_lpr_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); @@ -70,14 +74,18 @@ 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 ll_dsc_t app_con_ll; /*Store the communication connection between the apps*/ static lv_obj_t * app_scr; /*Screen of the applications*/ -static lv_obj_t * menuh; /*Holder of timg_bubbleshe menu on the top*/ + +#if LV_APP_DESKTOP != 0 +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; /*A list which is opened on 'app_btn' release*/ static lv_obj_t * sc_page; /*A page for the shortcuts */ +#endif + +static lv_obj_t * app_list; /*A list which is opened on 'app_btn' release*/ static lv_app_inst_t * con_send; /*The sender application in connection mode. Not NLL means connection mode is active*/ static lv_app_style_t app_style; /*Styles for application related things*/ -static lv_wins_t wins_anim; /*Used when the window is animated. (Do not use scrollbar during the anim.)*/ +static lv_wins_t wins_anim; /*Used when the window is animated. (Do not use scrollbar during the anim.)*/ /*Declare icons*/ #if USE_IMG_CLOSE != 0 LV_IMG_DECLARE(img_close); @@ -142,8 +150,10 @@ void lv_app_init(void) lv_app_init_icons(); lv_app_init_style(); +#if LV_APP_DESKTOP != 0 /*Create the desktop elements*/ lv_app_init_desktop(); +#endif /*Init. the utilities*/ lv_app_kb_init(); @@ -236,19 +246,21 @@ void lv_app_close(lv_app_inst_t * app) */ 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_scrl(sc_page)); /*Create a basic shortcut*/ +#if LV_APP_DESKTOP != 0 app->sc = lv_btn_create(sc_page, NULL); + lv_page_glue_obj(app->sc, true); +#else + app->sc = lv_btn_create(app_scr, NULL); +#endif 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_style(app->sc, &app_style.sc_bg); 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); lv_btn_set_lpr_action(app->sc, lv_app_sc_lpr_action); - lv_page_glue_obj(app->sc, true); + 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); @@ -268,13 +280,12 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app) app->sc_data = dm_alloc(app->dsc->sc_data_size); app->dsc->sc_open(app, app->sc); - /* Restore position of the scrollable part of the page because - * it moved when the shortcut is created*/ - lv_obj_set_y(lv_page_get_scrl(sc_page), scrl_y); +#if LV_APP_DESKTOP != 0 #if LV_APP_EFFECT_ANIM == 0 lv_page_focus(sc_page, app->sc, false); #else lv_page_focus(sc_page, app->sc, true); +#endif #endif return app->sc; @@ -310,11 +321,8 @@ 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_set_style(app->win, &app_style.win); lv_win_set_title(app->win, app->dsc->name); - lv_obj_t * win_content = lv_page_get_scrl(app->win); - lv_rect_set_fit(win_content, false, true); - lv_obj_set_width(win_content, LV_HOR_RES - 2 * app_style.win_style.pages.bg_rects.hpad); if(app->dsc->conf_open != NULL) { lv_win_add_ctrl_btn(app->win, "U:/icon_settings", lv_app_win_conf_action); @@ -523,17 +531,13 @@ void lv_app_style_refr(void) { lv_style_refr_all(NULL); - lv_obj_set_opa(menuh, app_style.menu_opa); - lv_obj_set_opa(app_btn, app_style.menu_btn_opa); +#if LV_APP_DESKTOP != 0 + lv_obj_set_width(lv_page_get_scrl(sc_page), LV_HOR_RES - 2 * (app_style.sc_page.bg.hpad)); +#endif - lv_obj_set_width(lv_page_get_scrl(sc_page), - LV_HOR_RES - 2 * (app_style.sc_page_style.bg_rects.hpad)); + app_style.win_useful_w = LV_HOR_RES - 2 * (app_style.win.page.bg.hpad + app_style.win.page.scrl.hpad); - app_style.win_useful_w = LV_HOR_RES - 2 * (app_style.win_style.pages.bg_rects.hpad + - app_style.win_style.pages.scrl_rects.hpad); - - app_style.win_useful_h = LV_VER_RES - 2 * (app_style.win_style.pages.bg_rects.vpad + - app_style.win_style.pages.scrl_rects.vpad); + app_style.win_useful_h = LV_VER_RES - 2 * (app_style.win.page.bg.vpad + app_style.win.page.scrl.vpad); } @@ -550,14 +554,15 @@ lv_app_style_t * lv_app_style_get(void) * STATIC FUNCTIONS **********************/ +#if LV_APP_DESKTOP != 0 /** - * Create the object on the desktop + * Create a desktop-like environment */ static void lv_app_init_desktop(void) { /*Shortcut area*/ sc_page = lv_page_create(lv_scr_act(), NULL); - lv_obj_set_style(sc_page, &app_style.sc_page_style); + lv_obj_set_style(sc_page, &app_style.sc_page); 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_scrl(sc_page), false, true); @@ -568,15 +573,15 @@ static void lv_app_init_desktop(void) 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); + lv_obj_set_style(menuh, &app_style.menu_bg); app_btn = lv_btn_create(menuh, NULL); - lv_obj_set_style(app_btn, &app_style.menu_btn_style); + lv_obj_set_style(app_btn, &app_style.menu_btn); 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_obj_set_style(app_label, &app_style.menu_btn_label); lv_label_set_text(app_label, "Apps"); lv_obj_set_pos(app_btn, 0, 0); @@ -585,19 +590,21 @@ static void lv_app_init_desktop(void) 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_obj_t * clock = lv_label_create(sys_apph, NULL); + lv_obj_set_style(clock, &app_style.menu_btn_label); lv_label_set_text(clock, "20:17"); -*/ + lv_obj_align(sys_apph, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); lv_app_style_refr(); } +#endif /*----------------------- APP. MENU ACTIONS ------------------------*/ +#if LV_APP_DESKTOP != 0 /** * CAlled when the "Apps" button is released to open or close the app. list * @param app_btn pointer to the "Apps" button @@ -614,8 +621,7 @@ 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_style(app_list, &app_style.app_list_style); - lv_obj_set_opar(app_list, app_style.menu_opa); + lv_obj_set_style(app_list, &app_style.app_list); 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); @@ -625,7 +631,6 @@ static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * d 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); } } } @@ -649,28 +654,15 @@ 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, NULL); lv_app_sc_open(app); -#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; - a.end_cb = NULL; - a.playback = 0; - a.repeat = 0; - a.var = app->sc; - a.path = anim_get_path(ANIM_PATH_LIN); - a.end = app_style.sc_opa; - a.start = OPA_TRANSP; - a.fp = (anim_fp_t) lv_obj_set_opa; - anim_create(&a); -#endif - return LV_ACTION_RES_INV; } +#endif /*----------------------- SHORTCUT ACTIONS ------------------------*/ +#if LV_APP_DESKTOP != 0 /** * Called when the shortcut page is released to hide the app list and/or * go back from connection mode @@ -689,13 +681,14 @@ static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * page, lv_dispi_t * d if(con_send != NULL) { lv_app_inst_t * i; LL_READ(app_inst_ll, i) { - if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_style); + if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_bg); } con_send = NULL; } return LV_ACTION_RES_OK; } +#endif /** * Called when a shortcut is released to open its window (or close app list if opened) (in normal mode) or @@ -709,10 +702,12 @@ static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) /*Normal mode*/ if(con_send == NULL) { +#if LV_APP_DESKTOP != 0 #if LV_APP_EFFECT_ANIM == 0 lv_page_focus(sc_page, sc, false); #else lv_page_focus(sc_page, sc, true); +#endif #endif /*Close the list if opened*/ if(app_list != NULL) { @@ -733,11 +728,11 @@ static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) if(app != con_send) { /*Do nothing with the sender*/ lv_btns_t * style = lv_obj_get_style(sc); /*Add connection to this application*/ - if(style == &app_style.sc_style) { - lv_obj_set_style(sc, &app_style.sc_rec_style); + if(style == &app_style.sc_bg) { + lv_obj_set_style(sc, &app_style.sc_rec_bg); lv_app_con_set(con_send, app); } else { /*Remove the applications connection*/ - lv_obj_set_style(sc, &app_style.sc_style); + lv_obj_set_style(sc, &app_style.sc_bg); lv_app_con_del(con_send, app); } } @@ -759,23 +754,23 @@ static lv_action_res_t lv_app_sc_lpr_action(lv_obj_t * sc, lv_dispi_t * dispi) if(con_send == app_send) { lv_app_inst_t * i; LL_READ(app_inst_ll, i) { - if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_style); + if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_bg); } con_send = NULL; } else { if(con_send != NULL) { lv_app_inst_t * i; LL_READ(app_inst_ll, i) { - if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_style); + if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_bg); } } con_send = app_send; - lv_obj_set_style(sc, &app_style.sc_send_style); + lv_obj_set_style(sc, &app_style.sc_send_bg); lv_app_inst_t * i; LL_READ(app_inst_ll, i) { if(i->sc != NULL && lv_app_con_check(con_send, i) != false) { - lv_obj_set_style(i->sc, &app_style.sc_rec_style); + lv_obj_set_style(i->sc, &app_style.sc_rec_bg); } } } @@ -803,16 +798,16 @@ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t #if LV_APP_EFFECT_ANIM != 0 && LV_APP_EFFECT_OPA != 0 && LV_APP_ANIM_WIN != 0 /*Temporally set a simpler style for the window during the animation*/ memcpy(&wins_anim, lv_obj_get_style(app->win), sizeof(lv_wins_t)); - wins_anim.pages.sb_mode = LV_PAGE_SB_MODE_OFF; + wins_anim.page.sb_mode = LV_PAGE_SB_MODE_OFF; /*Mix a new color for the header instead of using opacity */ - wins_anim.header_opa = OPA_COVER; + wins_anim.header.base.opa = OPA_COVER; wins_anim.header.gcolor = color_mix(wins_anim.header.gcolor, - app_style.win_style.pages.bg_rects.gcolor, - app_style.win_style.header_opa); + app_style.win.page.bg.gcolor, + app_style.win.header.base.opa); - wins_anim.header.objs.color = color_mix(wins_anim.header.objs.color, - app_style.win_style.pages.bg_rects.objs.color, - app_style.win_style.header_opa); + wins_anim.header.base.color = color_mix(wins_anim.header.base.color, + app_style.win.page.bg.base.color, + app_style.win.header.base.opa); lv_obj_set_style(app->win, &wins_anim); /*Hide some elements to speed up the animation*/ @@ -871,14 +866,14 @@ static lv_action_res_t lv_app_win_conf_action(lv_obj_t * set_btn, lv_dispi_t * d app->conf_win = lv_win_create(lv_scr_act(), NULL); lv_obj_set_free_p(app->conf_win, app); - lv_obj_set_style(app->conf_win, &app_style.win_style); + lv_obj_set_style(app->conf_win, &app_style.win); char buf[256]; sprintf(buf, "%s settings", app->dsc->name); lv_win_set_title(app->conf_win, buf); - lv_obj_t * set_content = lv_page_get_scrl(app->conf_win); - lv_rect_set_fit(set_content, false, true); - lv_rect_set_layout(set_content, LV_RECT_LAYOUT_COL_L); - lv_obj_set_width(set_content, LV_HOR_RES - 2 * app_style.win_style.pages.bg_rects.hpad); + lv_obj_t * scrl = lv_page_get_scrl(app->conf_win); + lv_rect_set_fit(scrl, false, true); + lv_rect_set_layout(scrl, LV_RECT_LAYOUT_COL_L); + lv_obj_set_width(scrl, LV_HOR_RES - 2 * app_style.win.page.bg.hpad); lv_win_add_ctrl_btn(app->conf_win, "U:/icon_close" ,lv_win_close_action); @@ -912,16 +907,16 @@ static lv_action_res_t lv_app_win_open_anim_create(lv_app_inst_t * app) /*Temporally set a simpler style for the window during the animation*/ memcpy(&wins_anim, lv_obj_get_style(app->win), sizeof(lv_wins_t)); - wins_anim.pages.sb_mode = LV_PAGE_SB_MODE_OFF; + wins_anim.page.sb_mode = LV_PAGE_SB_MODE_OFF; /*Mix a new color for the header instead of using opacity */ - wins_anim.header_opa = OPA_COVER; + wins_anim.header.base.opa = OPA_COVER; wins_anim.header.gcolor = color_mix(wins_anim.header.gcolor, - app_style.win_style.pages.bg_rects.gcolor, - app_style.win_style.header_opa); + app_style.win.page.bg.gcolor, + app_style.win.header.base.opa); - wins_anim.header.objs.color = color_mix(wins_anim.header.objs.color, - app_style.win_style.pages.bg_rects.objs.color, - app_style.win_style.header_opa); + wins_anim.header.base.color = color_mix(wins_anim.header.base.color, + app_style.win.page.bg.base.color, + app_style.win.header.base.opa); lv_obj_set_style(app->win, &wins_anim); /*Hide some elements to speed up the animation*/ @@ -992,16 +987,16 @@ static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app) /*Temporally set a simpler style for the window during the animation*/ memcpy(&wins_anim, lv_obj_get_style(app->win), sizeof(lv_wins_t)); - wins_anim.pages.sb_mode = LV_PAGE_SB_MODE_OFF; + wins_anim.page.sb_mode = LV_PAGE_SB_MODE_OFF; /*Mix a new color for the header instead of using opacity */ - wins_anim.header_opa = OPA_COVER; + wins_anim.header.base.opa = OPA_COVER; wins_anim.header.gcolor = color_mix(wins_anim.header.gcolor, - app_style.win_style.pages.bg_rects.gcolor, - app_style.win_style.header_opa); + app_style.win.page.bg.gcolor, + app_style.win.header.base.opa); - wins_anim.header.objs.color = color_mix(wins_anim.header.objs.color, - app_style.win_style.pages.bg_rects.objs.color, - app_style.win_style.header_opa); + wins_anim.header.base.color = color_mix(wins_anim.header.base.color, + app_style.win.page.bg.base.color, + app_style.win.header.base.opa); lv_obj_set_style(app->win, &wins_anim); /*Hide some elements to speed up the animation*/ @@ -1062,7 +1057,7 @@ static void lv_app_win_open_anim_cb(lv_obj_t * app_win) lv_obj_set_hidden(((lv_win_ext_t *)app_win->ext)->page.scrl, false); /*Restore the style*/ - lv_obj_set_style(app_win, &app_style.win_style); + lv_obj_set_style(app_win, &app_style.win); } /** @@ -1093,148 +1088,145 @@ static void lv_app_win_minim_anim_cb(lv_obj_t * app_win) static void lv_app_init_style(void) { /*Coordinates*/ - app_style.menu_h = 40 * LV_DOWNSCALE; +#if LV_APP_DESKTOP != 0 + app_style.menu_h = 4 * LV_DPI / 5; app_style.app_list_w = LV_HOR_RES / 3; app_style.app_list_h = (3 * LV_VER_RES) / 4; - app_style.sc_title_margin = 2 * LV_DOWNSCALE; - - /*Opacity*/ -#if LV_APP_EFFECT_OPA == 0 - app_style.menu_opa = OPA_COVER; - app_style.menu_btn_opa = OPA_COVER; - app_style.sc_opa = OPA_COVER; #else - app_style.menu_opa = OPA_80; - app_style.menu_btn_opa = OPA_50; - app_style.sc_opa = OPA_70; - -// app_style.menu_opa = OPA_COVER; -// app_style.menu_btn_opa = OPA_COVER; -// app_style.sc_opa = OPA_COVER; + app_style.menu_h = 0; + app_style.app_list_w = 0; + app_style.app_list_h = 0; #endif + app_style.sc_title_margin = 2 * LV_DOWNSCALE; + /*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_rects_get(LV_RECTS_PLAIN,&app_style.menu_bg); + app_style.menu_bg.base.color = COLOR_BLACK; + app_style.menu_bg.gcolor = COLOR_BLACK; + app_style.menu_bg.base.opa = OPA_80; + app_style.menu_bg.radius = 0; + app_style.menu_bg.bwidth = 0; + app_style.menu_bg.swidth = 0; + app_style.menu_bg.vpad = LV_DPI / 10; + app_style.menu_bg.hpad = LV_DPI / 10; + app_style.menu_bg.opad = LV_DPI / 10; - 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; + lv_btns_get(LV_BTNS_DEF,&app_style.menu_btn); + app_style.menu_btn.state_style[LV_BTN_STATE_REL].base.color = COLOR_BLACK; + app_style.menu_btn.state_style[LV_BTN_STATE_REL].gcolor = COLOR_BLACK; + app_style.menu_btn.state_style[LV_BTN_STATE_REL].bwidth = 0; + app_style.menu_btn.state_style[LV_BTN_STATE_REL].radius = 0; + app_style.menu_btn.state_style[LV_BTN_STATE_REL].swidth = 0; + app_style.menu_btn.state_style[LV_BTN_STATE_REL].empty = 1; - 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.state_style[LV_BTN_STATE_PR].base.color = COLOR_GRAY; + app_style.menu_btn.state_style[LV_BTN_STATE_PR].gcolor = COLOR_GRAY; + app_style.menu_btn.state_style[LV_BTN_STATE_PR].bwidth = 0; + app_style.menu_btn.state_style[LV_BTN_STATE_PR].radius = 0; + app_style.menu_btn.state_style[LV_BTN_STATE_PR].empty = 0; + app_style.menu_btn.state_style[LV_BTN_STATE_PR].swidth = 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); + app_style.menu_btn_label.font = font_get(LV_APP_FONT_LARGE); + app_style.menu_btn_label.base.color = COLOR_MAKE(0xd0, 0xe0, 0xf0); - 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); - - 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; + lv_imgs_get(LV_IMGS_DEF,&app_style.menu_btn_img); + app_style.menu_btn_img.base.color = COLOR_WHITE; + app_style.menu_btn_img.recolor_opa = OPA_90; /*App list styles*/ - lv_lists_get(LV_LISTS_SCRL,&app_style.app_list_style); - app_style.app_list_style.widthe_sb = 0; - memcpy(&app_style.app_list_style.bg_pages.scrl_rects, &app_style.menu_style, sizeof(lv_rects_t)); - app_style.app_list_style.bg_pages.scrl_rects.hpad = 0 * LV_DOWNSCALE; - app_style.app_list_style.bg_pages.scrl_rects.vpad = 0 * LV_DOWNSCALE; - app_style.app_list_style.bg_pages.scrl_rects.opad = 0 * LV_DOWNSCALE; - memcpy(&app_style.app_list_style.liste_labels, &app_style.menu_btn_label_style, sizeof(lv_labels_t)); - memcpy(&app_style.app_list_style.liste_btns, &app_style.menu_btn_style, sizeof(lv_btns_t)); - 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; + lv_lists_get(LV_LISTS_DEF,&app_style.app_list); + app_style.app_list.width_sb = 0; /*Do not keep place for the scrollbar*/ + memcpy(&app_style.app_list.page.scrl, &app_style.menu_bg, sizeof(lv_rects_t)); + app_style.app_list.page.bg.hpad = 0 * LV_DOWNSCALE; + app_style.app_list.page.bg.hpad = 0 * LV_DOWNSCALE; + app_style.app_list.page.bg.vpad = 0 * LV_DOWNSCALE; + app_style.app_list.page.bg.opad = 0 * LV_DOWNSCALE; + app_style.app_list.page.scrl.hpad = 0 * LV_DOWNSCALE; + app_style.app_list.page.scrl.vpad = 0 * LV_DOWNSCALE; + app_style.app_list.page.scrl.opad = 0 * LV_DOWNSCALE; + memcpy(&app_style.app_list.liste_label, &app_style.menu_btn_label, sizeof(lv_labels_t)); + memcpy(&app_style.app_list.liste_btn, &app_style.menu_btn, sizeof(lv_btns_t)); + app_style.app_list.page.sb.base.color = COLOR_GRAY; + app_style.app_list.page.sb.gcolor = COLOR_GRAY; + app_style.app_list.page.sb_width = 8 * LV_DOWNSCALE; /*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 = 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.scrl_rects.objs.transp = 1; - app_style.sc_page_style.scrl_rects.hpad = 10 * LV_DOWNSCALE; - app_style.sc_page_style.scrl_rects.vpad = 10 * LV_DOWNSCALE; - app_style.sc_page_style.scrl_rects.opad = 15 * LV_DOWNSCALE; + lv_pages_get(LV_PAGES_TRANSP,&app_style.sc_page); + app_style.sc_page.bg.vpad = app_style.menu_h; + app_style.sc_page.bg.hpad = 0; + app_style.sc_page.bg.opad = 0; + app_style.sc_page.scrl.hpad = 10 * LV_DOWNSCALE; + app_style.sc_page.scrl.vpad = 10 * LV_DOWNSCALE; + app_style.sc_page.scrl.opad = 15 * LV_DOWNSCALE; /*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; + lv_btns_get(LV_BTNS_DEF,&app_style.sc_bg); + app_style.sc_bg.state_style[LV_BTN_STATE_REL].base.opa = OPA_80; + app_style.sc_bg.state_style[LV_BTN_STATE_REL].base.color = COLOR_WHITE; + app_style.sc_bg.state_style[LV_BTN_STATE_REL].gcolor = COLOR_MAKE(0x20, 0x30, 0x40); + app_style.sc_bg.state_style[LV_BTN_STATE_REL].bcolor = COLOR_MAKE(0x40, 0x60, 0x80); + app_style.sc_bg.state_style[LV_BTN_STATE_REL].bopa = OPA_70; + app_style.sc_bg.state_style[LV_BTN_STATE_REL].bwidth = 1 * LV_DOWNSCALE; + app_style.sc_bg.state_style[LV_BTN_STATE_REL].swidth = 0 * LV_DOWNSCALE; + app_style.sc_bg.state_style[LV_BTN_STATE_PR].base.opa = OPA_80; + app_style.sc_bg.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0xB0, 0xD0, 0xF0); + app_style.sc_bg.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0x00, 0x00, 0x00); + app_style.sc_bg.state_style[LV_BTN_STATE_PR].bcolor = COLOR_MAKE(0xB0, 0xD0, 0xF0); + app_style.sc_bg.state_style[LV_BTN_STATE_PR].bopa = OPA_70; + app_style.sc_bg.state_style[LV_BTN_STATE_PR].bwidth = 1 * LV_DOWNSCALE; + app_style.sc_bg.state_style[LV_BTN_STATE_PR].swidth = 0 * LV_DOWNSCALE; - memcpy(&app_style.sc_send_style, &app_style.sc_style, sizeof(lv_btns_t)); - app_style.sc_send_style.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0xFF, 0xE0, 0xE0); - app_style.sc_send_style.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x50, 0x20, 0x00); - app_style.sc_send_style.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; - app_style.sc_send_style.flags[LV_BTN_STATE_REL].light_en = 1; - app_style.sc_send_style.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xFF, 0xB0, 0xB0); - app_style.sc_send_style.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x10, 0x00); - app_style.sc_send_style.bcolor[LV_BTN_STATE_PR] = COLOR_BLACK; - app_style.sc_send_style.flags[LV_BTN_STATE_PR].light_en = 1; - app_style.sc_send_style.rects.light = 10 * LV_DOWNSCALE; - app_style.sc_send_style.rects.bopa = 30; - app_style.sc_send_style.rects.bwidth = 3 * LV_DOWNSCALE; + memcpy(&app_style.sc_send_bg, &app_style.sc_bg, sizeof(lv_btns_t)); + app_style.sc_send_bg.state_style[LV_BTN_STATE_REL].base.color = COLOR_MAKE(0xFF, 0xE0, 0xE0); + app_style.sc_send_bg.state_style[LV_BTN_STATE_REL].gcolor = COLOR_MAKE(0x50, 0x20, 0x00); + app_style.sc_send_bg.state_style[LV_BTN_STATE_REL].bcolor = COLOR_BLACK; + app_style.sc_send_bg.state_style[LV_BTN_STATE_REL].bopa = OPA_30; + app_style.sc_send_bg.state_style[LV_BTN_STATE_REL].bwidth = 3 * LV_DOWNSCALE; + app_style.sc_send_bg.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0xFF, 0xB0, 0xB0); + app_style.sc_send_bg.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0x20, 0x10, 0x00); + app_style.sc_send_bg.state_style[LV_BTN_STATE_PR].gcolor = COLOR_BLACK; + app_style.sc_send_bg.state_style[LV_BTN_STATE_PR].bopa = OPA_30; + app_style.sc_send_bg.state_style[LV_BTN_STATE_PR].bwidth = 3 * LV_DOWNSCALE; - memcpy(&app_style.sc_rec_style, &app_style.sc_style, sizeof(lv_btns_t)); - app_style.sc_rec_style.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0xE0, 0xFF, 0xE0); - app_style.sc_rec_style.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x20, 0x50, 0x20); - app_style.sc_rec_style.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; - app_style.sc_rec_style.flags[LV_BTN_STATE_REL].light_en = 1; - app_style.sc_rec_style.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xB0, 0xFF, 0xB0); - app_style.sc_rec_style.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x20, 0x10); - app_style.sc_rec_style.bcolor[LV_BTN_STATE_PR] = COLOR_BLACK; - app_style.sc_rec_style.flags[LV_BTN_STATE_PR].light_en = 1; - app_style.sc_rec_style.rects.light = 10 * LV_DOWNSCALE; - app_style.sc_rec_style.rects.bopa = 30; - app_style.sc_rec_style.rects.bwidth = 3 * LV_DOWNSCALE; + memcpy(&app_style.sc_rec_bg, &app_style.sc_bg, sizeof(lv_btns_t)); + app_style.sc_rec_bg.state_style[LV_BTN_STATE_REL].base.color = COLOR_MAKE(0xE0, 0xFF, 0xE0); + app_style.sc_rec_bg.state_style[LV_BTN_STATE_REL].gcolor = COLOR_MAKE(0x20, 0x50, 0x20); + app_style.sc_rec_bg.state_style[LV_BTN_STATE_REL].bcolor = COLOR_BLACK; + app_style.sc_rec_bg.state_style[LV_BTN_STATE_REL].bopa = OPA_30; + app_style.sc_rec_bg.state_style[LV_BTN_STATE_REL].bwidth = 3 * LV_DOWNSCALE; + app_style.sc_rec_bg.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0xB0, 0xFF, 0xB0); + app_style.sc_rec_bg.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0x20, 0x20, 0x10); + app_style.sc_rec_bg.state_style[LV_BTN_STATE_PR].bcolor = COLOR_BLACK; + app_style.sc_rec_bg.state_style[LV_BTN_STATE_PR].bopa = OPA_30; + app_style.sc_rec_bg.state_style[LV_BTN_STATE_PR].bwidth = 3 * LV_DOWNSCALE; - 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(0x10, 0x18, 0x20); + lv_labels_get(LV_LABELS_TITLE,&app_style.sc_title_style); + app_style.sc_title_style.font = font_get(LV_APP_FONT_SMALL); + app_style.sc_title_style.base.color = COLOR_MAKE(0x10, 0x18, 0x20); app_style.sc_title_style.mid = 1; - lv_labels_get(LV_LABELS_DEF,&app_style.sc_txt_style); - app_style.sc_txt_style.font = LV_APP_FONT_MEDIUM; - app_style.sc_txt_style.objs.color = COLOR_MAKE(0x10, 0x18, 0x20); + lv_labels_get(LV_LABELS_TXT, &app_style.sc_txt_style); + app_style.sc_txt_style.font = font_get(LV_APP_FONT_MEDIUM); + app_style.sc_txt_style.base.color = COLOR_MAKE(0x10, 0x18, 0x20); app_style.sc_txt_style.mid = 1; /*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)); - 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; - app_style.win_style.pages.bg_rects.vpad = app_style.win_style.ctrl_btn_h + - 2 * app_style.win_style.header.vpad; - app_style.win_style.pages.bg_rects.hpad = 5 * LV_DOWNSCALE; - app_style.win_style.pages.scrl_rects.objs.transp = 1; - app_style.win_style.pages.sb_mode = LV_PAGE_SB_MODE_AUTO; + lv_wins_get(LV_WINS_DEF,&app_style.win); + app_style.win.page.bg.vpad = app_style.win.ctrl_btn_h + 2 * app_style.win.header.vpad; + app_style.win.page.sb_mode = LV_PAGE_SB_MODE_AUTO; + memcpy(&app_style.win.header, &app_style.menu_bg, sizeof(lv_rects_t)); + app_style.win.header.base.opa = app_style.menu_bg.base.opa; + memcpy(&app_style.win.title, &app_style.menu_btn_label, sizeof(lv_labels_t)); + memcpy(&app_style.win.ctrl_btn, &app_style.menu_btn, sizeof(lv_btns_t)); + app_style.win.ctrl_btn.state_style[LV_BTN_STATE_REL].base.opa = app_style.menu_btn.state_style[LV_BTN_STATE_REL].base.opa; + app_style.win.ctrl_btn.state_style[LV_BTN_STATE_PR].base.opa = app_style.menu_btn.state_style[LV_BTN_STATE_REL].base.opa; + memcpy(&app_style.win.ctrl_img, &app_style.menu_btn_img, sizeof(lv_imgs_t)); - lv_labels_get(LV_LABELS_DEF,&app_style.win_txt_style); - app_style.win_txt_style.font = LV_APP_FONT_MEDIUM; - app_style.win_txt_style.objs.color = COLOR_MAKE(0x20, 0x20, 0x20); + lv_labels_get(LV_LABELS_TXT,&app_style.win_txt_style); + app_style.win_txt_style.font = font_get(LV_APP_FONT_MEDIUM); + app_style.win_txt_style.base.color = COLOR_MAKE(0x20, 0x20, 0x20); app_style.win_txt_style.mid = 0; app_style.win_txt_style.letter_space = 1 * LV_DOWNSCALE; } diff --git a/lv_app/lv_app.h b/lv_app/lv_app.h index 97378ae02..24460b606 100644 --- a/lv_app/lv_app.h +++ b/lv_app/lv_app.h @@ -71,24 +71,20 @@ typedef struct __LV_APP_DSC_T }lv_app_dsc_t; typedef struct { - lv_rects_t menu_style; - lv_btns_t menu_btn_style; - lv_labels_t menu_btn_label_style; - lv_imgs_t menu_btn_img_style; - lv_lists_t app_list_style; - lv_pages_t sc_page_style; + lv_rects_t menu_bg; + lv_btns_t menu_btn; + lv_labels_t menu_btn_label; + lv_imgs_t menu_btn_img; + lv_lists_t app_list; + lv_pages_t sc_page; lv_labels_t win_txt_style; - lv_wins_t win_style; - lv_btns_t sc_style; - lv_btns_t sc_send_style; - lv_btns_t sc_rec_style; + lv_wins_t win; + lv_btns_t sc_bg; + lv_btns_t sc_send_bg; + lv_btns_t sc_rec_bg; lv_labels_t sc_title_style; lv_labels_t sc_txt_style; - opa_t menu_opa; - opa_t menu_btn_opa; - opa_t sc_opa; - cord_t menu_h; cord_t app_list_w; cord_t app_list_h; diff --git a/lv_app/lv_app_util/lv_app_fsel.c b/lv_app/lv_app_util/lv_app_fsel.c index c4ae5e091..6a58859b3 100644 --- a/lv_app/lv_app_util/lv_app_fsel.c +++ b/lv_app/lv_app_util/lv_app_fsel.c @@ -95,7 +95,7 @@ void lv_app_fsel_open(const char * path, const char * filter, void * param, void lv_app_style_t * app_style = lv_app_style_get(); fsel_win = lv_win_create(lv_scr_act(), NULL); lv_obj_set_size(fsel_win, LV_HOR_RES, LV_VER_RES); - lv_obj_set_style(fsel_win, &app_style->win_style); + lv_obj_set_style(fsel_win, &app_style->win); lv_win_add_ctrl_btn(fsel_win, "U:/icon_close", fsel_close_action); diff --git a/lv_app/lv_app_util/lv_app_kb.c b/lv_app/lv_app_util/lv_app_kb.c index f2d74d8f2..6a2c8dfa7 100644 --- a/lv_app/lv_app_util/lv_app_kb.c +++ b/lv_app/lv_app_util/lv_app_kb.c @@ -78,17 +78,18 @@ static lv_btnms_t kb_btnms; */ void lv_app_kb_init(void) { - lv_btnms_get(LV_BTNMS_DEF, &kb_btnms); - kb_btnms.rects.gcolor = COLOR_WHITE; - kb_btnms.rects.objs.color = COLOR_WHITE; - 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_btnms.rects.bwidth = 0; + lv_app_style_t * app_style = lv_app_style_get(); - kb_btnms.btns.rects.bwidth = 0; - kb_btnms.btns.rects.round = 0; + lv_btnms_get(LV_BTNMS_DEF, &kb_btnms); + + memcpy(&kb_btnms.bg, &app_style->menu_bg, sizeof(lv_rects_t)); + kb_btnms.bg.hpad = 0; + kb_btnms.bg.vpad = 0; + kb_btnms.bg.opad = 0; + memcpy(&kb_btnms.btn, &app_style->menu_btn, sizeof(lv_btns_t)); + kb_btnms.btn.state_style[LV_BTN_STATE_REL].bwidth = 1 * LV_DOWNSCALE; + kb_btnms.btn.state_style[LV_BTN_STATE_REL].bcolor = COLOR_GRAY; + memcpy(&kb_btnms.label, &app_style->menu_btn_label, sizeof(lv_labels_t)); } /** @@ -117,23 +118,23 @@ void lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t lv_obj_align(kb_btnm, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_btnm_set_cb(kb_btnm, lv_app_kb_action); if(mode & LV_APP_KB_MODE_TXT) { - kb_btnms.labels.font = LV_APP_FONT_MEDIUM; + kb_btnms.label.font = font_get(LV_APP_FONT_MEDIUM); lv_btnm_set_map(kb_btnm, kb_map_lc); } else if(mode & LV_APP_KB_MODE_NUM) { - kb_btnms.labels.font = LV_APP_FONT_LARGE; + kb_btnms.label.font = font_get(LV_APP_FONT_LARGE); lv_btnm_set_map(kb_btnm, kb_map_num); } lv_obj_set_style(kb_btnm, &kb_btnms); - /*Reduce teh size of the window and align it to the top*/ + /*Reduce the 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*/ + /*If the text area is higher then the new size of the window reduce its size too*/ lv_app_style_t * app_style = lv_app_style_get(); - cord_t win_h = lv_obj_get_height(kb_win) - 2 * app_style->win_style.pages.scrl_rects.vpad; + cord_t win_h = lv_obj_get_height(kb_win) - 2 * app_style->win.page.bg.vpad; kb_ta_ori_size = lv_obj_get_height(kb_ta); if(lv_obj_get_height(kb_ta) > win_h) { lv_obj_set_height(kb_ta, win_h); diff --git a/lv_app/lv_app_util/lv_app_notice.c b/lv_app/lv_app_util/lv_app_notice.c index b0e03e3d5..d94c08cf4 100644 --- a/lv_app/lv_app_util/lv_app_notice.c +++ b/lv_app/lv_app_util/lv_app_notice.c @@ -59,8 +59,8 @@ void lv_app_notice_init(void) lv_app_style_t * app_style = lv_app_style_get(); notice_h = lv_rect_create(lv_scr_act(), NULL); - lv_obj_set_size(notice_h, LV_HOR_RES, LV_VER_RES - app_style->menu_h); - lv_obj_set_y(notice_h, app_style->menu_h); + lv_obj_set_size(notice_h, LV_HOR_RES, LV_VER_RES - app_style->menu_h - LV_DPI / 8); + lv_obj_set_y(notice_h, app_style->menu_h + LV_DPI / 8); lv_obj_set_click(notice_h, false); lv_obj_set_style(notice_h, lv_rects_get(LV_RECTS_TRANSP, NULL)); lv_rect_set_layout(notice_h, LV_RECT_LAYOUT_COL_R); @@ -80,14 +80,11 @@ lv_obj_t * lv_app_notice_add(const char * format, ...) vsprintf(txt,format, va); va_end(va); - lv_app_style_t * app_style = lv_app_style_get(); - lv_obj_t * mbox; mbox = lv_mbox_create(notice_h, NULL); lv_obj_set_style(mbox, lv_mboxs_get(LV_MBOXS_INFO, NULL)); lv_mbox_set_title(mbox, ""); lv_mbox_set_text(mbox, txt); - lv_obj_set_opa(mbox, app_style->menu_opa); #if LV_APP_NOTICE_SHOW_TIME != 0 lv_mbox_start_auto_close(mbox, LV_APP_NOTICE_SHOW_TIME); diff --git a/lv_appx/lv_app_files.c b/lv_appx/lv_app_files.c index e9fb5e378..4373926e7 100644 --- a/lv_appx/lv_app_files.c +++ b/lv_appx/lv_app_files.c @@ -131,7 +131,7 @@ const lv_app_dsc_t * lv_app_files_init(void) { lv_app_style_t * app_style = lv_app_style_get(); memcpy(&sc_labels, &app_style->sc_txt_style, sizeof(lv_labels_t)); - sc_labels.font = LV_APP_FONT_LARGE; + sc_labels.font = font_get(LV_APP_FONT_LARGE); return &my_app_dsc; @@ -281,21 +281,21 @@ static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win) lv_obj_set_free_num(cb, SEND_SETTINGS_FN); lv_obj_set_free_p(cb, app); lv_btn_set_rel_action(cb, win_send_settings_element_rel_action); - if(app_data->send_fn != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL); + if(app_data->send_fn != 0) lv_btn_set_state(cb, LV_BTN_STATE_TREL); else lv_btn_set_state(cb, LV_BTN_STATE_REL); /*Send size check box*/ cb = lv_cb_create(conf_win, cb); lv_cb_set_text(cb, "Send size"); lv_obj_set_free_num(cb, SEND_SETTINGS_SIZE); - if(app_data->send_size != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL); + if(app_data->send_size != 0) lv_btn_set_state(cb, LV_BTN_STATE_TREL); else lv_btn_set_state(cb, LV_BTN_STATE_REL); /*Send CRC check box*/ cb = lv_cb_create(conf_win, cb); lv_cb_set_text(cb, "Send CRC"); lv_obj_set_free_num(cb, SEND_SETTINGS_CRC); - if(app_data->send_crc != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL); + if(app_data->send_crc != 0) lv_btn_set_state(cb, LV_BTN_STATE_TREL); else lv_btn_set_state(cb, LV_BTN_STATE_REL); /*Create a text area the type chunk size*/ @@ -313,7 +313,7 @@ static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win) lv_obj_t * ta; char buf[32]; ta = lv_ta_create(val_set_h, NULL); - lv_obj_set_style(ta, lv_tas_get(LV_TAS_SIMPLE, NULL)); + lv_obj_set_style(ta, lv_tas_get(LV_TAS_DEF, NULL)); lv_rect_set_fit(ta, false, true); lv_obj_set_free_num(ta, SEND_SETTINGS_CHUNK_SIZE); lv_obj_set_free_p(ta, app); diff --git a/lv_appx/lv_app_sysmon.c b/lv_appx/lv_app_sysmon.c index 0cabe7a78..8cd4fe341 100644 --- a/lv_appx/lv_app_sysmon.c +++ b/lv_appx/lv_app_sysmon.c @@ -111,28 +111,28 @@ const lv_app_dsc_t * lv_app_sysmon_init(void) /*Create progress bar styles for the shortcut*/ lv_pbs_get(LV_PBS_DEF, &cpu_pbs); cpu_pbs.bg.gcolor = COLOR_MAKE(0xFF, 0xE0, 0xE0); - cpu_pbs.bg.objs.color = COLOR_MAKE(0xFF, 0xD0, 0xD0); + cpu_pbs.bg.base.color = COLOR_MAKE(0xFF, 0xD0, 0xD0); cpu_pbs.bg.bcolor = COLOR_MAKE(0xFF, 0x20, 0x20); cpu_pbs.bg.bwidth = 1 * LV_DOWNSCALE; cpu_pbs.bar.gcolor = COLOR_MARRON; - cpu_pbs.bar.objs.color = COLOR_RED; + cpu_pbs.bar.base.color = COLOR_RED; cpu_pbs.bar.bwidth = 0; - cpu_pbs.label.objs.color = COLOR_MAKE(0x40, 0x00, 0x00); - cpu_pbs.label.font = LV_APP_FONT_MEDIUM; + cpu_pbs.label.base.color = COLOR_MAKE(0x40, 0x00, 0x00); + cpu_pbs.label.font = font_get(LV_APP_FONT_MEDIUM); cpu_pbs.label.line_space = 0; cpu_pbs.label.mid = 1; memcpy(&mem_pbs, &cpu_pbs, sizeof(mem_pbs)); mem_pbs.bg.gcolor = COLOR_MAKE(0xD0, 0xFF, 0xD0); - mem_pbs.bg.objs.color = COLOR_MAKE(0xE0, 0xFF, 0xE0); + mem_pbs.bg.base.color = COLOR_MAKE(0xE0, 0xFF, 0xE0); mem_pbs.bg.bcolor = COLOR_MAKE(0x20, 0xFF, 0x20); mem_pbs.bar.gcolor = COLOR_GREEN; - mem_pbs.bar.objs.color = COLOR_LIME; + mem_pbs.bar.base.color = COLOR_LIME; - mem_pbs.label.objs.color = COLOR_MAKE(0x00, 0x40, 0x00); + mem_pbs.label.base.color = COLOR_MAKE(0x00, 0x40, 0x00); return &my_app_dsc; } @@ -230,6 +230,7 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) /*Create a chart with two data lines*/ win_data->chart = lv_chart_create(win, NULL); lv_obj_set_size(win_data->chart, LV_HOR_RES / 2, LV_VER_RES / 2); + lv_obj_set_pos(win_data->chart, LV_DPI / 10, LV_DPI / 10); lv_chart_set_pnum(win_data->chart, LV_APP_SYSMON_PNUM); lv_chart_set_range(win_data->chart, 0, 100); lv_chart_set_type(win_data->chart, LV_CHART_LINE); @@ -244,7 +245,7 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) } /*Create a label for the details of Memory and CPU usage*/ - cord_t opad = app_style->win_style.pages.scrl_rects.opad; + cord_t opad = app_style->win.page.scrl.opad; win_data->label = lv_label_create(win, NULL); lv_label_set_recolor(win_data->label, true); lv_obj_align(win_data->label, win_data->chart, LV_ALIGN_OUT_RIGHT_MID, opad, 0); @@ -369,7 +370,7 @@ static void lv_app_sysmon_refr(void) sprintf(buf_short, "%sMem: N/A\nFrag: N/A", buf_short); #endif lv_app_style_t * app_style = lv_app_style_get(); - cord_t opad = app_style->win_style.pages.scrl_rects.opad; + cord_t opad = app_style->win.page.scrl.opad; lv_app_inst_t * app; app = lv_app_get_next(NULL, &my_app_dsc); while(app != NULL) { diff --git a/lv_appx/lv_app_terminal.c b/lv_appx/lv_app_terminal.c index 85a700e51..a514694e5 100644 --- a/lv_appx/lv_app_terminal.c +++ b/lv_appx/lv_app_terminal.c @@ -125,9 +125,9 @@ const lv_app_dsc_t * lv_app_terminal_init(void) sc_txts.line_space = 0; sc_txts.letter_space = 0; sc_txts.mid = 0; - sc_txts.objs.color = COLOR_WHITE; + sc_txts.base.color = COLOR_WHITE; - lv_objs_get(LV_OBJS_DEF, &sc_txt_bgs); + lv_objs_get(LV_OBJS_PLAIN, &sc_txt_bgs); sc_txt_bgs.color = COLOR_MAKE(0x20, 0x20, 0x20); @@ -252,14 +252,14 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) my_app_data_t * app_data = app->app_data; lv_app_style_t * app_style = lv_app_style_get(); - cord_t opad = app_style->win_style.pages.scrl_rects.opad; + cord_t opad = app_style->win.page.scrl.opad; /*Create a label for the text of the terminal*/ win_data->label = lv_label_create(win, NULL); lv_label_set_long_mode(win_data->label, LV_LABEL_LONG_BREAK); lv_obj_set_width(win_data->label, LV_HOR_RES - - 2 * (app_style->win_style.pages.bg_rects.hpad + - app_style->win_style.pages.scrl_rects.hpad)); + 2 * (app_style->win.page.bg.hpad + + app_style->win.page.scrl.hpad)); lv_obj_set_style(win_data->label, &app_style->win_txt_style); lv_label_set_text_static(win_data->label, app_data->txt); /*Use the app. data text directly*/ @@ -271,7 +271,8 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) lv_page_set_rel_action(win_data->ta, win_ta_rel_action); lv_ta_set_text(win_data->ta, ""); lv_obj_set_style(win_data->ta, lv_tas_get(LV_TAS_DEF, NULL)); - lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, opad); + if(app_data->txt[0] != '\0') lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, opad, opad); + else lv_obj_align(win_data->ta, NULL, LV_ALIGN_IN_TOP_LEFT, opad, opad); /*Create a clear button*/ win_data->clear_btn = lv_btn_create(win, NULL); @@ -285,7 +286,7 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) /*Align the window to see the text area on the bottom*/ lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - - app_style->win_style.pages.scrl_rects.vpad); + - app_style->win.page.scrl.vpad); } @@ -405,12 +406,12 @@ static lv_action_res_t win_clear_rel_action(lv_obj_t * btn, lv_dispi_t * dispi) if(win_data != NULL) { lv_app_style_t * app_style =lv_app_style_get(); - cord_t opad = app_style->win_style.pages.scrl_rects.opad; + cord_t opad = app_style->win.page.scrl.opad; lv_label_set_text_static(win_data->label, app_data->txt); - lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, opad); + lv_obj_align(win_data->ta, NULL, LV_ALIGN_IN_TOP_LEFT, opad, opad); lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0); lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - - app_style->win_style.pages.scrl_rects.vpad); + - app_style->win.page.scrl.vpad); } return LV_ACTION_RES_OK; @@ -491,12 +492,12 @@ static void add_data(lv_app_inst_t * app, const void * data, uint16_t data_len) lv_app_style_t * app_style = lv_app_style_get(); if(win_data != NULL) { - cord_t opad = app_style->win_style.pages.scrl_rects.opad; + cord_t opad = app_style->win.page.scrl.opad; lv_label_set_text_static(win_data->label, app_data->txt); - lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, opad); + lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, opad, opad); lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0); lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - - app_style->win_style.pages.scrl_rects.vpad); + - app_style->win.page.scrl.vpad); } /*Set the last line on the shortcut*/ diff --git a/lv_conf_temp.h b/lv_conf_temp.h index 0c37d4cd4..ca9ed3b56 100644 --- a/lv_conf_temp.h +++ b/lv_conf_temp.h @@ -26,6 +26,7 @@ * Use LV_DOWNSCALE to compensate * the down scaling effect of antialiassing*/ #define LV_ANTIALIAS 1 +#define LV_FONT_ANTIALIAS 0 /*Set the downscaling value*/ #if LV_ANTIALIAS == 0 #define LV_DOWNSCALE 1 diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 88575bc84..375151b91 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -1,5 +1,5 @@ /** - * @file lv_draw_img.c + * @file lv_draw.c * */ @@ -42,10 +42,10 @@ typedef enum * STATIC PROTOTYPES **********************/ #if USE_LV_RECT != 0 -static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa); -static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa); -static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa); -static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa); +static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p); +static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p); +static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p); +static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p); static uint16_t lv_draw_rect_radius_corr(uint16_t r, cord_t w, cord_t h); #endif /*USE_LV_RECT != 0*/ @@ -70,13 +70,13 @@ static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color #if USE_LV_IMG != 0 && USE_FSINT != 0 && USE_UFS != 0 static lv_rects_t lv_img_no_pic_rects = { - .objs.color = COLOR_BLACK, .gcolor = COLOR_BLACK, + .base.color = COLOR_BLACK, .gcolor = COLOR_BLACK, .bcolor = COLOR_RED, .bwidth = 2 * LV_DOWNSCALE, .bopa = 100, - .round = 0, .empty = 0 + .radius = 0, .empty = 0 }; static lv_labels_t lv_img_no_pic_labels = { - .font = LV_FONT_DEFAULT, .objs.color = COLOR_WHITE, + .base.color = COLOR_WHITE, .letter_space = 1 * LV_DOWNSCALE, .line_space = 1 * LV_DOWNSCALE, .mid = 1, }; @@ -96,26 +96,24 @@ static lv_labels_t lv_img_no_pic_labels = { * @param cords_p the coordinates of the rectangle * @param mask_p the rectangle will be drawn only in this mask * @param rects_p pointer to a rectangle style - * @param opa the opacity of the rectangle (0..255) */ -void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, - const lv_rects_t * rects_p, opa_t opa) +void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p) { if(area_get_height(cords_p) < 1 || area_get_width(cords_p) < 1) return; if(rects_p->empty == 0){ - lv_draw_rect_main_mid(cords_p, mask_p, rects_p, opa); + lv_draw_rect_main_mid(cords_p, mask_p, rects_p); - if(rects_p->round != 0) { - lv_draw_rect_main_corner(cords_p, mask_p, rects_p, opa); + if(rects_p->radius != 0) { + lv_draw_rect_main_corner(cords_p, mask_p, rects_p); } } if(rects_p->bwidth != 0) { - lv_draw_rect_border_straight(cords_p, mask_p, rects_p, opa); + lv_draw_rect_border_straight(cords_p, mask_p, rects_p); - if(rects_p->round != 0) { - lv_draw_rect_border_corner(cords_p, mask_p, rects_p, opa); + if(rects_p->radius != 0) { + lv_draw_rect_border_corner(cords_p, mask_p, rects_p); } } } @@ -236,21 +234,20 @@ void lv_draw_triangle(const point_t * points, const area_t * mask_p, color_t col * @param cords_p coordinates of the label * @param mask_p the label will be drawn only in this area * @param labels_p pointer to a label style - * @param opa opacity of the text (0..255) * @param txt 0 terminated text to write * @param flag settings for the text from 'txt_flag_t' enum */ -void lv_draw_label(const area_t * cords_p,const area_t * mask_p, - const lv_labels_t * style, opa_t opa, const char * txt, txt_flag_t flag) +void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels_t * style, + const char * txt, txt_flag_t flag) { - const font_t * font_p = font_get(style->font); + const font_t * font = style->font; cord_t w = area_get_width(cords_p); /*Init variables for the first line*/ cord_t line_length = 0; uint32_t line_start = 0; - uint32_t line_end = txt_get_next_line(txt, font_p, style->letter_space, w, flag); + uint32_t line_end = txt_get_next_line(txt, font, style->letter_space, w, flag); point_t pos; pos.x = cords_p->x1; @@ -259,7 +256,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, /*Align the line to middle if enabled*/ if(style->mid != 0) { line_length = txt_get_width(&txt[line_start], line_end - line_start, - font_p, style->letter_space, flag); + font, style->letter_space, flag); pos.x += (w - line_length) / 2; } @@ -301,7 +298,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, sscanf(buf, "%02x%02x%02x", &r, &g, &b); recolor = COLOR_MAKE(r, g, b); } else { - recolor.full = style->objs.color.full; + recolor.full = style->base.color.full; } cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/ } @@ -309,23 +306,23 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, } } - if(cmd_state == CMD_STATE_IN) letter_fp(&pos, mask_p, font_p, txt[i], recolor, opa); - else letter_fp(&pos, mask_p, font_p, txt[i], style->objs.color, opa); - pos.x += (font_get_width(font_p, txt[i]) >> LV_FONT_ANTIALIAS) + style->letter_space; + if(cmd_state == CMD_STATE_IN) letter_fp(&pos, mask_p, font, txt[i], recolor, style->base.opa); + else letter_fp(&pos, mask_p, font, txt[i], style->base.color, style->base.opa); + pos.x += (font_get_width(font, txt[i]) >> LV_FONT_ANTIALIAS) + style->letter_space; } /*Go to next line*/ line_start = line_end; - line_end += txt_get_next_line(&txt[line_start], font_p, style->letter_space, w, flag); + line_end += txt_get_next_line(&txt[line_start], font, style->letter_space, w, flag); pos.x = cords_p->x1; /*Align to middle*/ if(style->mid != 0) { line_length = txt_get_width(&txt[line_start], line_end - line_start, - font_p, style->letter_space, flag); + font, style->letter_space, flag); pos.x += (w - line_length) / 2; } /*Go the next line position*/ - pos.y += font_get_height(font_p) >> LV_FONT_ANTIALIAS; + pos.y += font_get_height(font) >> LV_FONT_ANTIALIAS; pos.y += style->line_space; } } @@ -341,11 +338,12 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, * @param opa opacity of the image (0..255) */ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, - const lv_imgs_t * imgs_p, opa_t opa, const char * fn) + const lv_imgs_t * style, const char * fn) { if(fn == NULL) { - lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); - lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, "No data", TXT_FLAG_NONE); + lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects); + if(lv_img_no_pic_labels.font == NULL) lv_img_no_pic_labels.font = font_get(LV_FONT_DEFAULT); + lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, "No data", TXT_FLAG_NONE); } else { fs_file_t file; fs_res_t res = fs_open(&file, fn, FS_MODE_RD); @@ -414,15 +412,15 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, uint8_t * f_data = ((ufs_file_t*)file.file_d)->ent->data_d; f_data += ((ufs_file_t*)file.file_d)->rwp; ((ufs_file_t*)file.file_d)->rwp += useful_data; - map_fp(&act_area, &mask_sub, (void*)f_data , opa, header.transp, upscale, - imgs_p->objs.color, imgs_p->recolor_opa); + map_fp(&act_area, &mask_sub, (void*)f_data , style->base.opa, header.transp, upscale, + style->base.color, style->recolor_opa); } /*Or read the NOT const files normally*/ else { color_t buf[LV_HOR_RES]; res = fs_read(&file, buf, useful_data, &br); - map_fp(&act_area, &mask_sub, buf, opa, header.transp, upscale, - imgs_p->objs.color, imgs_p->recolor_opa); + map_fp(&act_area, &mask_sub, buf, style->base.opa, header.transp, upscale, + style->base.color, style->recolor_opa); } fs_tell(&file, &act_pos); @@ -435,8 +433,9 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, fs_close(&file); if(res != FS_RES_OK) { - lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); - lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, fn, TXT_FLAG_NONE); + lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects); + if(lv_img_no_pic_labels.font == NULL) lv_img_no_pic_labels.font = font_get(LV_FONT_DEFAULT); + lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, fn, TXT_FLAG_NONE); } } } @@ -451,12 +450,11 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, * @param p2 second point of the line * @param mask_pthe line will be drawn only on this area * @param lines_p pointer to a line style - * @param opa opacity of the line (0..255) */ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, - const lv_lines_t * lines_p, opa_t opa) + const lv_lines_t * style) { - if(lines_p->width == 0) return; + if(style->width == 0) return; if(p1->x == p2->x && p1->y == p2->y) return; @@ -492,7 +490,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, } /*Make the correction on lie width*/ - width = ((lines_p->width - 1) * width_corr_array[wcor]) >> LINE_WIDTH_CORR_SHIFT; + width = ((style->width - 1) * width_corr_array[wcor]) >> LINE_WIDTH_CORR_SHIFT; width_half = width >> 1; width_1 = width & 0x1 ? 1 : 0; @@ -511,7 +509,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); + fill_fp(&draw_area, mask_p, style->base.color, style->base.opa); } if (hor == false && last_x != act_point.x) { area_t act_area; @@ -527,7 +525,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); + fill_fp(&draw_area, mask_p, style->base.color, style->base.opa); } /*Calc. the next point of the line*/ @@ -555,7 +553,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); + fill_fp(&draw_area, mask_p, style->base.color, style->base.opa); } if (hor == false) { area_t act_area; @@ -569,7 +567,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); + fill_fp(&draw_area, mask_p, style->base.color, style->base.opa); } } #endif /*USE_LV_LINE != 0*/ @@ -584,15 +582,15 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, * @param cords_p the coordinates of the original rectangle * @param mask_p the rectangle will be drawn only on this area * @param rects_p pointer to a rectangle style - * @param opa opacity of the rectangle (0..255) */ -static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa) +static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p) { - uint16_t radius = rects_p->round; + uint16_t radius = rects_p->radius; - color_t main_color = rects_p->objs.color; - color_t grad_color = rects_p->gcolor; + color_t mcolor = rects_p->base.color; + color_t gcolor = rects_p->gcolor; uint8_t mix; + opa_t opa = rects_p->base.opa; cord_t height = area_get_height(cords_p); cord_t width = area_get_width(cords_p); @@ -605,10 +603,10 @@ static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, work_area.x1 = cords_p->x1; work_area.x2 = cords_p->x2; - if(main_color.full == grad_color.full) { + if(mcolor.full == gcolor.full) { work_area.y1 = cords_p->y1 + radius; work_area.y2 = cords_p->y2 - radius; - fill_fp(&work_area, mask_p, main_color, opa); + fill_fp(&work_area, mask_p, mcolor, opa); } else { cord_t row; @@ -623,7 +621,7 @@ static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, work_area.y1 = row; work_area.y2 = row; mix = (uint32_t)((uint32_t)(cords_p->y2 - work_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&work_area, mask_p, act_color, opa); } @@ -634,15 +632,15 @@ static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, * @param cords_p the coordinates of the original rectangle * @param mask_p the rectangle will be drawn only on this area * @param rects_p pointer to a rectangle style - * @param opa opacity of the rectangle (0..255) */ -static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa) +static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p) { - uint16_t radius = rects_p->round; + uint16_t radius = rects_p->radius; - color_t main_color = rects_p->objs.color; - color_t grad_color = rects_p->gcolor; + color_t mcolor = rects_p->base.color; + color_t gcolor = rects_p->gcolor; color_t act_color; + opa_t opa = rects_p->base.opa; uint8_t mix; cord_t height = area_get_height(cords_p); cord_t width = area_get_width(cords_p); @@ -735,25 +733,25 @@ static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask /*Draw the areas which are not disabled*/ if(edge_top_refr != 0){ mix = (uint32_t)((uint32_t)(cords_p->y2 - edge_top_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&edge_top_area, mask_p, act_color, opa); } if(mid_top_refr != 0) { mix = (uint32_t)((uint32_t)(cords_p->y2 - mid_top_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&mid_top_area, mask_p, act_color, opa); } if(mid_bot_refr != 0) { mix = (uint32_t)((uint32_t)(cords_p->y2 - mid_bot_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&mid_bot_area, mask_p, act_color, opa); } if(edge_bot_refr != 0) { mix = (uint32_t)((uint32_t)(cords_p->y2 - edge_bot_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&edge_bot_area, mask_p, act_color, opa); } /*Save the current coordinates*/ @@ -781,20 +779,20 @@ static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask } mix = (uint32_t)((uint32_t)(cords_p->y2 - edge_top_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&edge_top_area, mask_p, act_color, opa); if(edge_top_area.y1 != mid_top_area.y1) { mix = (uint32_t)((uint32_t)(cords_p->y2 - mid_top_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&mid_top_area, mask_p, act_color, opa); } mix = (uint32_t)((uint32_t)(cords_p->y2 - mid_bot_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&mid_bot_area, mask_p, act_color, opa); if(edge_bot_area.y1 != mid_bot_area.y1) { mix = (uint32_t)((uint32_t)(cords_p->y2 - edge_bot_area.y1) * 255) / height; - act_color = color_mix(main_color, grad_color, mix); + act_color = color_mix(mcolor, gcolor, mix); fill_fp(&edge_bot_area, mask_p, act_color, opa); } @@ -805,28 +803,27 @@ if(edge_top_area.y1 != mid_top_area.y1) { * @param cords_p the coordinates of the original rectangle * @param mask_p the rectangle will be drawn only on this area * @param rects_p pointer to a rectangle style - * @param opa opacity of the rectangle (0..255) */ -static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa) +static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p) { - uint16_t radius = rects_p->round; + uint16_t radius = rects_p->radius; cord_t width = area_get_width(cords_p); cord_t height = area_get_height(cords_p); - uint16_t b_width = rects_p->bwidth; - opa_t b_opa = (uint16_t)((uint16_t) opa * rects_p->bopa) / 100; + uint16_t bwidth = rects_p->bwidth; + opa_t bopa = (uint16_t)((uint16_t) rects_p->base.opa * rects_p->bopa) >> 8; area_t work_area; cord_t length_corr = 0; cord_t corner_size = 0; /*the 0 px border width drawn as 1 px, so decrement the b_width*/ - b_width--; + bwidth--; radius = lv_draw_rect_radius_corr(radius, width, height); - if(radius < b_width) { - length_corr = b_width - radius; - corner_size = b_width; + if(radius < bwidth) { + length_corr = bwidth - radius; + corner_size = bwidth; } else { corner_size = radius; } @@ -838,53 +835,53 @@ static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * /*Left border*/ work_area.x1 = cords_p->x1; - work_area.x2 = work_area.x1 + b_width; + work_area.x2 = work_area.x1 + bwidth; work_area.y1 = cords_p->y1 + corner_size; work_area.y2 = cords_p->y2 - corner_size; - fill_fp(&work_area, mask_p, b_color, b_opa); + fill_fp(&work_area, mask_p, b_color, bopa); /*Right border*/ work_area.x2 = cords_p->x2; - work_area.x1 = work_area.x2 - b_width; - fill_fp(&work_area, mask_p, b_color, b_opa); + work_area.x1 = work_area.x2 - bwidth; + fill_fp(&work_area, mask_p, b_color, bopa); /*Upper border*/ work_area.x1 = cords_p->x1 + corner_size - length_corr; work_area.x2 = cords_p->x2 - corner_size + length_corr; work_area.y1 = cords_p->y1; - work_area.y2 = cords_p->y1 + b_width; - fill_fp(&work_area, mask_p, b_color, b_opa); + work_area.y2 = cords_p->y1 + bwidth; + fill_fp(&work_area, mask_p, b_color, bopa); /*Lower border*/ work_area.y2 = cords_p->y2; - work_area.y1 = work_area.y2 - b_width; - fill_fp(&work_area, mask_p, b_color, b_opa); + work_area.y1 = work_area.y2 - bwidth; + fill_fp(&work_area, mask_p, b_color, bopa); /*Draw the a remaining rectangles if the radius is smaller then b_width */ if(length_corr != 0) { work_area.x1 = cords_p->x1; work_area.x2 = cords_p->x1 + radius; work_area.y1 = cords_p->y1 + radius + 1; - work_area.y2 = cords_p->y1 + b_width; - fill_fp(&work_area, mask_p, b_color, b_opa); + work_area.y2 = cords_p->y1 + bwidth; + fill_fp(&work_area, mask_p, b_color, bopa); work_area.x1 = cords_p->x2 - radius; work_area.x2 = cords_p->x2; work_area.y1 = cords_p->y1 + radius + 1; - work_area.y2 = cords_p->y1 + b_width; - fill_fp(&work_area, mask_p, b_color, b_opa); + work_area.y2 = cords_p->y1 + bwidth; + fill_fp(&work_area, mask_p, b_color, bopa); work_area.x1 = cords_p->x1; work_area.x2 = cords_p->x1 + radius; - work_area.y1 = cords_p->y2 - b_width; + work_area.y1 = cords_p->y2 - bwidth; work_area.y2 = cords_p->y2 - radius - 1; - fill_fp(&work_area, mask_p, b_color, b_opa); + fill_fp(&work_area, mask_p, b_color, bopa); work_area.x1 = cords_p->x2 - radius; work_area.x2 = cords_p->x2; - work_area.y1 = cords_p->y2 - b_width; + work_area.y1 = cords_p->y2 - bwidth; work_area.y2 = cords_p->y2 - radius - 1; - fill_fp(&work_area, mask_p, b_color, b_opa); + fill_fp(&work_area, mask_p, b_color, bopa); } /*If radius == 0 one px on the corners are not drawn*/ @@ -893,25 +890,25 @@ static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * work_area.x2 = cords_p->x1; work_area.y1 = cords_p->y1; work_area.y2 = cords_p->y1; - fill_fp(&work_area, mask_p, b_color, b_opa); + fill_fp(&work_area, mask_p, b_color, bopa); work_area.x1 = cords_p->x2; work_area.x2 = cords_p->x2; work_area.y1 = cords_p->y1; work_area.y2 = cords_p->y1; - fill_fp(&work_area, mask_p, b_color, b_opa); + fill_fp(&work_area, mask_p, b_color, bopa); work_area.x1 = cords_p->x1; work_area.x2 = cords_p->x1; work_area.y1 = cords_p->y2; work_area.y2 = cords_p->y2; - fill_fp(&work_area, mask_p, b_color, b_opa); + fill_fp(&work_area, mask_p, b_color, bopa); work_area.x1 = cords_p->x2; work_area.x2 = cords_p->x2; work_area.y1 = cords_p->y2; work_area.y2 = cords_p->y2; - fill_fp(&work_area, mask_p, b_color, b_opa); + fill_fp(&work_area, mask_p, b_color, bopa); } } @@ -923,15 +920,15 @@ static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * * @param rects_p pointer to a rectangle style * @param opa opacity of the rectangle (0..255) */ -static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa) +static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p) { - uint16_t radius = rects_p->round; - uint16_t b_width = rects_p->bwidth; - color_t b_color = rects_p->bcolor; - opa_t b_opa = (uint16_t)((uint16_t) opa * rects_p->bopa ) / 100; + uint16_t radius = rects_p->radius; + uint16_t bwidth = rects_p->bwidth; + color_t bcolor = rects_p->bcolor; + opa_t bopa = (uint16_t)((uint16_t) rects_p->base.opa * rects_p->bopa ) >> 8; - /*0 px border width drawn as 1 px, so decrement the b_width*/ - b_width--; + /*0 px border width drawn as 1 px, so decrement the bwidth*/ + bwidth--; cord_t width = area_get_width(cords_p); cord_t height = area_get_height(cords_p); @@ -961,7 +958,7 @@ static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * ma point_t cir_in; cord_t tmp_in; - cord_t radius_in = radius - b_width; + cord_t radius_in = radius - bwidth; if(radius_in < 0){ radius_in = 0; @@ -989,26 +986,26 @@ static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * ma circ_area.x2 = rb_origo.x + CIRC_OCT1_X(cir_out); circ_area.y1 = rb_origo.y + CIRC_OCT1_Y(cir_out); circ_area.y2 = rb_origo.y + CIRC_OCT1_Y(cir_out); - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); circ_area.x1 = rb_origo.x + CIRC_OCT2_X(cir_out); circ_area.x2 = rb_origo.x + CIRC_OCT2_X(cir_out); circ_area.y1 = rb_origo.y + CIRC_OCT2_Y(cir_out)- act_w1; circ_area.y2 = rb_origo.y + CIRC_OCT2_Y(cir_out); - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); /*Draw the octets to the left bottom corner*/ circ_area.x1 = lb_origo.x + CIRC_OCT3_X(cir_out); circ_area.x2 = lb_origo.x + CIRC_OCT3_X(cir_out); circ_area.y1 = lb_origo.y + CIRC_OCT3_Y(cir_out) - act_w2; circ_area.y2 = lb_origo.y + CIRC_OCT3_Y(cir_out); - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); circ_area.x1 = lb_origo.x + CIRC_OCT4_X(cir_out); circ_area.x2 = lb_origo.x + CIRC_OCT4_X(cir_out) + act_w1; circ_area.y1 = lb_origo.y + CIRC_OCT4_Y(cir_out); circ_area.y2 = lb_origo.y + CIRC_OCT4_Y(cir_out); - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); /*Draw the octets to the left top corner*/ /*Don't draw if the lines are common in the middle*/ @@ -1017,21 +1014,21 @@ static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * ma circ_area.x2 = lt_origo.x + CIRC_OCT5_X(cir_out) + act_w2; circ_area.y1 = lt_origo.y + CIRC_OCT5_Y(cir_out); circ_area.y2 = lt_origo.y + CIRC_OCT5_Y(cir_out); - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); } circ_area.x1 = lt_origo.x + CIRC_OCT6_X(cir_out); circ_area.x2 = lt_origo.x + CIRC_OCT6_X(cir_out); circ_area.y1 = lt_origo.y + CIRC_OCT6_Y(cir_out); circ_area.y2 = lt_origo.y + CIRC_OCT6_Y(cir_out) + act_w1; - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); /*Draw the octets to the right top corner*/ circ_area.x1 = rt_origo.x + CIRC_OCT7_X(cir_out); circ_area.x2 = rt_origo.x + CIRC_OCT7_X(cir_out); circ_area.y1 = rt_origo.y + CIRC_OCT7_Y(cir_out); circ_area.y2 = rt_origo.y + CIRC_OCT7_Y(cir_out) + act_w2; - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); /*Don't draw if the lines are common in the middle*/ if(rb_origo.y + CIRC_OCT1_Y(cir_out) > rt_origo.y + CIRC_OCT8_Y(cir_out)) { @@ -1039,7 +1036,7 @@ static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * ma circ_area.x2 = rt_origo.x + CIRC_OCT8_X(cir_out); circ_area.y1 = rt_origo.y + CIRC_OCT8_Y(cir_out); circ_area.y2 = rt_origo.y + CIRC_OCT8_Y(cir_out); - fill_fp(&circ_area, mask_p, b_color, b_opa); + fill_fp(&circ_area, mask_p, bcolor, bopa); } circ_next(&cir_out, &tmp_out); diff --git a/lv_draw/lv_draw.h b/lv_draw/lv_draw.h index 728e9213a..eb4b94ca4 100644 --- a/lv_draw/lv_draw.h +++ b/lv_draw/lv_draw.h @@ -1,5 +1,5 @@ /** - * @file lv_draw_img.h + * @file lv_draw.h * */ @@ -35,11 +35,9 @@ * @param cords_p the coordinates of the rectangle * @param mask_p the rectangle will be drawn only in this mask * @param rects_p pointer to a rectangle style - * @param opa the opacity of the rectangle (0..255) */ #if USE_LV_RECT != 0 -void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, - const lv_rects_t * rects_p, opa_t opa); +void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p); #endif @@ -60,13 +58,12 @@ void lv_draw_triangle(const point_t * points, const area_t * mask_p, color_t col * @param cords_p coordinates of the label * @param mask_p the label will be drawn only in this area * @param labels_p pointer to a label style - * @param opa opacity of the text (0..255) * @param txt 0 terminated text to write * @param flags settings for the text from 'txt_flag_t' enum */ #if USE_LV_LABEL != 0 -void lv_draw_label(const area_t * cords_p,const area_t * mask_p, - const lv_labels_t * labels_p, opa_t opa, const char * txt, txt_flag_t flag); +void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels_t * style, + const char * txt, txt_flag_t flag); #endif /** @@ -74,11 +71,10 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, * @param cords_p the coordinates of the image * @param mask_p the image will be drawn only in this area * @param map_p pointer to a color_t array which contains the pixels of the image - * @param opa opacity of the image (0..255) */ #if USE_LV_IMG != 0 && USE_FSINT != 0 && USE_UFS != 0 void lv_draw_img(const area_t * cords_p, const area_t * mask_p, - const lv_imgs_t * imgs_p, opa_t opa, const char * fn); + const lv_imgs_t * imgs_p, const char * fn); #endif /** @@ -87,11 +83,10 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, * @param p2 second point of the line * @param mask_pthe line will be drawn only on this area * @param lines_p pointer to a line style - * @param opa opacity of the line (0..255) */ #if USE_LV_LINE != 0 void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, - const lv_lines_t * lines_p, opa_t opa); + const lv_lines_t * lines_p); #endif /********************** diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 757b6ea02..c322c0899 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -36,6 +36,7 @@ static void lv_obj_pos_child_refr(lv_obj_t * obj, cord_t x_diff, cord_t y_diff); static void lv_style_refr_core(void * style_p, lv_obj_t * obj); static void lv_obj_del_child(lv_obj_t * obj); +static void lv_objs_init(void); static bool lv_obj_design(lv_obj_t * obj, const area_t * mask_p, lv_design_mode_t mode); /********************** @@ -45,9 +46,9 @@ static lv_obj_t * def_scr = NULL; static lv_obj_t * act_scr = NULL; static ll_dsc_t scr_ll; -static lv_objs_t lv_objs_def = {.color = COLOR_MAKE(0xa0, 0xc0, 0xe0), .transp = 0}; -static lv_objs_t lv_objs_scr = {.color = LV_OBJ_DEF_SCR_COLOR, .transp = 0}; -static lv_objs_t lv_objs_transp = {.transp = 1}; +static lv_objs_t lv_objs_scr; +static lv_objs_t lv_objs_plain; +static lv_objs_t lv_objs_transp; #ifdef LV_IMG_DEF_WALLPAPER @@ -136,7 +137,6 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy) /*Set appearance*/ new_obj->style_p = lv_objs_get(LV_OBJS_SCR, NULL); - new_obj->opa = OPA_COVER; /*Set virtual functions*/ lv_obj_set_signal_f(new_obj, lv_obj_signal); @@ -178,8 +178,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy) new_obj->ext_size = 0; /*Set appearance*/ - new_obj->style_p = lv_objs_get(LV_OBJS_DEF, NULL); - new_obj->opa = OPA_COVER; + new_obj->style_p = lv_objs_get(LV_OBJS_PLAIN, NULL); /*Set virtual functions*/ lv_obj_set_signal_f(new_obj, lv_obj_signal); @@ -209,8 +208,6 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy) area_cpy(&new_obj->cords, ©->cords); new_obj->ext_size = copy->ext_size; - new_obj->opa = copy->opa; - /*Set free data*/ new_obj->free_num = copy->free_num; #if LV_OBJ_FREE_P != 0 @@ -330,15 +327,23 @@ bool lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) */ lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p) { - lv_objs_t *style_p; + static bool style_inited = false; + + /*Make the style initialization if it is not done yet*/ + if(style_inited == false) { + lv_objs_init(); + style_inited = true; + } + + lv_objs_t * style_p; switch(style) { - case LV_OBJS_DEF: - style_p = &lv_objs_def; - break; case LV_OBJS_SCR: style_p = &lv_objs_scr; break; + case LV_OBJS_PLAIN: + style_p = &lv_objs_plain; + break; case LV_OBJS_TRANSP: style_p = &lv_objs_transp; break; @@ -346,10 +351,7 @@ lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p) style_p = NULL; } - if(copy_p != NULL) { - if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_objs_t)); - else memcpy(copy_p, &lv_objs_def, sizeof(lv_objs_t)); - } + if(copy_p != NULL) memcpy(copy_p, style_p, sizeof(lv_objs_t)); return style_p; } @@ -843,38 +845,6 @@ void * lv_obj_iso_style(lv_obj_t * obj, uint32_t style_size) return obj->style_p; } -/** - * Set the opacity of an object - * @param obj pointer to an object - * @param opa 0 (transparent) .. 255(fully cover) - */ -void lv_obj_set_opa(lv_obj_t * obj, uint8_t opa) -{ - obj->opa = opa; - - lv_obj_inv(obj); -} - -/** - * Set the opacity of an object and all of its children - * @param obj pointer to an object - * @param opa 0 (transparent) .. 255(fully cover) - */ -void lv_obj_set_opar(lv_obj_t * obj, uint8_t opa) -{ - lv_obj_t * i; - - LL_READ(obj->child_ll, i) { - lv_obj_set_opar(i, opa); - } - - /*Set the opacity is the object is not protected*/ - if(lv_obj_is_protected(obj, LV_PROTECT_OPA) == false) obj->opa = opa; - - lv_obj_inv(obj); -} - - /** * Notify an object about its style is modified * @param obj pointer to an object @@ -889,7 +859,7 @@ void lv_obj_refr_style(lv_obj_t * obj) /** * Notify all object if a style is modified - * @param style pinter to a style. Only objects with this style will be notified + * @param style pointer to a style. Only the objects with this style will be notified * (NULL to notify all objects) */ void lv_style_refr_all(void * style) @@ -1117,11 +1087,6 @@ void lv_obj_anim(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t a.start = lv_obj_get_height(par); a.end = lv_obj_get_y(obj); break; - case LV_ANIM_FADE: - a.fp = (void(*)(void * , int32_t))lv_obj_set_opar; - a.start = OPA_TRANSP; - a.end = OPA_COVER; - break; case LV_ANIM_GROW_H: a.fp = (void(*)(void * , int32_t))lv_obj_set_width; a.start = 0; @@ -1321,16 +1286,6 @@ void * lv_obj_get_style(lv_obj_t * obj) return obj->style_p; } -/** - * Get the opacity of an object - * @param obj pointer to an object - * @return 0 (transparent) .. 255 (fully cover) - */ -opa_t lv_obj_get_opa(lv_obj_t * obj) -{ - return obj->opa; -} - /*----------------- * Attribute get *----------------*/ @@ -1505,16 +1460,13 @@ static bool lv_obj_design(lv_obj_t * obj, const area_t * mask_p, lv_design_mode cover = area_is_in(mask_p, &obj->cords); return cover; } else if(mode == LV_DESIGN_DRAW_MAIN) { - lv_objs_t * objs_p = lv_obj_get_style(obj); - - opa_t opa = lv_obj_get_opa(obj); - color_t color = objs_p->color; + lv_objs_t * style = lv_obj_get_style(obj); /*Simply draw a rectangle*/ #if LV_VDB_SIZE == 0 - lv_rfill(&obj->cords, mask_p, color, opa); + lv_rfill(&obj->cords, mask_p, style->color, style->opa); #else - lv_vfill(&obj->cords, mask_p, color, opa); + lv_vfill(&obj->cords, mask_p, style->color, style->opa); #endif } return true; @@ -1596,4 +1548,14 @@ static void lv_obj_del_child(lv_obj_t * obj) } +static void lv_objs_init(void) +{ + lv_objs_scr.color = LV_OBJ_DEF_SCR_COLOR; + lv_objs_scr.opa = OPA_COVER; + lv_objs_plain.color =COLOR_MAKE(0x88, 0xaf, 0xcb); + lv_objs_plain.opa = OPA_COVER; + + lv_objs_transp.color = lv_objs_plain.color; + lv_objs_transp.opa = OPA_TRANSP; +} diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index 5e3bd7fbf..47d3aa05d 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -106,9 +106,6 @@ typedef struct __LV_OBJ_T cord_t ext_size; /*EXTtend the size of the object in every direction. Used to draw shadow, shine etc.*/ uint8_t free_num; /*Application specific identifier (set it freely)*/ - opa_t opa; - - }lv_obj_t; /*Protect some attributes (max. 8 bit)*/ @@ -150,20 +147,19 @@ typedef enum typedef struct { color_t color; - uint8_t transp :1; + opa_t opa; }lv_objs_t; typedef enum { - LV_OBJS_DEF, LV_OBJS_SCR, + LV_OBJS_PLAIN, LV_OBJS_TRANSP, }lv_objs_builtin_t; typedef enum { LV_ANIM_NONE = 0, - LV_ANIM_FADE, /*Animate the opacity*/ LV_ANIM_FLOAT_TOP, /*Float from/to the top*/ LV_ANIM_FLOAT_LEFT, /*Float from/to the left*/ LV_ANIM_FLOAT_BOTTOM, /*Float from/to the bottom*/ @@ -377,20 +373,6 @@ void lv_obj_set_style(lv_obj_t * obj, void * style); */ void * lv_obj_iso_style(lv_obj_t * obj, uint32_t style_size); -/** - * Set the opacity of an object - * @param obj pointer to an object - * @param opa 0 (transparent) .. 255(fully cover) - */ -void lv_obj_set_opa(lv_obj_t * obj, uint8_t opa); - -/** - * Set the opacity of an object and all of its children - * @param obj pointer to an object - * @param opa 0 (transparent) .. 255(fully cover) - */ -void lv_obj_set_opar(lv_obj_t * obj, uint8_t opa); - /** * Hide an object. It won't be visible and clickable. * @param obj pointer to an object @@ -589,13 +571,6 @@ cord_t lv_obj_getext_size(lv_obj_t * obj); */ void * lv_obj_get_style(lv_obj_t * obj); -/** - * Get the opacity of an object - * @param obj pointer to an object - * @return 0 (transparent) .. 255 (fully cover) - */ -opa_t lv_obj_get_opa(lv_obj_t * obj); - /** * Get the hidden attribute of an object * @param obj pointer to an object diff --git a/lv_obj/lv_refr.c b/lv_obj/lv_refr.c index 174f0382e..5bded67e3 100644 --- a/lv_obj/lv_refr.c +++ b/lv_obj/lv_refr.c @@ -316,8 +316,7 @@ static lv_obj_t * lv_refr_get_top_obj(const area_t * area_p, lv_obj_t * obj) /*If no better children check this object*/ if(found_p == NULL) { - if(obj->opa == OPA_COVER && - LV_SA(obj, lv_objs_t)->transp == 0 && + if(((lv_objs_t *)obj->style_p)->opa == OPA_COVER && obj->design_f(obj, area_p, LV_DESIGN_COVER_CHK) != false) { found_p = obj; } @@ -403,7 +402,7 @@ static void lv_refr_obj(lv_obj_t * obj, const area_t * mask_ori_p) if(union_ok != false) { /* Redraw the object */ - if(obj->opa != OPA_TRANSP && LV_SA(obj, lv_objs_t)->transp == 0) { + if(((lv_objs_t *)obj->style_p)->opa != OPA_TRANSP) { obj->design_f(obj, &obj_ext_mask, LV_DESIGN_DRAW_MAIN); /* tick_wait_ms(100); */ /*DEBUG: Wait after every object draw to see the order of drawing*/ } @@ -436,7 +435,7 @@ static void lv_refr_obj(lv_obj_t * obj, const area_t * mask_ori_p) } /* If all the children are redrawn make 'post draw' design */ - if(obj->opa != OPA_TRANSP && LV_SA(obj, lv_objs_t)->transp == 0) { + if(((lv_objs_t *)obj->style_p)->opa != OPA_TRANSP) { obj->design_f(obj, &obj_ext_mask, LV_DESIGN_DRAW_POST); } } diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index ffadb9157..510fd3750 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -30,15 +30,15 @@ * STATIC PROTOTYPES **********************/ static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t mode); -static void lv_btn_style_load(lv_obj_t * btn, lv_rects_t * new_rects); + static void lv_btns_init(void); /********************** * STATIC VARIABLES **********************/ static lv_btns_t lv_btns_def; -static lv_btns_t lv_btns_transp; static lv_btns_t lv_btns_border; +static lv_btns_t lv_btns_transp; static lv_design_f_t ancestor_design_f; @@ -110,6 +110,13 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) { bool valid; + /*On style change preload the style for the rectangle signal*/ + lv_btn_ext_t * ext = lv_obj_get_ext(btn); + lv_btns_t * style = lv_obj_get_style(btn); + if(sign == LV_SIGNAL_STYLE_CHG) { + memcpy(&style->current, &style->state_style[ext->state], sizeof(lv_rects_t)); + } + /* Include the ancient signal function */ valid = lv_rect_signal(btn, sign, param); @@ -117,7 +124,6 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) * make the object specific signal handling */ if(valid != false) { lv_btn_state_t state = lv_btn_get_state(btn); - lv_btn_ext_t * ext = lv_obj_get_ext(btn); bool tgl = lv_btn_get_tgl(btn); switch (sign) { @@ -125,8 +131,8 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) /*Refresh the state*/ if(ext->state == LV_BTN_STATE_REL) { lv_btn_set_state(btn, LV_BTN_STATE_PR); - } else if(ext->state == LV_BTN_STATE_TGL_REL) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR); + } else if(ext->state == LV_BTN_STATE_TREL) { + lv_btn_set_state(btn, LV_BTN_STATE_TPR); } ext->lpr_exec = 0; @@ -139,17 +145,15 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) case LV_SIGNAL_PRESS_LOST: /*Refresh the state*/ if(ext->state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); - else if(ext->state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + else if(ext->state == LV_BTN_STATE_TPR) lv_btn_set_state(btn, LV_BTN_STATE_TREL); - lv_obj_inv(btn); break; case LV_SIGNAL_PRESSING: /*When the button begins to drag revert pressed states to released*/ if(lv_dispi_is_dragging(param) != false) { if(ext->state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); - else if(ext->state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + else if(ext->state == LV_BTN_STATE_TPR) lv_btn_set_state(btn, LV_BTN_STATE_TREL); } - lv_obj_inv(btn); break; case LV_SIGNAL_RELEASED: @@ -158,11 +162,11 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) if(lv_dispi_is_dragging(param) == false && ext->lpr_exec == 0) { if(ext->state == LV_BTN_STATE_PR && tgl == false) { lv_btn_set_state(btn, LV_BTN_STATE_REL); - } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == false) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } else if(ext->state == LV_BTN_STATE_TPR && tgl == false) { + lv_btn_set_state(btn, LV_BTN_STATE_TREL); } else if(ext->state == LV_BTN_STATE_PR && tgl == true) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); - } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == true) { + lv_btn_set_state(btn, LV_BTN_STATE_TREL); + } else if(ext->state == LV_BTN_STATE_TPR && tgl == true) { lv_btn_set_state(btn, LV_BTN_STATE_REL); } @@ -172,10 +176,9 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) } else { /*If dragged change back the state*/ if(ext->state == LV_BTN_STATE_PR) { lv_btn_set_state(btn, LV_BTN_STATE_REL); - } else if(ext->state == LV_BTN_STATE_TGL_PR) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + } else if(ext->state == LV_BTN_STATE_TPR) { + lv_btn_set_state(btn, LV_BTN_STATE_TREL); } - lv_obj_inv(btn); } break; @@ -227,7 +230,9 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) lv_btn_ext_t * ext = lv_obj_get_ext(btn); if(ext->state != state) { ext->state = state; - lv_obj_inv(btn); + lv_btns_t * style = lv_obj_get_style(btn); + memcpy(&style->current, &style->state_style[ext->state], sizeof(lv_rects_t)); + lv_obj_refr_style(btn); } } @@ -278,6 +283,7 @@ void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_action_t lpr_rep_action) ext->lpr_rep_action = lpr_rep_action; } + /*===================== * Getter functions *====================*/ @@ -328,20 +334,17 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy) case LV_BTNS_DEF: style_p = &lv_btns_def; break; + case LV_BTNS_BORDER: + style_p = &lv_btns_border; + break; case LV_BTNS_TRANSP: style_p = &lv_btns_transp; break; - case LV_BTNS_BORDER: - style_p = &lv_btns_border; - break; default: style_p = &lv_btns_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_btns_t)); - else memcpy(copy, &lv_btns_def, sizeof(lv_btns_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_btns_t)); return style_p; } @@ -349,7 +352,6 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy) /********************** * STATIC FUNCTIONS **********************/ - /** * Handle the drawing related tasks of the buttons * @param btn pointer to a button object @@ -368,13 +370,13 @@ static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t /*Temporally set a rectangle style for the button to look like as rectangle*/ lv_rects_t rects_tmp; lv_btns_t * btns_tmp = lv_obj_get_style(btn); + lv_btn_ext_t * ext = lv_obj_get_ext(btn); bool ret = false; - lv_btn_style_load(btn, &rects_tmp); - if(rects_tmp.objs.transp == 0) { - btn->style_p = &rects_tmp; - ret = ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/ - btn->style_p = btns_tmp; /*Reload the original button style*/ - } + memcpy(&rects_tmp, &btns_tmp->state_style[ext->state], sizeof(lv_rects_t)); + btn->style_p = &rects_tmp; + ret = ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/ + btn->style_p = btns_tmp; /*Reload the original button style*/ + return ret; } else if(mode == LV_DESIGN_DRAW_MAIN || mode == LV_DESIGN_DRAW_POST) { area_t area; @@ -383,143 +385,67 @@ static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t /*Temporally set a rectangle style for the button to draw it as rectangle*/ lv_rects_t rects_tmp; lv_btns_t * btns_tmp = lv_obj_get_style(btn); - lv_btn_style_load(btn, &rects_tmp); - if(rects_tmp.objs.transp == 0) { - btn->style_p = &rects_tmp; - ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/ - btn->style_p = btns_tmp; /*Reload the original button style*/ - } + lv_btn_ext_t * ext = lv_obj_get_ext(btn); + memcpy(&rects_tmp, &btns_tmp->state_style[ext->state], sizeof(lv_rects_t)); + btn->style_p = &rects_tmp; + ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/ + btn->style_p = btns_tmp; /*Reload the original button style*/ + } return true; } -/** - * Crate a rectangle style according to the state of the button - * @param btn pointer to a button object - * @param new_rects load the style here (pointer to a rectangle style) - */ -static void lv_btn_style_load(lv_obj_t * btn, lv_rects_t * new_rects) -{ - lv_btn_state_t state = lv_btn_get_state(btn); - lv_btns_t * style = lv_obj_get_style(btn); - /*Load the style*/ - memcpy(new_rects, &style->rects, sizeof(lv_rects_t)); - new_rects->objs.color = style->mcolor[state]; - new_rects->gcolor = style->gcolor[state]; - new_rects->bcolor = style->bcolor[state]; - new_rects->lcolor = style->lcolor[state]; - new_rects->empty = style->flags[state].empty; - new_rects->objs.transp = style->flags[state].transp; - - if(style->flags[state].light_en != 0) new_rects->light = style->rects.light; - else new_rects->light = 0; - -} /** * Initialize the button styles */ static void lv_btns_init(void) { - /*Default style*/ - lv_btns_def.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x60, 0x88, 0xb0); - lv_btns_def.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_btns_def.bcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0xff, 0xff, 0xff); - lv_btns_def.lcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_btns_def.flags[LV_BTN_STATE_REL].light_en = 0; - lv_btns_def.flags[LV_BTN_STATE_REL].transp = 0; - lv_btns_def.flags[LV_BTN_STATE_REL].empty = 0; - lv_btns_def.mcolor[LV_BTN_STATE_PR] =COLOR_MAKE(0x50, 0x68, 0x80); - lv_btns_def.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x18, 0x20, 0x28); - lv_btns_def.bcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x60, 0x80, 0xa0); - lv_btns_def.lcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_btns_def.flags[LV_BTN_STATE_PR].light_en = 0; - lv_btns_def.flags[LV_BTN_STATE_PR].transp = 0; - lv_btns_def.flags[LV_BTN_STATE_PR].empty = 0; - - lv_btns_def.mcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x40, 0x60, 0x80); - lv_btns_def.gcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x10, 0x18, 0x20); - lv_btns_def.bcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_btns_def.lcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_btns_def.flags[LV_BTN_STATE_TGL_REL].light_en = 1; - lv_btns_def.flags[LV_BTN_STATE_TGL_REL].transp = 0; - lv_btns_def.flags[LV_BTN_STATE_TGL_REL].empty = 0; - - lv_btns_def.mcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x60, 0x80, 0xa0); - lv_btns_def.gcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_btns_def.bcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_btns_def.lcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_btns_def.flags[LV_BTN_STATE_TGL_PR].light_en = 1; - lv_btns_def.flags[LV_BTN_STATE_TGL_PR].transp = 0; - lv_btns_def.flags[LV_BTN_STATE_TGL_PR].empty = 0; - - lv_btns_def.mcolor[LV_BTN_STATE_INA] = COLOR_SILVER; - lv_btns_def.gcolor[LV_BTN_STATE_INA] = COLOR_GRAY; - lv_btns_def.bcolor[LV_BTN_STATE_INA] = COLOR_WHITE; - lv_btns_def.lcolor[LV_BTN_STATE_INA] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_btns_def.flags[LV_BTN_STATE_INA].light_en = 0; - lv_btns_def.flags[LV_BTN_STATE_INA].transp= 0; - lv_btns_def.flags[LV_BTN_STATE_INA].empty = 0; - - lv_btns_def.rects.objs.color = lv_btns_def.mcolor[LV_BTN_STATE_REL]; - lv_btns_def.rects.gcolor = lv_btns_def.gcolor[LV_BTN_STATE_REL]; - lv_btns_def.rects.bcolor = lv_btns_def.bcolor[LV_BTN_STATE_REL]; - lv_btns_def.rects.objs.transp = 0; - lv_btns_def.rects.empty = 0; - lv_btns_def.rects.light = 6 * LV_DOWNSCALE; - lv_btns_def.rects.bwidth = 2 * LV_DOWNSCALE; - lv_btns_def.rects.bopa = 70; - lv_btns_def.rects.empty = 0; - lv_btns_def.rects.round = 4 * LV_DOWNSCALE; - lv_btns_def.rects.hpad = 10 * LV_DOWNSCALE; - lv_btns_def.rects.vpad = 15 * LV_DOWNSCALE; - lv_btns_def.rects.opad = 10 * LV_DOWNSCALE; - - /*Transparent style*/ - memcpy(&lv_btns_transp, &lv_btns_def, sizeof(lv_btns_t)); - lv_btns_transp.rects.bwidth = 0; - lv_btns_transp.flags[LV_BTN_STATE_REL].transp = 1; - lv_btns_transp.flags[LV_BTN_STATE_REL].empty = 1; - lv_btns_transp.flags[LV_BTN_STATE_REL].light_en = 0; - - lv_btns_transp.flags[LV_BTN_STATE_PR].transp = 1; - lv_btns_transp.flags[LV_BTN_STATE_PR].empty = 1; - lv_btns_transp.flags[LV_BTN_STATE_PR].light_en = 0; - lv_btns_transp.flags[LV_BTN_STATE_TGL_REL].transp = 1; - lv_btns_transp.flags[LV_BTN_STATE_TGL_REL].empty = 1; - lv_btns_transp.flags[LV_BTN_STATE_TGL_REL].light_en = 0; - lv_btns_transp.flags[LV_BTN_STATE_TGL_PR].transp = 1; - lv_btns_transp.flags[LV_BTN_STATE_TGL_PR].empty = 1; - lv_btns_transp.flags[LV_BTN_STATE_TGL_PR].light_en = 0; - lv_btns_transp.flags[LV_BTN_STATE_INA].transp = 1; - lv_btns_transp.flags[LV_BTN_STATE_INA].empty = 1; - lv_btns_transp.flags[LV_BTN_STATE_INA].light_en = 0; + /*Default style*/ + lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_REL]); + lv_btns_def.state_style[LV_BTN_STATE_REL].base.color = COLOR_MAKE(0xcc, 0xe0, 0xf5); + lv_btns_def.state_style[LV_BTN_STATE_REL].gcolor = COLOR_MAKE(0xa6, 0xc9, 0xed); + lv_btns_def.state_style[LV_BTN_STATE_REL].bcolor = COLOR_MAKE(0x33, 0x99, 0xff); + lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_PR]); + lv_btns_def.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0xa6, 0xc9, 0xed); + lv_btns_def.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0x60, 0x88, 0xb0); + lv_btns_def.state_style[LV_BTN_STATE_PR].bcolor = COLOR_MAKE(0x33, 0x99, 0xff); + lv_btns_def.state_style[LV_BTN_STATE_PR].swidth = 3 * lv_btns_def.state_style[LV_BTN_STATE_REL].swidth / 4; + lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_TREL]); + lv_btns_def.state_style[LV_BTN_STATE_TREL].base.color = COLOR_MAKE(0xff, 0xed, 0xd3); + lv_btns_def.state_style[LV_BTN_STATE_TREL].gcolor = COLOR_MAKE(0xfc, 0xc7, 0x7a); + lv_btns_def.state_style[LV_BTN_STATE_TREL].bcolor = COLOR_MAKE(0xff, 0x90, 0x00); + lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_TPR]); + lv_btns_def.state_style[LV_BTN_STATE_TPR].base.color = COLOR_MAKE(0xfc, 0xc7, 0x7a); + lv_btns_def.state_style[LV_BTN_STATE_TPR].gcolor = COLOR_MAKE(0xdd, 0x8a, 0x4e); + lv_btns_def.state_style[LV_BTN_STATE_TPR].bcolor = COLOR_MAKE(0xff, 0x90, 0x00); + lv_btns_def.state_style[LV_BTN_STATE_TPR].swidth = 3 * lv_btns_def.state_style[LV_BTN_STATE_TREL].swidth / 4; + lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_INA]); + lv_btns_def.state_style[LV_BTN_STATE_INA].base.color = COLOR_MAKE(0xe0, 0xe0, 0xe0); + lv_btns_def.state_style[LV_BTN_STATE_INA].gcolor = lv_btns_def.state_style[LV_BTN_STATE_INA].base.color; + lv_btns_def.state_style[LV_BTN_STATE_INA].bcolor = COLOR_MAKE(0x80, 0x80, 0x80); - /*Border style*/ - memcpy(&lv_btns_border, &lv_btns_def, sizeof(lv_btns_t)); - lv_btns_border.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; - lv_btns_border.bcolor[LV_BTN_STATE_PR] = COLOR_BLACK; - lv_btns_border.bcolor[LV_BTN_STATE_TGL_REL] = COLOR_BLACK; - lv_btns_border.bcolor[LV_BTN_STATE_TGL_PR] = COLOR_BLACK; - lv_btns_border.bcolor[LV_BTN_STATE_INA] = COLOR_GRAY; - lv_btns_border.flags[LV_BTN_STATE_REL].empty = 1; - lv_btns_border.flags[LV_BTN_STATE_PR].empty = 0; - lv_btns_border.flags[LV_BTN_STATE_TGL_REL].empty = 0; - lv_btns_border.flags[LV_BTN_STATE_TGL_PR].empty = 0; - lv_btns_border.flags[LV_BTN_STATE_INA].empty = 1; - lv_btns_border.flags[LV_BTN_STATE_REL].light_en = 0; - lv_btns_border.flags[LV_BTN_STATE_PR].light_en = 0; - lv_btns_border.flags[LV_BTN_STATE_TGL_REL].light_en = 0; - lv_btns_border.flags[LV_BTN_STATE_TGL_PR].light_en = 0; - lv_btns_border.flags[LV_BTN_STATE_INA].light_en = 0; - lv_btns_border.rects.bwidth = 1 * LV_DOWNSCALE; - lv_btns_border.rects.bopa = 50; - lv_btns_border.rects.round = 4 * LV_DOWNSCALE; - lv_btns_border.rects.hpad = 10 * LV_DOWNSCALE; - lv_btns_border.rects.vpad = 10 * LV_DOWNSCALE; + /*Border style*/ + lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_REL]); + lv_btns_border.state_style[LV_BTN_STATE_REL].bcolor = COLOR_MAKE(0x20, 0x20, 0x20); + lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_PR]); + lv_btns_border.state_style[LV_BTN_STATE_PR].bcolor = COLOR_MAKE(0x60, 0x60, 0x60); + lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_TREL]); + lv_btns_border.state_style[LV_BTN_STATE_TREL].bcolor = COLOR_MAKE(0x00, 0x33, 0xff); + lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_TPR]); + lv_btns_border.state_style[LV_BTN_STATE_TPR].bcolor = COLOR_MAKE(0x00, 0x33, 0x99); + lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_INA]); + lv_btns_border.state_style[LV_BTN_STATE_INA].bcolor = COLOR_MAKE(0xa0, 0xa0, 0xa0); + + /*Transparent style*/ + lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_REL]); + lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_PR]); + lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_TREL]); + lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_TPR]); + lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_INA]); } #endif diff --git a/lv_objx/lv_btn.h b/lv_objx/lv_btn.h index 5d5b99060..924f27346 100644 --- a/lv_objx/lv_btn.h +++ b/lv_objx/lv_btn.h @@ -32,8 +32,8 @@ typedef enum { LV_BTN_STATE_PR, LV_BTN_STATE_REL, - LV_BTN_STATE_TGL_PR, - LV_BTN_STATE_TGL_REL, + LV_BTN_STATE_TPR, + LV_BTN_STATE_TREL, LV_BTN_STATE_INA, LV_BTN_STATE_NUM, }lv_btn_state_t; @@ -53,32 +53,20 @@ typedef struct uint8_t lpr_exec :1; /*1: long press action executed (Not for user)*/ }lv_btn_ext_t; -/*Bits of 'flag' in 'lv_btns_t'*/ -typedef struct -{ - uint8_t light_en :1; - uint8_t transp :1; - uint8_t empty :1; -}lv_btns_bits_t; - /*Style of button*/ typedef struct { - lv_rects_t rects; /*Style of ancestor*/ + lv_rects_t current; /*Current style according to the state. Library use this. Style of ancestor*/ /*New style element for this type */ - color_t mcolor[LV_BTN_STATE_NUM]; - color_t gcolor[LV_BTN_STATE_NUM]; - color_t bcolor[LV_BTN_STATE_NUM]; - color_t lcolor[LV_BTN_STATE_NUM]; - lv_btns_bits_t flags[LV_BTN_STATE_NUM]; + lv_rects_t state_style[LV_BTN_STATE_NUM]; }lv_btns_t; /*Built-in styles of button*/ typedef enum { LV_BTNS_DEF, - LV_BTNS_TRANSP, LV_BTNS_BORDER, + LV_BTNS_TRANSP, }lv_btns_builtin_t; diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index ea8893563..88d49439e 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -215,9 +215,9 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) /*Set size and positions of the buttons*/ lv_btnms_t * btnms = lv_obj_get_style(btnm); - cord_t max_w = lv_obj_get_width(btnm) - 2 * btnms->rects.hpad; - cord_t max_h = lv_obj_get_height(btnm) - 2 * btnms->rects.vpad; - cord_t act_y = btnms->rects.vpad; + cord_t max_w = lv_obj_get_width(btnm) - 2 * btnms->bg.hpad; + cord_t max_h = lv_obj_get_height(btnm) - 2 * btnms->bg.vpad; + cord_t act_y = btnms->bg.vpad; /*Count the lines to calculate button height*/ uint8_t line_cnt = 1; @@ -226,7 +226,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) if(strcmp(map[li], "\n") == 0) line_cnt ++; } - cord_t btn_h = max_h - ((line_cnt - 1) * btnms->rects.opad); + cord_t btn_h = max_h - ((line_cnt - 1) * btnms->bg.opad); btn_h = btn_h / line_cnt; /* Count the units and the buttons in a line @@ -253,11 +253,11 @@ 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 width of all units*/ - cord_t all_unit_w = max_w - ((btn_cnt-1) * btnms->rects.opad); + cord_t all_unit_w = max_w - ((btn_cnt-1) * btnms->bg.opad); /*Set the button size and positions and set the texts*/ uint16_t i; - cord_t act_x = btnms->rects.hpad; + cord_t act_x = btnms->bg.hpad; cord_t act_unit_w; unit_act_cnt = 0; for(i = 0; i < btn_cnt; i++) { @@ -267,7 +267,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) act_unit_w = (all_unit_w * lv_btnm_get_width_unit(map_p_tmp[i])) / unit_cnt; /*Always recalculate act_x because of rounding errors */ - act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * btnms->rects.opad + btnms->rects.hpad; + act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * btnms->bg.opad + btnms->bg.hpad; area_set(&ext->btn_areas[btn_i], act_x, act_y, @@ -280,7 +280,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) btn_i ++; } } - act_y += btn_h + btnms->rects.opad; + act_y += btn_h + btnms->bg.opad; if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/ map_p_tmp = &map_p_tmp[btn_cnt + 1]; /*Set the map to the next line*/ i_tot ++; /*Skip the '\n'*/ @@ -350,10 +350,7 @@ lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy) style_p = &lv_btnms_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_btnms_t)); - else memcpy(copy, &lv_btnms_def, sizeof(lv_btnms_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_btnms_t)); return style_p; } @@ -405,30 +402,19 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ btn_h = area_get_height(&area_tmp); /*Load the style*/ - lv_rects_t new_rects; lv_btn_state_t state; state = ext->btn_pr == btn_i ? LV_BTN_STATE_PR : LV_BTN_STATE_REL; - memcpy(&new_rects, &style->btns, sizeof(lv_rects_t)); - new_rects.objs.color = style->btns.mcolor[state]; - new_rects.gcolor = style->btns.gcolor[state]; - new_rects.bcolor = style->btns.bcolor[state]; - new_rects.lcolor = style->btns.lcolor[state]; - new_rects.empty = style->btns.flags[state].empty; - new_rects.objs.transp = style->btns.flags[state].transp; - if(style->btns.flags[state].light_en != 0) new_rects.light = style->rects.light; - else new_rects.light = 0; - - lv_draw_rect(&area_tmp, mask, &new_rects, OPA_COVER); + lv_draw_rect(&area_tmp, mask, &style->btn.state_style[state]); /*Search the next valid text in the map*/ while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; /*Calculate the size of the text*/ - const font_t * font = font_get(style->labels.font); + const font_t * font = style->label.font; point_t txt_size; txt_get_size(&txt_size, ext->map_p[txt_i], font, - style->labels.letter_space, style->labels.line_space, + style->label.letter_space, style->label.line_space, area_get_width(&area_btnm), TXT_FLAG_NONE); area_tmp.x1 += (btn_w - txt_size.x) / 2; @@ -436,7 +422,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ area_tmp.x2 = area_tmp.x1 + txt_size.x; area_tmp.y2 = area_tmp.y1 + txt_size.y; - lv_draw_label(&area_tmp, mask, &style->labels, OPA_COVER, ext->map_p[txt_i], TXT_FLAG_NONE); + lv_draw_label(&area_tmp, mask, &style->label, ext->map_p[txt_i], TXT_FLAG_NONE); txt_i ++; } } @@ -452,9 +438,16 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ static void lv_btnms_init(void) { /*Default style*/ - lv_rects_get(LV_RECTS_DEF, &lv_btnms_def.rects); /*Background rectangle style*/ - lv_btns_get(LV_BTNS_DEF, &lv_btnms_def.btns); /*Button style*/ - lv_labels_get(LV_LABELS_BTN, &lv_btnms_def.labels); /*BUtton label style*/ + lv_rects_get(LV_RECTS_PLAIN, &lv_btnms_def.bg); /*Background rectangle style*/ + lv_btnms_def.bg.vpad = LV_DPI / 30; + lv_btnms_def.bg.hpad = LV_DPI / 30; + lv_btnms_def.bg.opad = LV_DPI / 30; + lv_btnms_def.bg.radius = 0; + lv_btnms_def.bg.bwidth = 0; + lv_btns_get(LV_BTNS_DEF, &lv_btnms_def.btn); /*Button style*/ + lv_btnms_def.btn.state_style[LV_BTN_STATE_REL].swidth = 0; + lv_btnms_def.btn.state_style[LV_BTN_STATE_PR].swidth = 0; + lv_labels_get(LV_LABELS_BTN, &lv_btnms_def.label); /*BUtton label style*/ } /** diff --git a/lv_objx/lv_btnm.h b/lv_objx/lv_btnm.h index b07e74d9c..f68020baa 100644 --- a/lv_objx/lv_btnm.h +++ b/lv_objx/lv_btnm.h @@ -43,7 +43,7 @@ typedef lv_action_res_t (*lv_btnm_callback_t) (lv_obj_t *, uint16_t); /*Data of button matrix*/ typedef struct { - lv_rect_ext_t rect; /*Ext. of ancestor*/ + lv_rect_ext_t bg; /*Ext. of ancestor*/ /*New data for this type */ const char ** map_p; /*Pointer to the current map*/ area_t * btn_areas; @@ -55,10 +55,10 @@ typedef struct /*Style of button matrix*/ typedef struct { - lv_rects_t rects; /*Style of ancestor*/ + lv_rects_t bg; /*Style of ancestor*/ /*New style element for this type */ - lv_btns_t btns; /*Style of the buttons*/ - lv_labels_t labels; /*Style of the labels on the buttons*/ + lv_btns_t btn; /*Style of the buttons*/ + lv_labels_t label; /*Style of the labels on the buttons*/ }lv_btnms_t; /*Built-in styles of button matrix*/ diff --git a/lv_objx/lv_cb.c b/lv_objx/lv_cb.c index af30f5017..64cac2d0c 100644 --- a/lv_objx/lv_cb.c +++ b/lv_objx/lv_cb.c @@ -192,10 +192,7 @@ lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy) style_p = &lv_cbs_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_cbs_t)); - else memcpy(copy, &lv_cbs_def, sizeof(lv_cbs_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_cbs_t)); return style_p; } @@ -242,51 +239,23 @@ static void lv_cbs_init(void) /*Default style*/ /*Bg style*/ - lv_btns_get(LV_RECTS_TRANSP, &lv_cbs_def.bg); - lv_cbs_def.bg.rects.hpad = 6 * LV_DOWNSCALE; - lv_cbs_def.bg.rects.vpad = 6 * LV_DOWNSCALE; - lv_cbs_def.bg.rects.opad = 5 * LV_DOWNSCALE; + lv_btns_get(LV_BTNS_TRANSP, &lv_cbs_def.bg); + lv_cbs_def.bg.state_style[LV_BTN_STATE_REL].hpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_REL].vpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_PR].hpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_PR].vpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_TREL].hpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_TREL].vpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_TPR].hpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_TPR].vpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_INA].hpad = LV_DPI / 10; + lv_cbs_def.bg.state_style[LV_BTN_STATE_INA].vpad = LV_DPI / 10; /*Bullet style*/ lv_btns_get(LV_BTNS_DEF, &lv_cbs_def.bullet); - lv_cbs_def.bullet.mcolor[LV_BTN_STATE_REL] = COLOR_WHITE; - lv_cbs_def.bullet.gcolor[LV_BTN_STATE_REL] = COLOR_SILVER; - lv_cbs_def.bullet.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; - lv_cbs_def.bullet.flags[LV_BTN_STATE_REL].light_en = 0; - - lv_cbs_def.bullet.mcolor[LV_BTN_STATE_PR] = COLOR_SILVER; - lv_cbs_def.bullet.gcolor[LV_BTN_STATE_PR] = COLOR_GRAY; - lv_cbs_def.bullet.bcolor[LV_BTN_STATE_PR] = COLOR_BLACK; - lv_cbs_def.bullet.flags[LV_BTN_STATE_PR].light_en = 0; - - lv_cbs_def.bullet.mcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_cbs_def.bullet.gcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x10, 0x20, 0x30); - lv_cbs_def.bullet.bcolor[LV_BTN_STATE_TGL_REL] = COLOR_WHITE; - lv_cbs_def.bullet.flags[LV_BTN_STATE_TGL_REL].light_en = 1; - - lv_cbs_def.bullet.mcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x50, 0x70, 0x90); - lv_cbs_def.bullet.gcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_cbs_def.bullet.bcolor[LV_BTN_STATE_TGL_PR] = COLOR_WHITE; - lv_cbs_def.bullet.flags[LV_BTN_STATE_TGL_PR].light_en = 1; - - lv_cbs_def.bullet.mcolor[LV_BTN_STATE_INA] = COLOR_SILVER; - lv_cbs_def.bullet.gcolor[LV_BTN_STATE_INA] = COLOR_GRAY; - lv_cbs_def.bullet.bcolor[LV_BTN_STATE_INA] = COLOR_WHITE; - lv_cbs_def.bullet.flags[LV_BTN_STATE_INA].light_en = 0; - - lv_cbs_def.bullet.rects.bwidth = 2 * LV_DOWNSCALE; - lv_cbs_def.bullet.rects.bopa = 70; - lv_cbs_def.bullet.rects.light = 6 * LV_DOWNSCALE; - lv_cbs_def.bullet.rects.empty = 0; - lv_cbs_def.bullet.rects.round = LV_OBJ_DEF_WIDTH / 3 / 4; - lv_cbs_def.bullet.rects.hpad = 0 * LV_DOWNSCALE; - lv_cbs_def.bullet.rects.vpad = 0 * LV_DOWNSCALE; - lv_cbs_def.bullet.rects.opad = 0 * LV_DOWNSCALE; - /*Label*/ lv_labels_get(LV_LABELS_TXT, &lv_cbs_def.label); - lv_cbs_def.label.objs.color = COLOR_MAKE(0x10, 0x18, 0x20); /*Others*/ lv_cbs_def.bullet_size = LV_OBJ_DEF_WIDTH / 3; diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index c42d109cc..13634e4f5 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -40,7 +40,6 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask); * STATIC VARIABLES **********************/ static lv_charts_t lv_charts_def; -static lv_charts_t lv_charts_transp; static lv_design_f_t ancestor_design_f; /********************** @@ -314,17 +313,11 @@ lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy) case LV_CHARTS_DEF: style_p = &lv_charts_def; break; - case LV_CHARTS_TRANSP: - style_p = &lv_charts_transp; - break; default: style_p = &lv_charts_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_charts_t)); - else memcpy(copy, &lv_charts_def, sizeof(lv_charts_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_charts_t)); return style_p; } @@ -386,14 +379,11 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask) lv_chart_ext_t * ext = lv_obj_get_ext(chart); lv_charts_t * style = lv_obj_get_style(chart); - if(style->div_lines.objs.transp != 0) return; - uint8_t div_i; point_t p1; point_t p2; cord_t w = lv_obj_get_width(chart); cord_t h = lv_obj_get_height(chart); - opa_t div_opa = (uint16_t)lv_obj_get_opa(chart) * style->div_line_opa / 100; cord_t x_ofs = chart->cords.x1; cord_t y_ofs = chart->cords.y1; p1.x = 0 + x_ofs; @@ -402,7 +392,7 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask) p1.y = (int32_t)((int32_t)h * div_i) / (ext->hdiv_num + 1); p1.y += y_ofs; p2.y = p1.y; - lv_draw_line(&p1, &p2, mask, &style->div_lines, div_opa); + lv_draw_line(&p1, &p2, mask, &style->div_line); } p1.y = 0 + y_ofs; @@ -411,7 +401,7 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask) p1.x = (int32_t)((int32_t)w * div_i) / (ext->vdiv_num + 1); p1.x += x_ofs; p2.x = p1.x; - lv_draw_line(&p1, &p2, mask, &style->div_lines, div_opa); + lv_draw_line(&p1, &p2, mask, &style->div_line); } } @@ -422,26 +412,26 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask) static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask) { lv_chart_ext_t * ext = lv_obj_get_ext(chart); - lv_charts_t * style_p = lv_obj_get_style(chart); + lv_charts_t * style = lv_obj_get_style(chart); uint8_t i; point_t p1; point_t p2; cord_t w = lv_obj_get_width(chart); cord_t h = lv_obj_get_height(chart); - opa_t opa = (uint16_t)lv_obj_get_opa(chart) * style_p->data_opa / 100; cord_t x_ofs = chart->cords.x1; cord_t y_ofs = chart->cords.y1; int32_t y_tmp; cord_t ** y_data; uint8_t dl_cnt = 0; lv_lines_t lines; - lv_lines_get(LV_LINES_CHART, &lines); + lv_lines_get(LV_LINES_DEF, &lines); + lines.width = style->width; + lines.base.opa = (uint16_t)((uint16_t)style->bg.base.opa * style->data_opa) >> 8; /*Go through all data lines*/ LL_READ_BACK(ext->dl_ll, y_data) { - lines.objs.color = style_p->color[dl_cnt]; - lines.width = style_p->width; + lines.base.color = style->color[dl_cnt]; p1.x = 0 + x_ofs; p2.x = 0 + x_ofs; @@ -459,7 +449,7 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask) y_tmp = y_tmp / (ext->ymax - ext->ymin); p2.y = h - y_tmp + y_ofs; - lv_draw_line(&p1, &p2, mask, &lines, opa); + lv_draw_line(&p1, &p2, mask, &lines); } dl_cnt++; } @@ -473,30 +463,30 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask) static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask) { lv_chart_ext_t * ext = lv_obj_get_ext(chart); - lv_charts_t * style_p = lv_obj_get_style(chart); + lv_charts_t * style = lv_obj_get_style(chart); uint8_t i; area_t cir_a; cord_t w = lv_obj_get_width(chart); cord_t h = lv_obj_get_height(chart); - opa_t opa = (uint16_t)lv_obj_get_opa(chart) * style_p->data_opa / 100; cord_t x_ofs = chart->cords.x1; cord_t y_ofs = chart->cords.y1; int32_t y_tmp; cord_t ** y_data; uint8_t dl_cnt = 0; lv_rects_t rects; - cord_t rad = style_p->width; + cord_t rad = style->width; - lv_rects_get(LV_RECTS_DEF, &rects); + lv_rects_get(LV_RECTS_PLAIN, &rects); rects.bwidth = 0; rects.empty = 0; - rects.round = LV_RECT_CIRCLE; + rects.radius = LV_RECT_CIRCLE; + rects.base.opa = (uint16_t)((uint16_t)style->bg.base.opa * style->data_opa) >> 8; /*Go through all data lines*/ LL_READ_BACK(ext->dl_ll, y_data) { - rects.objs.color = style_p->color[dl_cnt]; - rects.gcolor = color_mix(COLOR_BLACK, style_p->color[dl_cnt], style_p->dark_eff); + rects.base.color = style->color[dl_cnt]; + rects.gcolor = color_mix(COLOR_BLACK, style->color[dl_cnt], style->dark_eff); for(i = 0; i < ext->pnum; i ++) { cir_a.x1 = ((w * i) / (ext->pnum - 1)) + x_ofs; @@ -509,7 +499,7 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask) cir_a.y2 = cir_a.y1 + rad; cir_a.y1 -= rad; - lv_draw_rect(&cir_a, mask, &rects, opa); + lv_draw_rect(&cir_a, mask, &rects); } dl_cnt++; } @@ -523,7 +513,7 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask) static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask) { lv_chart_ext_t * ext = lv_obj_get_ext(chart); - lv_charts_t * style_p = lv_obj_get_style(chart); + lv_charts_t * style = lv_obj_get_style(chart); uint8_t i; area_t col_a; @@ -531,24 +521,24 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask) bool mask_ret; cord_t w = lv_obj_get_width(chart); cord_t h = lv_obj_get_height(chart); - opa_t opa = (uint16_t)lv_obj_get_opa(chart) * style_p->data_opa / 100; int32_t y_tmp; cord_t ** y_data; uint8_t dl_cnt = 0; lv_rects_t rects; cord_t col_w = w / (2 * ext->dl_num * ext->pnum); /* Suppose (2 * dl_num) * pnum columns*/ cord_t x_ofs = col_w / 2; /*Shift with a half col.*/ - lv_rects_get(LV_RECTS_DEF, &rects); + lv_rects_get(LV_RECTS_PLAIN, &rects); rects.bwidth = 0; rects.empty = 0; - rects.round = 0; + rects.radius = 0; + rects.base.opa = (uint16_t)((uint16_t)style->bg.base.opa * style->data_opa) >> 8; col_a.y2 = chart->cords.y2; /*Go through all data lines*/ LL_READ_BACK(ext->dl_ll, y_data) { - rects.objs.color = style_p->color[dl_cnt]; - rects.gcolor = color_mix(COLOR_BLACK, style_p->color[dl_cnt], style_p->dark_eff); + rects.base.color = style->color[dl_cnt]; + rects.gcolor = color_mix(COLOR_BLACK, style->color[dl_cnt], style->dark_eff); for(i = 0; i < ext->pnum; i ++) { /* Calculate the x coordinates. Suppose (2 * dl_num) * pnum columns and draw to every second @@ -564,14 +554,13 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask) col_a.x1 += x_ofs; col_a.x2 += x_ofs; - y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext->ymin) * h; y_tmp = y_tmp / (ext->ymax - ext->ymin); col_a.y1 = h - y_tmp + chart->cords.y1; mask_ret = area_union(&col_mask, mask, &col_a); if(mask_ret != false) { - lv_draw_rect(&chart->cords, &col_mask, &rects, opa); + lv_draw_rect(&chart->cords, &col_mask, &rects); } } dl_cnt++; @@ -585,21 +574,18 @@ static void lv_charts_init(void) { /*Default style*/ /* Background */ - lv_rects_get(LV_RECTS_DEF, &lv_charts_def.bg_rects); - lv_charts_def.bg_rects.objs.color = COLOR_MAKE(0x60, 0x80, 0xA0); - lv_charts_def.bg_rects.gcolor = COLOR_WHITE; - lv_charts_def.bg_rects.bcolor = COLOR_BLACK; + lv_rects_get(LV_RECTS_FANCY, &lv_charts_def.bg); /* Div. line */ - lv_lines_get(LV_LINES_DECOR, &lv_charts_def.div_lines); - lv_charts_def.div_lines.width = 1 * LV_DOWNSCALE; - lv_charts_def.div_lines.objs.color = COLOR_BLACK; - lv_charts_def.div_line_opa = OPA_COVER; + lv_lines_get(LV_LINES_DEF, &lv_charts_def.div_line); + lv_charts_def.div_line.width = 1 * LV_DOWNSCALE; + lv_charts_def.div_line.base.color = COLOR_GRAY; + lv_charts_def.div_line.base.opa = OPA_50; /*Data lines*/ lv_charts_def.width = 2 * LV_DOWNSCALE; - lv_charts_def.data_opa = 100; - lv_charts_def.dark_eff = 150; + lv_charts_def.data_opa = OPA_COVER; + lv_charts_def.dark_eff = OPA_70; lv_charts_def.color[0] = COLOR_RED; lv_charts_def.color[1] = COLOR_GREEN; lv_charts_def.color[2] = COLOR_BLUE; @@ -609,11 +595,6 @@ static void lv_charts_init(void) lv_charts_def.color[6] = COLOR_WHITE; lv_charts_def.color[7] = COLOR_GRAY; - - memcpy(&lv_charts_transp, &lv_charts_def, sizeof(lv_charts_t)); - lv_charts_transp.bg_rects.empty = 1; - lv_charts_transp.bg_rects.bwidth = 0; - lv_charts_transp.div_lines.objs.transp = 1; } #endif diff --git a/lv_objx/lv_chart.h b/lv_objx/lv_chart.h index d782dc81a..70df5e06f 100644 --- a/lv_objx/lv_chart.h +++ b/lv_objx/lv_chart.h @@ -33,13 +33,13 @@ /********************** * TYPEDEFS **********************/ -/*Data of chart background*/ +/*Data of chart */ typedef struct { - lv_rect_ext_t bg_rects; /*Ext. of ancestor*/ + lv_rect_ext_t bg_rect; /*Ext. of ancestor*/ /*New data for this type */ - cord_t ymin; - cord_t ymax; + cord_t ymin; /*y min value (used to scale the data)*/ + cord_t ymax; /*y max value (used to scale the data)*/ uint8_t hdiv_num; /*Number of horizontal division lines*/ uint8_t vdiv_num; /*Number of vertical division lines*/ ll_dsc_t dl_ll; /*Linked list for the data line pointers (stores cord_t * )*/ @@ -56,24 +56,22 @@ typedef enum LV_CHART_POINT, }lv_chart_type_t; -/*Style of chart background*/ +/*Style of chart*/ typedef struct { - lv_rects_t bg_rects; /*Style of ancestor*/ + lv_rects_t bg; /*Style of the ancestor*/ /*New style element for this type */ - lv_lines_t div_lines; - uint8_t div_line_opa; /*Percentage of obj. opacity*/ - color_t color[LV_CHART_DL_NUM]; /*Line/Point/Col color */ - uint16_t width; /*Line width or point radius*/ - opa_t data_opa; /*Line/Point/Col opacity in the percentage of obj. opacity*/ - uint8_t dark_eff; /*Dark effect on the bottom of ó points and columns*/ + lv_lines_t div_line; + color_t color[LV_CHART_DL_NUM]; /*Line/Point/Col colors */ + cord_t width; /*Data line width or point radius*/ + opa_t data_opa; /*Line/Point/Col opacity*/ + opa_t dark_eff; /*Dark effect on the bottom of points and columns*/ }lv_charts_t; -/*Built-in styles of chart background*/ +/*Built-in styles of chart*/ typedef enum { LV_CHARTS_DEF, - LV_CHARTS_TRANSP, }lv_charts_builtin_t; /********************** diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 21cb4cf1e..11c85134f 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -34,7 +34,7 @@ static void lv_ddlists_init(void); /********************** * STATIC VARIABLES **********************/ -static lv_ddlists_t lv_ddlists_def; /*Default drop down list style*/ +static lv_ddlists_t lv_ddlists_def; static lv_design_f_t ancestor_design_f; static const char * def_options[] = {"Option 1", "Option 2", "Option 3", ""}; /********************** @@ -129,7 +129,7 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ break; case LV_SIGNAL_STYLE_CHG: - lv_obj_set_style(ext->opt_label, &style->list_labels); + lv_obj_set_style(ext->opt_label, &style->label); lv_ddlist_refr_size(ddlist, false); break; default: @@ -273,10 +273,7 @@ lv_ddlists_t * lv_ddlists_get(lv_ddlists_builtin_t style, lv_ddlists_t * copy) style_p = &lv_ddlists_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_ddlists_t)); - else memcpy(copy, &lv_ddlists_def, sizeof(lv_ddlists_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_ddlists_t)); return style_p; } @@ -310,18 +307,18 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_m lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); if(ext->opened != 0) { lv_ddlists_t * style = lv_obj_get_style(ddlist); - const font_t * font = font_get(style->list_labels.font); + const font_t * font = style->label.font; cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS; area_t rect_area; rect_area.y1 = ext->opt_label->cords.y1; - rect_area.y1 += ext->sel_opt * (font_h + style->list_labels.line_space); - rect_area.y1 -= style->sel_rects.vpad; + rect_area.y1 += ext->sel_opt * (font_h + style->label.line_space); + rect_area.y1 -= style->sel.vpad; - rect_area.y2 = rect_area.y1 + font_h + 2 * style->sel_rects.vpad; - rect_area.x1 = ext->opt_label->cords.x1 - style->pages.scrl_rects.hpad; + rect_area.y2 = rect_area.y1 + font_h + 2 * style->sel.vpad; + rect_area.x1 = ext->opt_label->cords.x1 - style->page.scrl.hpad; rect_area.x2 = rect_area.x1 + lv_obj_get_width(lv_page_get_scrl(ddlist)); - lv_draw_rect(&rect_area, mask, &style->sel_rects, OPA_COVER); + lv_draw_rect(&rect_area, mask, &style->sel); } } /*Post draw when the children are drawn*/ @@ -392,16 +389,16 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) lv_ddlists_t * style = lv_obj_get_style(ddlist); cord_t new_height; if(ext->opened != 0) { /*Open the list*/ - new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->pages.bg_rects.vpad; + new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->page.bg.vpad; lv_obj_t * parent = lv_obj_get_parent(ddlist); /*Reduce the height if enabled and required*/ if(ext->auto_size != 0 && new_height + ddlist->cords.y1 > parent->cords.y2) { new_height = parent->cords.y2 - ddlist->cords.y1; } } else { /*Close the list*/ - const font_t * font = font_get(style->list_labels.font); + const font_t * font = style->label.font; cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS; - new_height = font_h + 2 * style->sel_rects.vpad; + new_height = font_h + 2 * style->sel.vpad; } if(anim_en == false) { lv_obj_set_height(ddlist, new_height); @@ -433,12 +430,12 @@ static void lv_ddlist_pos_act_option(lv_obj_t * ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_ddlists_t * style = lv_obj_get_style(ddlist); - const font_t * font = font_get(style->list_labels.font); + const font_t * font = style->label.font; cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS; lv_obj_set_y(lv_page_get_scrl(ddlist), - -(ext->sel_opt * (font_h + style->list_labels.line_space) + - style->pages.scrl_rects.vpad) + style->sel_rects.vpad); + -(ext->sel_opt * (font_h + style->label.line_space) + + style->page.scrl.vpad) + style->sel.vpad); } @@ -447,29 +444,28 @@ static void lv_ddlist_pos_act_option(lv_obj_t * ddlist) */ static void lv_ddlists_init(void) { - /*Default style*/ - lv_pages_get(LV_PAGES_SIMPLE, &lv_ddlists_def.pages); - lv_ddlists_def.pages.bg_rects.objs.color = COLOR_WHITE; - lv_ddlists_def.pages.bg_rects.gcolor = COLOR_SILVER; - lv_ddlists_def.pages.bg_rects.bcolor = COLOR_GRAY; + /*Plain style*/ + lv_pages_get(LV_PAGES_PAPER, &lv_ddlists_def.page); + lv_ddlists_def.page.bg.base.color = COLOR_WHITE; + lv_ddlists_def.page.bg.gcolor = COLOR_SILVER; + lv_ddlists_def.page.bg.bopa = OPA_50; + lv_ddlists_def.page.bg.swidth = LV_DPI / 8; - lv_ddlists_def.pages.bg_rects.hpad = 0 * LV_DOWNSCALE; - lv_ddlists_def.pages.bg_rects.vpad = 0 * LV_DOWNSCALE; - lv_ddlists_def.pages.bg_rects.opad = 0; + lv_ddlists_def.page.scrl.hpad = LV_DPI / 10; + lv_ddlists_def.page.scrl.vpad = LV_DPI / 4; + lv_ddlists_def.page.scrl.opad = 0; - lv_ddlists_def.pages.scrl_rects.hpad = 5 * LV_DOWNSCALE; - lv_ddlists_def.pages.scrl_rects.vpad = 10 * LV_DOWNSCALE; - lv_ddlists_def.pages.scrl_rects.opad = 0 * LV_DOWNSCALE; + lv_ddlists_def.page.sb_mode = LV_PAGE_SB_MODE_OFF; - lv_ddlists_def.pages.sb_mode = LV_PAGE_SB_MODE_OFF; + lv_labels_get(LV_LABELS_TXT, &lv_ddlists_def.label); + lv_ddlists_def.label.line_space = LV_DPI / 4; + + lv_rects_get(LV_RECTS_PLAIN, &lv_ddlists_def.sel); + lv_ddlists_def.sel.bwidth = 0; + lv_ddlists_def.sel.radius = 0; + lv_ddlists_def.sel.vpad = LV_DPI / 8; - lv_labels_get(LV_LABELS_DEF, &lv_ddlists_def.list_labels); - lv_ddlists_def.list_labels.line_space = 15 * LV_DOWNSCALE; - lv_rects_get(LV_RECTS_DEF, &lv_ddlists_def.sel_rects); - lv_ddlists_def.sel_rects.bwidth = 0; - lv_ddlists_def.sel_rects.round = 0; - lv_ddlists_def.sel_rects.vpad = 7 * LV_DOWNSCALE; } #endif diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index 0181af0f2..91a4fd101 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -37,10 +37,10 @@ typedef struct /*Style of drop down list*/ typedef struct { - lv_pages_t pages; /*Style of ancestor*/ + lv_pages_t page; /*Style of ancestor*/ /*New style element for this type */ - lv_rects_t sel_rects; - lv_labels_t list_labels; + lv_rects_t sel; /*Select rectangle*/ + lv_labels_t label; /*Style of labels*/ }lv_ddlists_t; /*Built-in styles of drop down list*/ diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index 1c668b28e..38d0abb0b 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -495,7 +495,7 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask) area_t nm_cord; lv_rects_get(LV_RECTS_DEF, &nm); nm.bwidth = 0; - nm.round = LV_RECT_CIRCLE; + nm.radius = LV_RECT_CIRCLE; nm.objs.color = style->needle_mid_color; nm.gcolor = style->needle_mid_color; @@ -515,7 +515,7 @@ static void lv_gauges_init(void) { /*Default style*/ lv_rects_get(LV_RECTS_DEF, &lv_gauges_def.rects); - lv_gauges_def.rects.round = LV_RECT_CIRCLE; + lv_gauges_def.rects.radius = LV_RECT_CIRCLE; lv_gauges_def.rects.bwidth = 4 * LV_DOWNSCALE; lv_gauges_def.rects.objs.color = COLOR_MAKE(0x00, 0xaa, 0x00);//GREEN; lv_gauges_def.rects.gcolor = COLOR_BLACK; diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index ca3d60b7f..bce0ba46e 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -229,7 +229,7 @@ void lv_img_set_file(lv_obj_t * img, const char * fn) #if LV_IMG_ENABLE_SYMBOLS lv_imgs_t * imgs = lv_obj_get_style(img); point_t size; - txt_get_size(&size, fn, font_get(imgs->sym_font), 0, 0, LV_CORD_MAX, TXT_FLAG_NONE); + txt_get_size(&size, fn, imgs->sym_font, 0, 0, LV_CORD_MAX, TXT_FLAG_NONE); ext->w = size.x; ext->h = size.y; ext->transp = 0; @@ -351,16 +351,15 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t #if LV_IMG_ENABLE_SYMBOLS != 0 bool sym = lv_img_is_symbol(ext->fn); lv_labels_t sym_style; - lv_labels_get(LV_LABELS_DEF, &sym_style); + lv_labels_get(LV_LABELS_TXT, &sym_style); sym_style.font = imgs_p->sym_font; sym_style.letter_space = 0; sym_style.line_space = 0; sym_style.mid = 0; - sym_style.objs.color = imgs_p->objs.color; + sym_style.base.color = imgs_p->base.color; #endif lv_obj_get_cords(img, &cords); - opa_t opa = lv_obj_get_opa(img); area_t cords_tmp; cords_tmp.y1 = cords.y1; @@ -374,8 +373,8 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t #if LV_IMG_ENABLE_SYMBOLS == 0 lv_draw_img(&cords_tmp, mask, imgs_p, opa, ext->fn); #else - if(sym == false) lv_draw_img(&cords_tmp, mask, imgs_p, opa, ext->fn); - else lv_draw_label(&cords_tmp, mask, &sym_style, opa, ext->fn, TXT_FLAG_NONE); + if(sym == false) lv_draw_img(&cords_tmp, mask, imgs_p, ext->fn); + else lv_draw_label(&cords_tmp, mask, &sym_style, ext->fn, TXT_FLAG_NONE); #endif } } @@ -412,18 +411,19 @@ static bool lv_img_is_symbol(const char * txt) static void lv_imgs_init(void) { /*Default style*/ - lv_imgs_def.objs.color = COLOR_BLACK; + lv_imgs_def.base.color = COLOR_BLACK; + lv_imgs_def.base.opa = OPA_COVER; lv_imgs_def.recolor_opa = OPA_TRANSP; #if LV_IMG_ENABLE_SYMBOLS != 0 - lv_imgs_def.sym_font = LV_IMG_DEF_SYMBOL_FONT; + lv_imgs_def.sym_font = font_get(LV_IMG_DEF_SYMBOL_FONT); #endif /*Dark style*/ memcpy(&lv_imgs_dark, &lv_imgs_def, sizeof(lv_imgs_t)); - lv_imgs_dark.objs.color = COLOR_BLACK; lv_imgs_dark.recolor_opa = OPA_50; + lv_imgs_dark.base.color = COLOR_BLACK; lv_imgs_dark.recolor_opa = OPA_50; /*Light style*/ memcpy(&lv_imgs_light, &lv_imgs_dark, sizeof(lv_imgs_t)); - lv_imgs_light.objs.color = COLOR_WHITE; lv_imgs_light.recolor_opa = OPA_50; + lv_imgs_light.base.color = COLOR_WHITE; lv_imgs_light.recolor_opa = OPA_50; } diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index 01bcf45bc..0db3a061d 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -52,11 +52,11 @@ typedef struct /*Style of image*/ typedef struct { - lv_objs_t objs; /*Style of ancestor*/ + lv_objs_t base; /*Style of ancestor*/ /*New style element for this type */ opa_t recolor_opa; /*Intensity of recoloring (OPA_TRANSP, OPA_10 ... OPA_COVER)*/ #if LV_IMG_ENABLE_SYMBOLS != 0 - font_types_t sym_font; /*Symbol font*/ + const font_t * sym_font; /*Symbol font*/ #endif }lv_imgs_t; diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 091bbc8f0..2ed276aac 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -54,10 +54,9 @@ static void lv_labels_init(void); /********************** * STATIC VARIABLES **********************/ -static lv_labels_t lv_labels_def; -static lv_labels_t lv_labels_btn; static lv_labels_t lv_labels_title; static lv_labels_t lv_labels_txt; +static lv_labels_t lv_labels_btn; /********************** * MACROS @@ -95,9 +94,8 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new label*/ if(copy == NULL) { - lv_obj_set_opa(new_label, OPA_COVER); lv_obj_set_click(new_label, false); - lv_obj_set_style(new_label, lv_labels_get(LV_LABELS_DEF, NULL)); + lv_obj_set_style(new_label, lv_labels_get(LV_LABELS_TXT, NULL)); lv_label_set_long_mode(new_label, LV_LABEL_LONG_EXPAND); lv_label_set_text(new_label, "Text"); } @@ -356,8 +354,8 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) uint32_t line_start = 0; uint32_t new_line_start = 0; 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); + lv_labels_t * style = lv_obj_get_style(label); + const font_t * font = style->font; uint8_t letter_height = font_get_height(font) >> LV_FONT_ANTIALIAS; cord_t y = 0; txt_flag_t flag = TXT_FLAG_NONE; @@ -371,15 +369,15 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) /*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_w, flag); + new_line_start += txt_get_next_line(&text[line_start], font, style->letter_space, max_w, flag); 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; + y += letter_height + style->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; + y += letter_height + style->line_space; line_start = index; } @@ -395,13 +393,13 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) } } - x += (font_get_width(font, text[i]) >> LV_FONT_ANTIALIAS) + labels->letter_space; + x += (font_get_width(font, text[i]) >> LV_FONT_ANTIALIAS) + style->letter_space; } - 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, flag); + font, style->letter_space, flag); x += lv_obj_get_width(label) / 2 - line_w / 2; } @@ -424,7 +422,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos) uint32_t new_line_start = 0; 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); + const font_t * font = style->font; uint8_t letter_height = font_get_height(font) >> LV_FONT_ANTIALIAS; cord_t y = 0; txt_flag_t flag = TXT_FLAG_NONE; @@ -490,26 +488,20 @@ lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy) lv_labels_t * style_p; switch(style) { - case LV_LABELS_DEF: - style_p = &lv_labels_def; - break; - case LV_LABELS_BTN: - style_p = &lv_labels_btn; - break; case LV_LABELS_TXT: style_p = &lv_labels_txt; break; case LV_LABELS_TITLE: style_p = &lv_labels_title; break; + case LV_LABELS_BTN: + style_p = &lv_labels_btn; + break; default: - style_p = &lv_labels_def; + style_p = &lv_labels_txt; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_labels_t)); - else memcpy(copy, &lv_labels_def, sizeof(lv_labels_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_labels_t)); return style_p; } @@ -539,13 +531,12 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod area_t cords; lv_obj_get_cords(label, &cords); - opa_t opa = lv_obj_get_opa(label); lv_label_ext_t * ext = lv_obj_get_ext(label); txt_flag_t flag = TXT_FLAG_NONE; if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR; - lv_draw_label(&cords, mask, lv_obj_get_style(label), opa, ext->txt, flag); + lv_draw_label(&cords, mask, lv_obj_get_style(label), ext->txt, flag); } @@ -564,7 +555,7 @@ static void lv_label_refr_text(lv_obj_t * label) 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); + const font_t * font = style->font; ext->dot_end = LV_LABEL_DOT_END_INV; /*Initialize the dot end index*/ @@ -675,28 +666,21 @@ static void lv_label_refr_text(lv_obj_t * label) */ static void lv_labels_init(void) { - /*Default style*/ - lv_labels_def.font = LV_FONT_DEFAULT; - lv_labels_def.objs.color = COLOR_MAKE(0x10, 0x18, 0x20); - lv_labels_def.letter_space = 2 * LV_DOWNSCALE; - lv_labels_def.line_space = 2 * LV_DOWNSCALE; - lv_labels_def.mid = 0; + /*Text style*/ + lv_objs_get(LV_OBJS_PLAIN, &lv_labels_txt.base); + lv_labels_txt.base.color = COLOR_MAKE(0x10, 0x18, 0x20); + lv_labels_txt.font = font_get(LV_FONT_DEFAULT); + lv_labels_txt.letter_space = 1 * LV_DOWNSCALE; + lv_labels_txt.line_space = 2 * LV_DOWNSCALE; + lv_labels_txt.mid = 0; - memcpy(&lv_labels_btn, &lv_labels_def, sizeof(lv_labels_t)); - lv_labels_btn.objs.color = COLOR_MAKE(0xd0, 0xe0, 0xf0); + memcpy(&lv_labels_btn, &lv_labels_txt, sizeof(lv_labels_t)); + lv_labels_btn.base.color = COLOR_MAKE(0x20, 0x20, 0x20); lv_labels_btn.mid = 1; - memcpy(&lv_labels_title, &lv_labels_def, sizeof(lv_labels_t)); - lv_labels_title.objs.color = COLOR_MAKE(0x10, 0x20, 0x30); + memcpy(&lv_labels_title, &lv_labels_txt, sizeof(lv_labels_t)); lv_labels_title.letter_space = 4 * LV_DOWNSCALE; lv_labels_title.line_space = 4 * LV_DOWNSCALE; lv_labels_title.mid = 0; - - memcpy(&lv_labels_txt, &lv_labels_def, sizeof(lv_labels_t)); - lv_labels_txt.objs.color = COLOR_MAKE(0x16, 0x23, 0x34); - lv_labels_txt.letter_space = 0 * LV_DOWNSCALE; - lv_labels_txt.line_space = 1 * LV_DOWNSCALE; - lv_labels_txt.mid = 0; - } #endif diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index 330b0ba43..62ef494f6 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -50,21 +50,20 @@ typedef struct /*Style of label*/ typedef struct { - lv_objs_t objs; /*Style of ancestor*/ + lv_objs_t base; /*Style of ancestor*/ /*New style element for this type */ - font_types_t font; /*Name of the font. E.g: FONT_DEJAVU_20*/ - uint16_t letter_space; - uint16_t line_space; + const font_t * font; /*Pointer to a font*/ + cord_t letter_space; + cord_t line_space; uint8_t mid :1; /*1: Align the lines into the middle*/ }lv_labels_t; /*Built-in styles of label*/ typedef enum { - LV_LABELS_DEF, - LV_LABELS_BTN, - LV_LABELS_TXT, LV_LABELS_TITLE, + LV_LABELS_TXT, + LV_LABELS_BTN, }lv_labels_builtin_t; /********************** diff --git a/lv_objx/lv_led.c b/lv_objx/lv_led.c index 0bcb76238..c11410c09 100644 --- a/lv_objx/lv_led.c +++ b/lv_objx/lv_led.c @@ -283,7 +283,7 @@ static void lv_leds_init(void) lv_leds_def.bg_rect.bwidth = 4 * LV_DOWNSCALE; lv_leds_def.bg_rect.bopa = 50; lv_leds_def.bg_rect.light = 15 * LV_DOWNSCALE; - lv_leds_def.bg_rect.round = LV_RECT_CIRCLE; + lv_leds_def.bg_rect.radius = LV_RECT_CIRCLE; lv_leds_def.bg_rect.hpad = 0; lv_leds_def.bg_rect.vpad = 0; lv_leds_def.bg_rect.opad = 0; diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index 16bf56f16..48985b9ac 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -40,8 +40,6 @@ static void lv_lines_init(void); * STATIC VARIABLES **********************/ static lv_lines_t lv_lines_def; -static lv_lines_t lv_lines_decor; -static lv_lines_t lv_lines_chart; /********************** * MACROS @@ -265,20 +263,11 @@ lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy) case LV_LINES_DEF: style_p = &lv_lines_def; break; - case LV_LINES_DECOR: - style_p = &lv_lines_decor; - break; - case LV_LINES_CHART: - style_p = &lv_lines_chart; - break; default: style_p = &lv_lines_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_lines_t)); - else memcpy(copy, &lv_lines_def, sizeof(lv_lines_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_lines_t)); return style_p; } @@ -305,9 +294,7 @@ static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_ if(ext->point_num == 0 || ext->point_array == NULL) return false; - lv_lines_t * lines = lv_obj_get_style(line); - - opa_t opa = lv_obj_get_opa(line); + lv_lines_t * style = lv_obj_get_style(line); area_t area; lv_obj_get_cords(line, &area); cord_t x_ofs = area.x1; @@ -334,7 +321,7 @@ static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_ p1.y = h - ext->point_array[i].y * us + y_ofs; p2.y = h - ext->point_array[i + 1].y * us + y_ofs; } - lv_draw_line(&p1, &p2, mask, lines, opa); + lv_draw_line(&p1, &p2, mask, style); } } return true; @@ -346,18 +333,8 @@ static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_ static void lv_lines_init(void) { /*Default style*/ - lv_lines_def.width = 2 * LV_DOWNSCALE; - lv_lines_def.objs.color = COLOR_RED; - lv_lines_def.objs.transp = 0; - - /*Decoration line style*/ - memcpy(&lv_lines_decor, &lv_lines_def, sizeof(lv_lines_t)); - lv_lines_decor.width = 1 * LV_DOWNSCALE; - lv_lines_decor.objs.color = COLOR_GRAY; - - /*Chart line style*/ - memcpy(&lv_lines_chart, &lv_lines_def, sizeof(lv_lines_t)); - lv_lines_chart.width = 3 * LV_DOWNSCALE; - lv_lines_chart.objs.color = COLOR_RED; + lv_lines_def.width = LV_DPI / 25; + lv_lines_def.base.color = COLOR_RED; + lv_lines_def.base.opa = OPA_COVER; } #endif diff --git a/lv_objx/lv_line.h b/lv_objx/lv_line.h index bb1819630..07b4e73d3 100644 --- a/lv_objx/lv_line.h +++ b/lv_objx/lv_line.h @@ -36,17 +36,15 @@ typedef struct /*Style of line*/ typedef struct { - lv_objs_t objs; /*Style of ancestor*/ + lv_objs_t base; /*Style of ancestor*/ /*New style element for this type */ - uint16_t width; + cord_t width; /*Line width*/ }lv_lines_t; /*Built-in styles of line*/ typedef enum { LV_LINES_DEF, - LV_LINES_DECOR, - LV_LINES_CHART, }lv_lines_builtin_t; /********************** diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index a84f82d0e..bb1a7b53f 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -34,7 +34,6 @@ static void lv_lists_init(void); * STATIC VARIABLES **********************/ static lv_lists_t lv_lists_def; -static lv_lists_t lv_lists_scrl; static lv_lists_t lv_lists_transp; /********************** @@ -118,23 +117,23 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l /*Create a list element with the image an the text*/ lv_obj_t * liste; liste = lv_btn_create(list, NULL); - lv_obj_set_style(liste, &lists->liste_btns); + lv_obj_set_style(liste, &lists->liste_btn); lv_btn_set_rel_action(liste, rel_action); lv_page_glue_obj(liste, true); - lv_rect_set_layout(liste, lists->liste_layout); + lv_rect_set_layout(liste, LV_RECT_LAYOUT_ROW_M); lv_rect_set_fit(liste, false, true); - if(img_fn != NULL) { + if(img_fn != NULL && img_fn[0] != '\0') { lv_obj_t * img = lv_img_create(liste, NULL); lv_img_set_file(img, img_fn); - lv_obj_set_style(img, &lists->liste_imgs); + lv_obj_set_style(img, &lists->liste_img); lv_obj_set_click(img, false); } if(txt != NULL) { lv_obj_t * label = lv_label_create(liste, NULL); lv_label_set_text(label, txt); - lv_obj_set_style(label,&lists->liste_labels); + lv_obj_set_style(label,&lists->liste_label); lv_obj_set_click(label, false); } @@ -143,12 +142,12 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l /*Make the size adjustment*/ cord_t w = lv_obj_get_width(list); - cord_t hpad_tot = lists->bg_pages.bg_rects.hpad + lists->bg_pages.scrl_rects.hpad; + cord_t hpad_tot = lists->page.bg.hpad + lists->page.scrl.hpad; w -= hpad_tot * 2; /*Make place for the scrollbar if hpad_tot is too small*/ - if(style->widthe_sb != 0) { - if(hpad_tot < lists->bg_pages.sb_width) w -= lists->bg_pages.sb_width - hpad_tot; + if(style->width_sb != 0) { + if(hpad_tot < lists->page.sb_width) w -= lists->page.sb_width - hpad_tot; } lv_obj_set_width(liste, w); @@ -240,11 +239,8 @@ lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * list) lv_lists_t *style_p; switch(style) { - case LV_LISTS_DEF: + case LV_LISTS_DEF: style_p = &lv_lists_def; - break; - case LV_LISTS_SCRL: - style_p = &lv_lists_scrl; break; case LV_LISTS_TRANSP: style_p = &lv_lists_transp; @@ -253,10 +249,7 @@ lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * list) style_p = &lv_lists_def; } - if(list != NULL) { - if(style_p != NULL) memcpy(list, style_p, sizeof(lv_lists_t)); - else memcpy(list, &lv_lists_def, sizeof(lv_lists_t)); - } + if(list != NULL) memcpy(list, style_p, sizeof(lv_lists_t)); return style_p; } @@ -295,100 +288,36 @@ static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_ */ static void lv_lists_init(void) { - /*Default style*/ - lv_pages_get(LV_PAGES_DEF, &lv_lists_def.bg_pages); - lv_lists_def.bg_pages.bg_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_def.bg_pages.bg_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_def.bg_pages.bg_rects.opad = 0 * LV_DOWNSCALE; + /*Default style*/ + lv_pages_get(LV_PAGES_MENU, &lv_lists_def.page); - lv_lists_def.bg_pages.scrl_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_def.bg_pages.scrl_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_def.bg_pages.scrl_rects.opad = 5 * LV_DOWNSCALE; - - lv_btns_get(LV_BTNS_DEF, &lv_lists_def.liste_btns); /*List element button style*/ - lv_lists_def.liste_btns.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x90, 0xa8, 0xc0); - lv_lists_def.liste_btns.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x90, 0xa8, 0xc0); - lv_lists_def.liste_btns.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; - lv_lists_def.liste_btns.lcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_lists_def.liste_btns.flags[LV_BTN_STATE_REL].light_en = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_REL].transp = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_REL].empty = 0; - - lv_lists_def.liste_btns.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x40, 0x60, 0x80);// COLOR_MAKE(0x60, 0x80, 0xa0); - lv_lists_def.liste_btns.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x40, 0x60, 0x80);//COLOR_MAKE(0x20, 0x30, 0x40); - lv_lists_def.liste_btns.bcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_lists_def.liste_btns.lcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_lists_def.liste_btns.flags[LV_BTN_STATE_PR].light_en = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_PR].transp = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_PR].empty = 0; - - lv_lists_def.liste_btns.mcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_lists_def.liste_btns.gcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_lists_def.liste_btns.bcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_lists_def.liste_btns.lcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_lists_def.liste_btns.flags[LV_BTN_STATE_TGL_REL].light_en = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_TGL_REL].transp = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_TGL_REL].empty = 0; - - lv_lists_def.liste_btns.mcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x40, 0x60, 0x80); - lv_lists_def.liste_btns.gcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x40, 0x60, 0x80); - lv_lists_def.liste_btns.bcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x20, 0x30, 0x40); - lv_lists_def.liste_btns.lcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_lists_def.liste_btns.flags[LV_BTN_STATE_TGL_PR].light_en = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_TGL_PR].transp = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_TGL_PR].empty = 0; - - lv_lists_def.liste_btns.mcolor[LV_BTN_STATE_INA] = COLOR_SILVER; - lv_lists_def.liste_btns.gcolor[LV_BTN_STATE_INA] = COLOR_GRAY; - lv_lists_def.liste_btns.bcolor[LV_BTN_STATE_INA] = COLOR_WHITE; - lv_lists_def.liste_btns.lcolor[LV_BTN_STATE_INA] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_lists_def.liste_btns.flags[LV_BTN_STATE_INA].light_en = 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_INA].transp= 0; - lv_lists_def.liste_btns.flags[LV_BTN_STATE_INA].empty = 0; - - lv_lists_def.liste_btns.rects.objs.color = lv_lists_def.liste_btns.mcolor[LV_BTN_STATE_REL]; - lv_lists_def.liste_btns.rects.gcolor = lv_lists_def.liste_btns.gcolor[LV_BTN_STATE_REL]; - lv_lists_def.liste_btns.rects.bcolor = lv_lists_def.liste_btns.bcolor[LV_BTN_STATE_REL]; - lv_lists_def.liste_btns.rects.objs.transp = 0; - lv_lists_def.liste_btns.rects.empty = 0; - lv_lists_def.liste_btns.rects.light = 6 * LV_DOWNSCALE; - lv_lists_def.liste_btns.rects.bwidth = 0 * LV_DOWNSCALE; - lv_lists_def.liste_btns.rects.bopa = 70; - lv_lists_def.liste_btns.rects.empty = 0; - lv_lists_def.liste_btns.rects.round = 0 * LV_DOWNSCALE; - - lv_labels_get(LV_LABELS_DEF, &lv_lists_def.liste_labels); /*List element label style*/ - lv_lists_def.liste_labels.mid = 0; - - lv_imgs_get(LV_IMGS_DEF, &lv_lists_def.liste_imgs); /*Lit element image style*/ - - lv_lists_def.liste_layout = LV_RECT_LAYOUT_ROW_M; - lv_lists_def.widthe_sb = 1; - - /*Only the scrollable part is visible style*/ - memcpy(&lv_lists_scrl, &lv_lists_def, sizeof(lv_lists_t)); - lv_pages_get(LV_PAGES_TRANSP, &lv_lists_scrl.bg_pages); - lv_lists_scrl.bg_pages.bg_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_scrl.bg_pages.bg_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_scrl.bg_pages.bg_rects.opad = 0 * LV_DOWNSCALE; - - lv_lists_scrl.bg_pages.scrl_rects.objs.transp = 0; - lv_lists_scrl.bg_pages.scrl_rects.empty = 0; - lv_lists_scrl.bg_pages.scrl_rects.bwidth = 1 * LV_DOWNSCALE; - lv_lists_scrl.bg_pages.scrl_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_scrl.bg_pages.scrl_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_scrl.bg_pages.scrl_rects.opad = 0 * LV_DOWNSCALE; - - /*Transparent list background*/ - memcpy(&lv_lists_transp, &lv_lists_def, sizeof(lv_lists_t)); - lv_pages_get(LV_PAGES_TRANSP, &lv_lists_transp.bg_pages); - lv_lists_transp.bg_pages.bg_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_transp.bg_pages.bg_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_transp.bg_pages.bg_rects.opad = 0 * LV_DOWNSCALE; - - lv_lists_transp.bg_pages.scrl_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_transp.bg_pages.scrl_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_transp.bg_pages.scrl_rects.opad = 5 * LV_DOWNSCALE; + lv_rects_get(LV_RECTS_TRANSP, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL]); + lv_rects_get(LV_RECTS_PLAIN, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR]); + lv_rects_get(LV_RECTS_TRANSP, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL]); + lv_rects_get(LV_RECTS_PLAIN, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR]); + lv_rects_get(LV_RECTS_PLAIN, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA]); + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL].hpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL].vpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL].opad = LV_DPI / 6; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].hpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].vpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].opad = LV_DPI / 6; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].radius = 0; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL].hpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL].vpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL].opad = LV_DPI / 6; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].hpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].vpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].opad = LV_DPI / 6; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].radius = 0; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].hpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].vpad = LV_DPI / 4; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].opad = LV_DPI / 6; + lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].radius = 0; + lv_labels_get(LV_LABELS_BTN, &lv_lists_def.liste_label); /*List element label style*/ + lv_imgs_get(LV_IMGS_DEF, &lv_lists_def.liste_img); /*List element image style*/ + memcpy(&lv_lists_transp, &lv_lists_def, sizeof(lv_lists_t)); + lv_pages_get(LV_PAGES_TRANSP, &lv_lists_transp.page); } #endif diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 8125c7542..a3f0eeaa4 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -49,20 +49,18 @@ typedef struct /*Style of list*/ typedef struct { - lv_pages_t bg_pages; /*Style of ancestor*/ + lv_pages_t page; /*Style of ancestor*/ /*New style element for this type */ - lv_btns_t liste_btns; /*List element button style*/ - lv_labels_t liste_labels; /*List element label style*/ - lv_imgs_t liste_imgs; /*List element image style*/ - lv_rect_layout_t liste_layout; /*List element layout (will be removed)*/ - uint8_t widthe_sb :1; /*1: Keep space for the scrollbar*/ + lv_btns_t liste_btn; /*List element button style*/ + lv_labels_t liste_label; /*List element label style*/ + lv_imgs_t liste_img; /*List element image style*/ + uint8_t width_sb :1; /*1: Keep space for the scrollbar*/ }lv_lists_t; /*Built-in styles of list*/ typedef enum { LV_LISTS_DEF, - LV_LISTS_SCRL, LV_LISTS_TRANSP, }lv_lists_builtin_t; diff --git a/lv_objx/lv_mbox.c b/lv_objx/lv_mbox.c index 551eaef7c..3bc4e7106 100644 --- a/lv_objx/lv_mbox.c +++ b/lv_objx/lv_mbox.c @@ -467,12 +467,9 @@ static void lv_mbox_disable_fit(lv_obj_t * mbox) static void lv_mboxs_init(void) { /*Default style*/ - lv_rects_get(LV_RECTS_DEF, &lv_mboxs_def.bg); - lv_mboxs_def.bg.light = 8 * LV_DOWNSCALE; + lv_rects_get(LV_RECTS_FANCY, &lv_mboxs_def.bg); lv_btns_get(LV_BTNS_DEF, &lv_mboxs_def.btn); - lv_mboxs_def.btn.flags[LV_BTN_STATE_PR].light_en = 0; - lv_mboxs_def.btn.flags[LV_BTN_STATE_REL].light_en = 0; lv_labels_get(LV_LABELS_TITLE, &lv_mboxs_def.title); lv_labels_get(LV_LABELS_TXT, &lv_mboxs_def.txt); lv_labels_get(LV_LABELS_BTN, &lv_mboxs_def.btn_label); @@ -481,42 +478,43 @@ static void lv_mboxs_init(void) lv_mboxs_def.btnh.vpad = 0; memcpy(&lv_mboxs_info, &lv_mboxs_def, sizeof(lv_mboxs_t)); - lv_mboxs_info.bg.objs.color = COLOR_BLACK; + lv_mboxs_info.bg.base.color = COLOR_BLACK; lv_mboxs_info.bg.gcolor = COLOR_BLACK; lv_mboxs_info.bg.bcolor = COLOR_WHITE; - lv_mboxs_info.title.objs.color = COLOR_WHITE; - lv_mboxs_info.txt.objs.color = COLOR_WHITE; + lv_mboxs_info.title.base.color = COLOR_WHITE; + lv_mboxs_info.txt.base.color = COLOR_WHITE; lv_mboxs_info.txt.letter_space = 2 * LV_DOWNSCALE; lv_btns_get(LV_BTNS_BORDER, &lv_mboxs_info.btn); - lv_mboxs_info.btn.bcolor[LV_BTN_STATE_PR] = COLOR_SILVER; - lv_mboxs_info.btn.bcolor[LV_BTN_STATE_REL] = COLOR_WHITE; - lv_mboxs_info.btn.mcolor[LV_BTN_STATE_PR] = COLOR_GRAY; - lv_mboxs_info.btn.gcolor[LV_BTN_STATE_PR] = COLOR_GRAY; - lv_mboxs_info.btn.rects.bopa = OPA_COVER; - lv_mboxs_info.btn_label.objs.color = COLOR_WHITE; + lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].bcolor = COLOR_SILVER; + lv_mboxs_info.btn.state_style[LV_BTN_STATE_REL].bcolor = COLOR_WHITE; + lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].base.color = COLOR_GRAY; + lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].gcolor = COLOR_GRAY; + lv_mboxs_info.btn.state_style[LV_BTN_STATE_REL].bopa = OPA_COVER; + lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].bopa = OPA_COVER; + lv_mboxs_info.btn_label.base.color = COLOR_WHITE; memcpy(&lv_mboxs_warn, &lv_mboxs_info, sizeof(lv_mboxs_t)); - lv_mboxs_warn.bg.objs.color = COLOR_MAKE(0xff, 0xb2, 0x66); + lv_mboxs_warn.bg.base.color = COLOR_MAKE(0xff, 0xb2, 0x66); lv_mboxs_warn.bg.gcolor = COLOR_MAKE(0xff, 0xad, 0x29); - lv_mboxs_warn.btn.bcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x10, 0x10, 0x10); - lv_mboxs_warn.btn.bcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x10, 0x10, 0x10); - lv_mboxs_warn.btn.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xa8, 0x6e, 0x33); - lv_mboxs_warn.btn.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xa8, 0x6e, 0x33); - lv_mboxs_warn.title.objs.color = COLOR_MAKE(0x10, 0x10, 0x10); - lv_mboxs_warn.txt.objs.color = COLOR_MAKE(0x10, 0x10, 0x10);; - lv_mboxs_warn.btn_label.objs.color = COLOR_MAKE(0x10, 0x10, 0x10); + lv_mboxs_warn.btn.state_style[LV_BTN_STATE_REL].bcolor = COLOR_MAKE(0x10, 0x10, 0x10); + lv_mboxs_warn.btn.state_style[LV_BTN_STATE_PR].bcolor = COLOR_MAKE(0x10, 0x10, 0x10); + lv_mboxs_warn.btn.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0xa8, 0x6e, 0x33); + lv_mboxs_warn.btn.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0xa8, 0x6e, 0x33); + lv_mboxs_warn.title.base.color = COLOR_MAKE(0x10, 0x10, 0x10); + lv_mboxs_warn.txt.base.color = COLOR_MAKE(0x10, 0x10, 0x10);; + lv_mboxs_warn.btn_label.base.color = COLOR_MAKE(0x10, 0x10, 0x10); memcpy(&lv_mboxs_err, &lv_mboxs_warn, sizeof(lv_mboxs_t)); - lv_mboxs_err.bg.objs.color = COLOR_MAKE(0xff, 0x66, 0x66); + lv_mboxs_err.bg.base.color = COLOR_MAKE(0xff, 0x66, 0x66); lv_mboxs_err.bg.gcolor = COLOR_MAKE(0x99, 0x22, 0x22); - lv_mboxs_err.btn.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; - lv_mboxs_err.btn.bcolor[LV_BTN_STATE_PR] = COLOR_BLACK; - lv_mboxs_err.btn.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x70, 0x00, 0x00); - lv_mboxs_err.btn.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x70, 0x00, 0x00); - lv_mboxs_err.title.objs.color = COLOR_BLACK; - lv_mboxs_err.txt.objs.color = COLOR_BLACK; - lv_mboxs_err.btn_label.objs.color = COLOR_BLACK; + lv_mboxs_err.btn.state_style[LV_BTN_STATE_REL].bcolor = COLOR_BLACK; + lv_mboxs_err.btn.state_style[LV_BTN_STATE_PR].bcolor = COLOR_BLACK; + lv_mboxs_err.btn.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0x70, 0x00, 0x00); + lv_mboxs_err.btn.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0x70, 0x00, 0x00); + lv_mboxs_err.title.base.color = COLOR_BLACK; + lv_mboxs_err.txt.base.color = COLOR_BLACK; + lv_mboxs_err.btn_label.base.color = COLOR_BLACK; } #endif diff --git a/lv_objx/lv_mbox.h b/lv_objx/lv_mbox.h index 6097fe61e..63dd0b9cf 100644 --- a/lv_objx/lv_mbox.h +++ b/lv_objx/lv_mbox.h @@ -42,7 +42,7 @@ /*Data of message box*/ typedef struct { - lv_rect_ext_t rect; /*Ext. of ancestor*/ + lv_rect_ext_t bg; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * title; /*Title of the message box*/ lv_obj_t * txt; /*Text of the message box*/ diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 400dcfd14..2d9d47cdf 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -40,7 +40,8 @@ static void lv_pages_init(void); * STATIC VARIABLES **********************/ static lv_pages_t lv_pages_def; -static lv_pages_t lv_pages_simple; +static lv_pages_t lv_pages_paper; +static lv_pages_t lv_pages_menu; static lv_pages_t lv_pages_transp; static lv_design_f_t ancestor_design_f; @@ -81,20 +82,20 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new page object*/ if(copy == NULL) { - lv_pages_t * pages = lv_pages_get(LV_PAGES_DEF, NULL); + lv_pages_t * style = lv_pages_get(LV_PAGES_DEF, NULL); ext->scrl = lv_rect_create(new_page, NULL); lv_obj_set_signal_f(ext->scrl, lv_scrl_signal); lv_obj_set_drag(ext->scrl, true); lv_obj_set_drag_throw(ext->scrl, true); lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT); lv_rect_set_fit(ext->scrl, true, true); - lv_obj_set_style(ext->scrl, &pages->scrl_rects); + lv_obj_set_style(ext->scrl, &style->scrl); /* Add the signal function only if 'scrolling' is created * because everything has to be ready before any signal is received*/ lv_obj_set_signal_f(new_page, lv_page_signal); lv_obj_set_design_f(new_page, lv_page_design); - lv_obj_set_style(new_page, pages); + lv_obj_set_style(new_page, style); } else { lv_page_ext_t * copy_ext = lv_obj_get_ext(copy); ext->scrl = lv_rect_create(new_page, copy_ext->scrl); @@ -135,7 +136,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) * make the object specific signal handling */ if(obj_valid != false) { lv_page_ext_t * ext = lv_obj_get_ext(page); - lv_pages_t * pages = lv_obj_get_style(page); + lv_pages_t * style = lv_obj_get_style(page); lv_obj_t * child; switch(sign) { case LV_SIGNAL_CHILD_CHG: /*Move children to the scrollable object*/ @@ -152,11 +153,11 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) break; case LV_SIGNAL_STYLE_CHG: - area_set_height(&ext->sbh, pages->sb_width); - area_set_width(&ext->sbv, pages->sb_width); - lv_obj_set_style(ext->scrl, &pages->scrl_rects); + area_set_height(&ext->sbh, style->sb_width); + area_set_width(&ext->sbv, style->sb_width); + lv_obj_set_style(ext->scrl, &style->scrl); - if(pages->sb_mode == LV_PAGE_SB_MODE_ON) { + if(style->sb_mode == LV_PAGE_SB_MODE_ON) { ext->sbh_draw = 1; ext->sbv_draw = 1; } else { @@ -227,8 +228,8 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param) lv_obj_t * page = lv_obj_get_parent(scrl); lv_pages_t * style = lv_obj_get_style(page); lv_page_ext_t * page_ext = lv_obj_get_ext(page); - cord_t hpad = style->bg_rects.hpad; - cord_t vpad = style->bg_rects.vpad; + cord_t hpad = style->bg.hpad; + cord_t vpad = style->bg.vpad; switch(sign) { case LV_SIGNAL_CORD_CHG: @@ -281,8 +282,8 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param) case LV_SIGNAL_DRAG_BEGIN: if(style->sb_mode == LV_PAGE_SB_MODE_DRAG ) { - cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg_rects.hpad); - cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg_rects.vpad); + cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg.hpad); + cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg.vpad); if(area_get_height(&page_ext->sbv) < lv_obj_get_height(scrl) - 2 * sbv_pad) { page_ext->sbv_draw = 1; } @@ -400,8 +401,8 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en) if((obj_h <= page_h && top_err > 0) || (obj_h > page_h && top_err < bot_err)) { /*Calculate a new position and to let scrable_rects.vpad space above*/ - scrlable_y = -(obj_y - style->scrl_rects.vpad - style->bg_rects.vpad); - scrlable_y += style->scrl_rects.vpad; + scrlable_y = -(obj_y - style->scrl.vpad - style->bg.vpad); + scrlable_y += style->scrl.vpad; refr = true; } /*Out of the page on the bottom*/ @@ -410,7 +411,7 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en) /*Calculate a new position and to let scrable_rects.vpad space below*/ scrlable_y = -obj_y; scrlable_y += page_h - obj_h; - scrlable_y -= style->scrl_rects.vpad; + scrlable_y -= style->scrl.vpad; refr = true; } @@ -477,8 +478,11 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy) case LV_PAGES_DEF: style_p = &lv_pages_def; break; - case LV_PAGES_SIMPLE: - style_p = &lv_pages_simple; + case LV_PAGES_PAPER: + style_p = &lv_pages_paper; + break; + case LV_PAGES_MENU: + style_p = &lv_pages_menu; break; case LV_PAGES_TRANSP: style_p = &lv_pages_transp; @@ -487,10 +491,7 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy) style_p = &lv_pages_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_pages_t)); - else memcpy(copy, &lv_pages_def, sizeof(lv_pages_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_pages_t)); return style_p; } @@ -519,7 +520,6 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_ ancestor_design_f(page, mask, mode); lv_page_ext_t * ext = lv_obj_get_ext(page); lv_pages_t * style = lv_obj_get_style(page); - opa_t sb_opa = lv_obj_get_opa(page) * style->sb_opa /100; /*Draw the scrollbars*/ area_t sb_area; @@ -530,7 +530,7 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_ sb_area.y1 += page->cords.y1; sb_area.x2 += page->cords.x1; sb_area.y2 += page->cords.y1; - lv_draw_rect(&sb_area, mask, &style->sb_rects, sb_opa); + lv_draw_rect(&sb_area, mask, &style->sb); } if(ext->sbv_draw != 0) { @@ -540,7 +540,7 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_ sb_area.y1 += page->cords.y1; sb_area.x2 += page->cords.x1; sb_area.y2 += page->cords.y1; - lv_draw_rect(&sb_area, mask, &style->sb_rects, sb_opa); + lv_draw_rect(&sb_area, mask, &style->sb); } } @@ -565,12 +565,12 @@ static void lv_page_sb_refresh(lv_obj_t * page) cord_t size_tmp; cord_t scrl_w = lv_obj_get_width(scrl); cord_t scrl_h = lv_obj_get_height(scrl); - cord_t hpad = style->bg_rects.hpad; - cord_t vpad = style->bg_rects.vpad; + cord_t hpad = style->bg.hpad; + cord_t vpad = style->bg.vpad; cord_t obj_w = lv_obj_get_width(page); cord_t obj_h = lv_obj_get_height(page); - cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg_rects.hpad); - cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg_rects.vpad); + cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg.hpad); + cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg.vpad); if(style->sb_mode == LV_PAGE_SB_MODE_OFF) return; @@ -655,40 +655,56 @@ static void lv_page_sb_refresh(lv_obj_t * page) */ static void lv_pages_init(void) { - /*Default style*/ - lv_rects_get(LV_RECTS_DEF, &lv_pages_def.bg_rects); + /*Deafult style*/ + lv_rects_get(LV_RECTS_FANCY, &lv_pages_def.bg); + lv_pages_def.bg.swidth = 0; + lv_rects_get(LV_RECTS_PLAIN, &lv_pages_def.scrl); + lv_rects_get(LV_RECTS_PLAIN, &lv_pages_def.sb); + lv_pages_def.sb.base.opa = OPA_70; + lv_pages_def.sb.base.color = COLOR_SILVER; + lv_pages_def.sb.gcolor = COLOR_GRAY; + lv_pages_def.sb.bcolor = COLOR_GRAY; + lv_pages_def.sb.bopa = OPA_COVER; + lv_pages_def.sb.bwidth = LV_DPI / 50 == 0 ? 1 * LV_DOWNSCALE : LV_DPI / 50; + lv_pages_def.sb.radius = LV_RECT_CIRCLE; + lv_pages_def.sb_width = LV_DPI / 6; + lv_pages_def.sb_mode = LV_PAGE_SB_MODE_ON; - lv_rects_get(LV_RECTS_DEF, &lv_pages_def.scrl_rects); - lv_pages_def.scrl_rects.objs.color = COLOR_WHITE; - lv_pages_def.scrl_rects.gcolor = COLOR_SILVER; - lv_pages_def.scrl_rects.bcolor = COLOR_GRAY; + /*Paper style*/ + lv_rects_get(LV_RECTS_FANCY, &lv_pages_paper.bg); + lv_rects_get(LV_RECTS_TRANSP, &lv_pages_paper.scrl); + lv_pages_paper.scrl.hpad = LV_DPI / 4; + lv_pages_paper.scrl.vpad = LV_DPI / 4; + lv_pages_paper.scrl.opad = LV_DPI / 3; + lv_pages_paper.bg.hpad = 0; + lv_pages_paper.bg.vpad = 0; + lv_pages_paper.bg.opad = 0; + lv_pages_paper.bg.base.color = COLOR_WHITE; + lv_pages_paper.bg.gcolor = COLOR_SILVER; + memcpy(&lv_pages_paper.sb, &lv_pages_def.sb, sizeof(lv_rects_t)); + lv_pages_paper.sb_width = LV_DPI / 6; + lv_pages_paper.sb_mode = LV_PAGE_SB_MODE_AUTO; - lv_rects_get(LV_RECTS_DEF, &lv_pages_def.sb_rects); - lv_pages_def.sb_rects.objs.color = COLOR_BLACK; - lv_pages_def.sb_rects.gcolor = COLOR_BLACK; - lv_pages_def.sb_rects.bcolor = COLOR_WHITE; - lv_pages_def.sb_rects.bwidth = 1 * LV_DOWNSCALE; - lv_pages_def.sb_rects.round = 5 * LV_DOWNSCALE; - - lv_pages_def.sb_width= 8 * LV_DOWNSCALE; - lv_pages_def.sb_opa=50; - lv_pages_def.sb_mode = LV_PAGE_SB_MODE_AUTO; - - /*No (transparent) scrollable style*/ - memcpy(&lv_pages_simple, &lv_pages_def, sizeof(lv_pages_t)); - lv_rects_get(LV_RECTS_TRANSP, &lv_pages_simple.scrl_rects); - lv_pages_simple.scrl_rects.vpad = 0 * LV_DOWNSCALE; - lv_pages_simple.scrl_rects.hpad = 0 * LV_DOWNSCALE; + /*Menu style*/ + lv_rects_get(LV_RECTS_TRANSP, &lv_pages_menu.bg); + lv_rects_get(LV_RECTS_PLAIN, &lv_pages_menu.scrl); + lv_pages_menu.scrl.hpad = 0; + lv_pages_menu.scrl.vpad = 0; + lv_pages_menu.scrl.opad = LV_DPI / 6; + lv_pages_menu.bg.hpad = 0; + lv_pages_menu.bg.vpad = 0; + lv_pages_menu.bg.opad = 0; + lv_pages_menu.scrl.base.color = COLOR_SILVER; + lv_pages_menu.scrl.gcolor = COLOR_SILVER; + memcpy(&lv_pages_menu.sb, &lv_pages_def.sb, sizeof(lv_rects_t)); + lv_pages_menu.sb_width = LV_DPI / 6; + lv_pages_menu.sb_mode = LV_PAGE_SB_MODE_AUTO; /*Transparent style*/ - memcpy(&lv_pages_transp, &lv_pages_simple, sizeof(lv_pages_t)); - lv_rects_get(LV_RECTS_TRANSP, &lv_pages_transp.bg_rects); - lv_pages_transp.bg_rects.vpad = 10 * LV_DOWNSCALE; - lv_pages_transp.bg_rects.hpad = 10 * LV_DOWNSCALE; - lv_pages_transp.bg_rects.opad = 10 * LV_DOWNSCALE; - /* Make transparent bg. only witth bwidth = 0 nad empty = 1 - * because with transp = 1 the design function will not be called - * to draw the scrollbars*/ - lv_pages_transp.bg_rects.objs.transp = 0; + lv_rects_get(LV_RECTS_TRANSP, &lv_pages_transp.bg); + lv_rects_get(LV_RECTS_TRANSP, &lv_pages_transp.scrl); + memcpy(&lv_pages_transp.sb, &lv_pages_def.sb, sizeof(lv_rects_t)); + lv_pages_transp.sb_width = LV_DPI / 6; + lv_pages_transp.sb_mode = LV_PAGE_SB_MODE_AUTO; } #endif diff --git a/lv_objx/lv_page.h b/lv_objx/lv_page.h index 9ad5149fd..8ab794adb 100644 --- a/lv_objx/lv_page.h +++ b/lv_objx/lv_page.h @@ -54,20 +54,20 @@ typedef enum /*Style of page*/ typedef struct { - lv_rects_t bg_rects; /*Style of ancestor*/ + lv_rects_t bg; /*Style of ancestor*/ /*New style element for this type */ - lv_rects_t scrl_rects; /*Style of the scrollable rectangle*/ - lv_rects_t sb_rects; /*Style of scrollbars*/ - cord_t sb_width; /*Width of the scrollbars*/ - lv_page_sb_mode_t sb_mode; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/ - uint8_t sb_opa; /*Opacity of scrollbars in percentage of object opacity (0..100)*/ + lv_rects_t scrl; /*Style of the scrollable rectangle*/ + lv_rects_t sb; /*Style of scrollbars*/ + cord_t sb_width; /*Width of the scrollbars*/ + lv_page_sb_mode_t sb_mode; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/ }lv_pages_t; /*Built-in styles of page*/ typedef enum { - LV_PAGES_DEF, - LV_PAGES_SIMPLE, + LV_PAGES_DEF, + LV_PAGES_PAPER, /*White background, transparent scrollable*/ + LV_PAGES_MENU, /*Transparent background, gray scrollable*/ LV_PAGES_TRANSP, }lv_pages_builtin_t; diff --git a/lv_objx/lv_pb.c b/lv_objx/lv_pb.c index aa776c2d8..9673b53da 100644 --- a/lv_objx/lv_pb.c +++ b/lv_objx/lv_pb.c @@ -338,8 +338,7 @@ static bool lv_pb_design(lv_obj_t * pb, const area_t * mask, lv_design_mode_t mo } /*Draw the main bar*/ - opa_t opa = lv_obj_get_opa(pb); - lv_draw_rect(&bar_area, mask, &style->bar, opa); + lv_draw_rect(&bar_area, mask, &style->bar); /*Draw a button if its size is not 0*/ if(style->btn_size != 0) { @@ -372,7 +371,7 @@ static bool lv_pb_design(lv_obj_t * pb, const area_t * mask, lv_design_mode_t mo } } - lv_draw_rect(&bar_area, mask, &tmp_rects, opa ); + lv_draw_rect(&bar_area, mask, &tmp_rects ); } } return true; @@ -401,32 +400,31 @@ void lv_pb_set_tmp_value(lv_obj_t * pb, int16_t value) static void lv_pbs_init(void) { /*Default style*/ - lv_rects_get(LV_RECTS_DEF, &lv_pbs_def.bg); /*Background*/ - lv_pbs_def.bg.objs.color = COLOR_WHITE; + lv_rects_get(LV_RECTS_PLAIN, &lv_pbs_def.bg); /*Background*/ + lv_pbs_def.bg.base.color = COLOR_WHITE; lv_pbs_def.bg.gcolor = COLOR_SILVER, lv_pbs_def.bg.bcolor = COLOR_BLACK; - lv_rects_get(LV_RECTS_DEF, &lv_pbs_def.bar); /*Bar*/ - lv_pbs_def.bar.objs.color = COLOR_LIME; + lv_rects_get(LV_RECTS_PLAIN, &lv_pbs_def.bar); /*Bar*/ + lv_pbs_def.bar.base.color = COLOR_LIME; lv_pbs_def.bar.gcolor = COLOR_GREEN; lv_pbs_def.bar.bcolor = COLOR_BLACK; - lv_rects_get(LV_RECTS_DEF, &lv_pbs_def.btn); /*Button*/ - lv_pbs_def.btn.objs.color = COLOR_WHITE; + lv_rects_get(LV_RECTS_FANCY, &lv_pbs_def.btn); /*Button*/ + lv_pbs_def.btn.base.color = COLOR_WHITE; lv_pbs_def.btn.gcolor = COLOR_GRAY; lv_pbs_def.btn.bcolor = COLOR_GRAY; lv_pbs_def.btn.bopa = 100; lv_pbs_def.btn_size = 0; - lv_labels_get(LV_LABELS_DEF, &lv_pbs_def.label); /*Label*/ - lv_pbs_def.label.objs.color = COLOR_MAKE(0x20, 0x20, 0x20); + lv_labels_get(LV_LABELS_TXT, &lv_pbs_def.label); /*Label*/ lv_pbs_def.label.line_space = 0; /*Slider style*/ memcpy(&lv_pbs_slider, &lv_pbs_def, sizeof(lv_pbs_t)); - lv_pbs_slider.bg.round = LV_RECT_CIRCLE; - lv_pbs_slider.bar.round = LV_RECT_CIRCLE; - lv_pbs_slider.btn.round = LV_RECT_CIRCLE; + lv_pbs_slider.bg.radius = LV_RECT_CIRCLE; + lv_pbs_slider.bar.radius = LV_RECT_CIRCLE; + lv_pbs_slider.btn.radius = LV_RECT_CIRCLE; lv_pbs_slider.btn_size = 40 * LV_DOWNSCALE; } diff --git a/lv_objx/lv_rect.c b/lv_objx/lv_rect.c index 626b25741..bde81cacf 100644 --- a/lv_objx/lv_rect.c +++ b/lv_objx/lv_rect.c @@ -36,7 +36,7 @@ * STATIC PROTOTYPES **********************/ static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_t mode); -static void lv_rect_draw_light(lv_obj_t * rect, const area_t * mask); +static void lv_rect_draw_shadow(lv_obj_t * rect, const area_t * mask); static void lv_rect_refr_layout(lv_obj_t * rect); static void lv_rect_layout_col(lv_obj_t * rect); static void lv_rect_layout_row(lv_obj_t * rect); @@ -49,9 +49,10 @@ static void lv_rects_init(void); /********************** * STATIC VARIABLES **********************/ -static lv_rects_t lv_rects_def; -static lv_rects_t lv_rects_transp; +static lv_rects_t lv_rects_plain; +static lv_rects_t lv_rects_fancy; static lv_rects_t lv_rects_border; +static lv_rects_t lv_rects_transp; /********************** * MACROS @@ -88,7 +89,7 @@ lv_obj_t * lv_rect_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new rectangle*/ if(copy == NULL) { - lv_obj_set_style(new_rect, lv_rects_get(LV_RECTS_DEF, NULL)); + lv_obj_set_style(new_rect, lv_rects_get(LV_RECTS_PLAIN, NULL)); } /*Copy an existing object*/ else { @@ -142,7 +143,7 @@ bool lv_rect_signal(lv_obj_t * rect, lv_signal_t sign, void * param) } break; case LV_SIGNAL_REFR_EXT_SIZE: - if(style->light > rect->ext_size) rect->ext_size = style->light; + if(style->swidth > rect->ext_size) rect->ext_size = style->swidth; break; default: break; @@ -246,9 +247,12 @@ lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy) lv_rects_t * style_p; switch(style) { - case LV_RECTS_DEF: - style_p = &lv_rects_def; + case LV_RECTS_PLAIN: + style_p = &lv_rects_plain; break; + case LV_RECTS_FANCY: + style_p = &lv_rects_fancy; + break; case LV_RECTS_BORDER: style_p = &lv_rects_border; break; @@ -256,12 +260,11 @@ lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy) style_p = &lv_rects_transp; break; default: - style_p = &lv_rects_def; + style_p = &lv_rects_plain; } if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_rects_t)); - else memcpy(copy, &lv_rects_def, sizeof(lv_rects_t)); + memcpy(copy, style_p, sizeof(lv_rects_t)); } return style_p; @@ -289,7 +292,7 @@ static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_ * Check the areas where there is no radius*/ if(LV_SA(rect, lv_rects_t)->empty != 0) return false; - uint16_t r = LV_SA(rect, lv_rects_t)->round; + uint16_t r = LV_SA(rect, lv_rects_t)->radius; if(r == LV_RECT_CIRCLE) return false; @@ -309,14 +312,13 @@ static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_ return false; } else if(mode == LV_DESIGN_DRAW_MAIN) { - opa_t opa = lv_obj_get_opa(rect); lv_rects_t * style = lv_obj_get_style(rect); area_t area; lv_obj_get_cords(rect, &area); /*Draw the rectangle*/ - lv_draw_rect(&area, mask, style, opa); - lv_rect_draw_light(rect, mask); + lv_draw_rect(&area, mask, style); + lv_rect_draw_shadow(rect, mask); } else if(mode == LV_DESIGN_DRAW_POST) { @@ -325,50 +327,50 @@ static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_ } /** - * Draw a light around the object + * Draw a shadow around the object * @param rect pointer to rectangle object * @param mask pointer to a mask area (from the design functions) */ -static void lv_rect_draw_light(lv_obj_t * rect, const area_t * mask) +static void lv_rect_draw_shadow(lv_obj_t * rect, const area_t * mask) { lv_rects_t * style = lv_obj_get_style(rect); - cord_t light_size = style->light; - if(light_size == 0) return; - if(light_size < LV_DOWNSCALE) light_size = LV_DOWNSCALE; + cord_t swidth = style->swidth; + if(swidth == 0) return; + uint8_t res = LV_DOWNSCALE * 2; + if(swidth < res) return; - area_t light_area; - lv_rects_t light_style; - lv_obj_get_cords(rect, &light_area); + area_t shadow_area; + lv_rects_t shadow_style; + lv_obj_get_cords(rect, &shadow_area); - memcpy(&light_style, style, sizeof(lv_rects_t)); + memcpy(&shadow_style, style, sizeof(lv_rects_t)); - light_style.empty = 1; - light_style.bwidth = light_size; - light_style.round = style->round; - if(light_style.round == LV_RECT_CIRCLE) { - light_style.round = MATH_MIN(lv_obj_get_width(rect), lv_obj_get_height(rect)); + shadow_style.empty = 1; + shadow_style.bwidth = swidth; + shadow_style.radius = style->radius; + if(shadow_style.radius == LV_RECT_CIRCLE) { + shadow_style.radius = MATH_MIN(lv_obj_get_width(rect), lv_obj_get_height(rect)); } - light_style.round += light_size + 1; - light_style.bcolor = style->lcolor; - light_style.bopa = 100; + shadow_style.radius += swidth + 1; + shadow_style.bcolor = style->scolor; + shadow_style.bopa = 100; - light_area.x1 -= light_size; - light_area.y1 -= light_size; - light_area.x2 += light_size; - light_area.y2 += light_size; + shadow_area.x1 -= swidth; + shadow_area.y1 -= swidth; + shadow_area.x2 += swidth; + shadow_area.y2 += swidth; cord_t i; - uint8_t res = LV_DOWNSCALE ; - opa_t opa_sub = lv_obj_get_opa(rect) / (light_size / LV_DOWNSCALE); + shadow_style.base.opa = style->base.opa / (swidth / res); - for(i = 1; i < light_size; i += res) { - lv_draw_rect(&light_area, mask, &light_style, (uint16_t) opa_sub); - light_style.round -= res; - light_style.bwidth -= res; - light_area.x1 += res; - light_area.y1 += res; - light_area.x2 -= res; - light_area.y2 -= res; + for(i = 1; i < swidth; i += res) { + lv_draw_rect(&shadow_area, mask, &shadow_style); + shadow_style.radius -= res; + shadow_style.bwidth -= res; + shadow_area.x1 += res; + shadow_area.y1 += res; + shadow_area.x2 -= res; + shadow_area.y2 -= res; } } @@ -742,32 +744,51 @@ static void lv_rect_refr_autofit(lv_obj_t * rect) */ static void lv_rects_init(void) { - /*Default style*/ - lv_rects_def.objs.color = COLOR_MAKE(0x50, 0x70, 0x90); - lv_rects_def.gcolor = COLOR_MAKE(0x70, 0xA0, 0xC0); - lv_rects_def.bcolor = COLOR_WHITE; - lv_rects_def.bwidth = 2 * LV_DOWNSCALE; - lv_rects_def.bopa = 50; - lv_rects_def.round = 4 * LV_DOWNSCALE; - lv_rects_def.empty = 0; - lv_rects_def.hpad = 10 * LV_DOWNSCALE; - lv_rects_def.vpad = 10 * LV_DOWNSCALE; - lv_rects_def.opad = 10 * LV_DOWNSCALE; - lv_rects_def.light = 0; - lv_rects_def.lcolor = COLOR_MAKE(0x60, 0x60, 0x60); + /*Plain style*/ + lv_objs_get(LV_OBJS_PLAIN, &lv_rects_plain.base); + lv_rects_plain.base.color = COLOR_MAKE(0x80, 0xb3, 0xe6); //6BA3BF + lv_rects_plain.gcolor = lv_rects_plain.base.color; + lv_rects_plain.bcolor = COLOR_WHITE; + lv_rects_plain.scolor = COLOR_GRAY; + lv_rects_plain.bwidth = (LV_DPI / 30) == 0 ? 1 * LV_DOWNSCALE : LV_DPI / 30; + lv_rects_plain.swidth = 0; + lv_rects_plain.bopa = OPA_COVER; + lv_rects_plain.radius = LV_DPI / 10; + lv_rects_plain.empty = 0; + lv_rects_plain.hpad = LV_DPI / 2; + lv_rects_plain.vpad = LV_DPI / 2; + lv_rects_plain.opad = LV_DPI / 4; + + /*Fancy style*/ + lv_objs_get(LV_OBJS_PLAIN, &lv_rects_fancy.base); + lv_rects_fancy.gcolor = COLOR_MAKE(0xd3, 0xe1, 0xea); + lv_rects_fancy.bcolor = COLOR_WHITE; + lv_rects_fancy.scolor = COLOR_GRAY; + lv_rects_fancy.bwidth = (LV_DPI / 30) == 0 ? 1 * LV_DOWNSCALE : LV_DPI / 30; + lv_rects_fancy.swidth = LV_DPI / 8; + lv_rects_fancy.bopa = OPA_50; + lv_rects_fancy.radius = LV_DPI / 10; + lv_rects_fancy.empty = 0; + lv_rects_fancy.hpad = LV_DPI / 4; + lv_rects_fancy.vpad = LV_DPI / 4; + lv_rects_fancy.opad = LV_DPI / 6; + /*Transparent style*/ - memcpy(&lv_rects_transp, &lv_rects_def, sizeof(lv_rects_t)); - lv_rects_transp.objs.transp = 1; - lv_rects_transp.bwidth = 0; + memcpy(&lv_rects_transp, &lv_rects_plain, sizeof(lv_rects_t)); + /* Do not use opa=OPA_TRANSP because design function will not be called + * but it might draw something on transparent background*/ lv_rects_transp.empty = 1; + lv_rects_transp.bwidth = 0; + lv_rects_transp.swidth = 0; + lv_rects_transp.hpad = 0; + lv_rects_transp.vpad = 0; /*Border style*/ - memcpy(&lv_rects_border, &lv_rects_def, sizeof(lv_rects_t)); - lv_rects_border.bcolor = COLOR_BLACK; - lv_rects_border.bwidth = 2 * LV_DOWNSCALE; - lv_rects_border.bopa = 100; - lv_rects_border.round = 4 * LV_DOWNSCALE; + memcpy(&lv_rects_border, &lv_rects_plain, sizeof(lv_rects_t)); + lv_rects_border.bcolor = COLOR_MAKE(0x30, 0x30, 0x30); + lv_rects_border.bwidth = LV_DPI / 30; + lv_rects_border.swidth = 0; lv_rects_border.empty = 1; } #endif diff --git a/lv_objx/lv_rect.h b/lv_objx/lv_rect.h index a38954886..3a17e0108 100644 --- a/lv_objx/lv_rect.h +++ b/lv_objx/lv_rect.h @@ -52,27 +52,28 @@ typedef struct /*Style of rectangle*/ typedef struct { - lv_objs_t objs; /*Style of ancestor*/ + lv_objs_t base; /*Style of ancestor*/ /*New style element for this type */ color_t gcolor; /*Gradient color*/ color_t bcolor; /*Border color*/ - color_t lcolor; /*Light color*/ - uint16_t bwidth;/*Border width*/ - uint16_t round; /*Radius on the corners*/ + color_t scolor; /*Shadow color*/ + cord_t bwidth; /*Border width*/ + cord_t swidth; /*Shadow width*/ + cord_t radius; /*Radius on the corners*/ cord_t hpad; /*Horizontal padding. Used by fit and layout.*/ cord_t vpad; /*Vertical padding. Used by fit and layout.*/ cord_t opad; /*Object padding. Used by fit */ - cord_t light; /*Light size*/ - uint8_t bopa; /*Border opacity in percentage of object opacity (0..100)*/ + opa_t bopa; /*Border opacity relative to the object*/ uint8_t empty :1; /*1: Do not draw the body of the rectangle*/ }lv_rects_t; /*Built-in styles of rectangle*/ typedef enum { - LV_RECTS_DEF, - LV_RECTS_TRANSP, + LV_RECTS_PLAIN, + LV_RECTS_FANCY, LV_RECTS_BORDER, + LV_RECTS_TRANSP, }lv_rects_builtin_t; /********************** diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 8a8f5f06a..7d7996d71 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -46,8 +46,6 @@ static void lv_tas_init(void); * STATIC VARIABLES **********************/ static lv_tas_t lv_tas_def; -static lv_tas_t lv_tas_simple; -static lv_tas_t lv_tas_transp; lv_design_f_t ancestor_design_f; lv_design_f_t scrl_design_f; @@ -158,9 +156,9 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) break; case LV_SIGNAL_STYLE_CHG: if(ext->label) { - lv_obj_set_style(ext->label, &style->labels); + lv_obj_set_style(ext->label, &style->label); lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 * - (style->pages.bg_rects.hpad + style->pages.scrl_rects.hpad)); + (style->page.bg.hpad + style->page.scrl.hpad)); lv_label_set_text(ext->label, NULL); } break; @@ -168,7 +166,7 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) case LV_SIGNAL_CORD_CHG: if(ext->label != NULL) { lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 * - (style->pages.bg_rects.hpad + style->pages.scrl_rects.hpad)); + (style->page.bg.hpad + style->page.scrl.hpad)); lv_label_set_text(ext->label, NULL); } break; @@ -313,7 +311,7 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) lv_obj_t * label_par = lv_obj_get_parent(ext->label); point_t cur_pos; lv_tas_t * style = lv_obj_get_style(ta); - const font_t * font_p = font_get(style->labels.font); + const font_t * font_p = style->label.font; area_t label_cords; area_t ta_cords; lv_label_get_letter_pos(ext->label, pos, &cur_pos); @@ -327,9 +325,9 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) /*Check the bottom*/ cord_t font_h = font_get_height(font_p) >> LV_FONT_ANTIALIAS; - if(label_cords.y1 + cur_pos.y + font_h + style->pages.scrl_rects.vpad > ta_cords.y2) { + if(label_cords.y1 + cur_pos.y + font_h + style->page.scrl.vpad > ta_cords.y2) { lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) + - font_h + 2 * style->pages.scrl_rects.vpad)); + font_h + 2 * style->page.scrl.vpad)); } lv_obj_inv(ta); @@ -380,7 +378,7 @@ void lv_ta_cursor_down(lv_obj_t * ta) /*Increment the y with one line and keep the valid x*/ lv_labels_t * label_style = lv_obj_get_style(ext->label); - const font_t * font_p = font_get(label_style->font); + const font_t * font_p = label_style->font; cord_t font_h = font_get_height(font_p) >> LV_FONT_ANTIALIAS; pos.y += font_h + label_style->line_space + 1; pos.x = ext->cursor_valid_x; @@ -407,7 +405,7 @@ void lv_ta_cursor_up(lv_obj_t * ta) /*Decrement the y with one line and keep the valid x*/ lv_labels_t * label_style = lv_obj_get_style(ext->label); - const font_t * font = font_get(label_style->font); + const font_t * font = label_style->font; cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS; pos.y -= font_h + label_style->line_space - 1; pos.x = ext->cursor_valid_x; @@ -464,20 +462,11 @@ lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy) case LV_TAS_DEF: style_p = &lv_tas_def; break; - case LV_TAS_SIMPLE: - style_p = &lv_tas_simple; - break; - case LV_TAS_TRANSP: - style_p = &lv_tas_transp; - break; default: style_p = &lv_tas_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_tas_t)); - else memcpy(copy, &lv_tas_def, sizeof(lv_tas_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_tas_t)); return style_p; } @@ -546,15 +535,15 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 - (ta_style->cursor_width >> 1); cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1; cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + (ta_style->cursor_width >> 1); - cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + (font_get_height(font_get(labels_p->font)) >> LV_FONT_ANTIALIAS); + cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + (font_get_height(labels_p->font) >> LV_FONT_ANTIALIAS); lv_rects_t cur_rects; - lv_rects_get(LV_RECTS_DEF, &cur_rects); - cur_rects.round = 0; + lv_rects_get(LV_RECTS_PLAIN, &cur_rects); + cur_rects.radius = 0; cur_rects.bwidth = 0; - cur_rects.objs.color = ta_style->cursor_color; + cur_rects.base.color = ta_style->cursor_color; cur_rects.gcolor = ta_style->cursor_color; - lv_draw_rect(&cur_area, mask, &cur_rects, OPA_COVER); + lv_draw_rect(&cur_area, mask, &cur_rects); } } @@ -594,27 +583,14 @@ static void lv_ta_save_valid_cursor_x(lv_obj_t * ta) static void lv_tas_init(void) { /*Default style*/ - lv_pages_get(LV_PAGES_DEF, &lv_tas_def.pages); - lv_tas_def.pages.sb_mode = LV_PAGE_SB_MODE_DRAG; + lv_pages_get(LV_PAGES_PAPER, &lv_tas_def.page); + lv_tas_def.page.sb_mode = LV_PAGE_SB_MODE_DRAG; - lv_labels_get(LV_LABELS_TXT, &lv_tas_def.labels); - lv_tas_def.labels.objs.color = COLOR_MAKE(0x20, 0x20, 0x20); + lv_labels_get(LV_LABELS_TXT, &lv_tas_def.label); lv_tas_def.cursor_color = COLOR_MAKE(0x10, 0x10, 0x10); lv_tas_def.cursor_width = 1 * LV_DOWNSCALE; /*>=1 px for visible cursor*/ lv_tas_def.cursor_show = 1; - memcpy(&lv_tas_simple, &lv_tas_def, sizeof(lv_tas_t)); - lv_pages_get(LV_PAGES_SIMPLE, &lv_tas_simple.pages); - lv_tas_simple.pages.sb_mode = LV_PAGE_SB_MODE_DRAG; - lv_tas_simple.pages.scrl_rects.objs.transp = 0; /*if transp == 1 the cursor will not be drawn*/ - lv_tas_simple.pages.bg_rects.objs.color = COLOR_WHITE; - lv_tas_simple.pages.bg_rects.gcolor = COLOR_SILVER; - lv_tas_simple.pages.bg_rects.bcolor = COLOR_GRAY; - - memcpy(&lv_tas_transp, &lv_tas_def, sizeof(lv_tas_t)); - lv_pages_get(LV_PAGES_TRANSP, &lv_tas_transp.pages); - lv_tas_transp.pages.scrl_rects.objs.transp = 0; /*if transp == 1 the cursor will not be drawn*/ - } #endif diff --git a/lv_objx/lv_ta.h b/lv_objx/lv_ta.h index 4a8bbc55c..6af19129f 100644 --- a/lv_objx/lv_ta.h +++ b/lv_objx/lv_ta.h @@ -48,9 +48,9 @@ typedef struct /*Style of text area*/ typedef struct { - lv_pages_t pages; /*Style of ancestor*/ + lv_pages_t page; /*Style of ancestor*/ /*New style element for this type */ - lv_labels_t labels; + lv_labels_t label; color_t cursor_color; cord_t cursor_width; uint8_t cursor_show :1; @@ -60,8 +60,6 @@ typedef struct typedef enum { LV_TAS_DEF, - LV_TAS_SIMPLE, - LV_TAS_TRANSP, }lv_tas_builtin_t; /********************** diff --git a/lv_objx/lv_win.c b/lv_objx/lv_win.c index c1a63df0c..61ebe0525 100644 --- a/lv_objx/lv_win.c +++ b/lv_objx/lv_win.c @@ -69,8 +69,10 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new window object*/ if(copy == NULL) { - lv_obj_set_size(new_win, lv_obj_get_width(new_win), lv_obj_get_height(new_win)); + lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES); lv_obj_set_pos(new_win, 0, 0); + lv_obj_t * scrl = lv_page_get_scrl(new_win); + lv_rect_set_fit(scrl, false, true); /*Create a holder for the header*/ ext->header = lv_rect_create(new_win, NULL); @@ -151,14 +153,12 @@ bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param) lv_obj_set_style(ext->ctrl_holder, &style->ctrl_holder); lv_obj_set_style(ext->title, &style->title); lv_obj_set_style(ext->header, &style->header); - lv_obj_set_opa(ext->header, style->header_opa); /*Refresh the style of all control buttons*/ child = lv_obj_get_child(ext->ctrl_holder, NULL); while(child != NULL) { lv_obj_set_style(child, &style->ctrl_btn); - lv_obj_set_opa(child, style->ctrl_btn_opa); /*Refresh the image style too*/ lv_obj_set_style(lv_obj_get_child(child, NULL), &style->ctrl_img); @@ -201,7 +201,6 @@ lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img_path, lv_action_ lv_obj_t * btn = lv_btn_create(ext->ctrl_holder, NULL); lv_obj_set_style(btn, &style->ctrl_btn); - lv_obj_set_opa(btn, style->ctrl_btn_opa); lv_obj_set_size(btn, style->ctrl_btn_w, style->ctrl_btn_h); lv_btn_set_rel_action(btn, rel_action); @@ -299,10 +298,7 @@ lv_wins_t * lv_wins_get(lv_wins_builtin_t style, lv_wins_t * copy) style_p = &lv_wins_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_wins_t)); - else memcpy(copy, &lv_wins_def, sizeof(lv_wins_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_wins_t)); return style_p; } @@ -347,51 +343,42 @@ static bool lv_win_design(lv_obj_t * win, const area_t * mask, lv_design_mode_t static void lv_wins_init(void) { /*Style for the content*/ - lv_pages_get(LV_PAGES_DEF, &lv_wins_def.pages); - lv_wins_def.pages.bg_rects.objs.color = COLOR_WHITE; - lv_wins_def.pages.bg_rects.gcolor = COLOR_WHITE; - lv_wins_def.pages.bg_rects.bwidth = 1 * LV_DOWNSCALE; - lv_wins_def.pages.bg_rects.bcolor = COLOR_GRAY; - lv_wins_def.pages.bg_rects.round = 0; - lv_wins_def.pages.bg_rects.hpad = 0; - lv_wins_def.pages.bg_rects.vpad = 0; + lv_pages_get(LV_PAGES_PAPER, &lv_wins_def.page); /*LV_PAGES_PAPER: White bg, transparent scrl*/ + lv_wins_def.page.bg.base.color = COLOR_WHITE; + lv_wins_def.page.bg.gcolor = COLOR_WHITE; + lv_wins_def.page.bg.bwidth = 1 * LV_DOWNSCALE; + lv_wins_def.page.bg.bcolor = COLOR_GRAY; + lv_wins_def.page.bg.radius = 0; + lv_wins_def.page.bg.vpad = LV_DPI; /*Great vpad on the background to move the content below the header*/ + lv_wins_def.page.bg.hpad = LV_DPI / 4; /*Styles for the header*/ - lv_rects_get(LV_RECTS_DEF, &lv_wins_def.header); - lv_wins_def.header.hpad = 5 * LV_DOWNSCALE; - lv_wins_def.header.vpad = 5 * LV_DOWNSCALE; - lv_wins_def.header.objs.color = COLOR_MAKE(0x30, 0x40, 0x50); - lv_wins_def.header.gcolor = COLOR_MAKE(0x30, 0x40, 0x50); + lv_rects_get(LV_RECTS_PLAIN, &lv_wins_def.header); + lv_wins_def.header.bwidth = 0; + lv_wins_def.header.radius = 0; + lv_wins_def.header.hpad = LV_DPI / 10; + lv_wins_def.header.vpad = LV_DPI / 10; lv_wins_def.header.bwidth = 0; - lv_wins_def.header.round = 0; + lv_wins_def.header.radius = 0; lv_rects_get(LV_RECTS_TRANSP, &lv_wins_def.ctrl_holder); lv_wins_def.ctrl_holder.hpad = 0; lv_wins_def.ctrl_holder.vpad = 0; - lv_wins_def.ctrl_holder.opad = 5 * LV_DOWNSCALE; + lv_wins_def.ctrl_holder.opad = LV_DPI / 10; lv_btns_get(LV_BTNS_DEF, &lv_wins_def.ctrl_btn); - lv_wins_def.ctrl_btn.bcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0xD0, 0xE0, 0xF0); - lv_wins_def.ctrl_btn.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_wins_def.ctrl_btn.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x30, 0x40, 0x50); - lv_wins_def.ctrl_btn.rects.bopa = 70; - lv_wins_def.ctrl_btn.rects.bwidth = 2 * LV_DOWNSCALE; - lv_wins_def.ctrl_btn.rects.round = LV_RECT_CIRCLE; + lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_REL].swidth = 0; + lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_PR].swidth = 0; + lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_TREL].swidth = 0; + lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_TPR].swidth = 0; + lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_INA].swidth = 0; lv_imgs_get(LV_IMGS_DEF, &lv_wins_def.ctrl_img); - lv_wins_def.ctrl_img.recolor_opa = OPA_50; - lv_wins_def.ctrl_img.objs.color = COLOR_WHITE; lv_labels_get(LV_LABELS_TITLE, &lv_wins_def.title); - lv_wins_def.title.objs.color = COLOR_MAKE(0xD0, 0xE0, 0xF0); - lv_wins_def.title.letter_space = 1 * LV_DOWNSCALE; - lv_wins_def.title.line_space = 1 * LV_DOWNSCALE; - lv_wins_def.ctrl_btn_w = 30 * LV_DOWNSCALE; - lv_wins_def.ctrl_btn_h = 30 * LV_DOWNSCALE; - - lv_wins_def.header_opa = OPA_COVER; - lv_wins_def.ctrl_btn_opa = OPA_COVER; + lv_wins_def.ctrl_btn_w = 2 * LV_DPI / 3; + lv_wins_def.ctrl_btn_h = 2 * LV_DPI / 3; } /** @@ -427,6 +414,8 @@ static void lv_win_realign(lv_obj_t * win) lv_obj_set_pos_us(ext->header, 0, 0); + lv_obj_t * scrl = lv_page_get_scrl(win); + lv_obj_set_width(scrl, LV_HOR_RES - 2 * style->page.bg.hpad); } #endif diff --git a/lv_objx/lv_win.h b/lv_objx/lv_win.h index 85f2e480a..57a229948 100644 --- a/lv_objx/lv_win.h +++ b/lv_objx/lv_win.h @@ -65,7 +65,7 @@ typedef struct /*Style of window*/ typedef struct { - lv_pages_t pages; /*Style of ancestor*/ + lv_pages_t page; /*Style of ancestor*/ /*New style element for this type */ /*Header settings*/ lv_rects_t header; /*Style of the header rectangle*/ @@ -75,8 +75,6 @@ typedef struct lv_imgs_t ctrl_img; /*Style of the image on the control buttons*/ cord_t ctrl_btn_w; /*Width of the control buttons*/ cord_t ctrl_btn_h; /*Height of the control buttons*/ - opa_t ctrl_btn_opa; /*Width of the control buttons in the percentage of object opacity (0..100)*/ - opa_t header_opa; /*Opacity of the header in the percentage of object opacity (0..100)*/ }lv_wins_t; /*Built-in styles of window*/