diff --git a/lv_conf_templ.h b/lv_conf_templ.h index f946864b2..a4712fea6 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -382,6 +382,13 @@ /************************* * Non-user section *************************/ + +#if LV_INDEV_DRAG_THROW <= 0 +#warning "LV_INDEV_DRAG_THROW must be greater than 0" +#undef LV_INDEV_DRAG_THROW +#define LV_INDEV_DRAG_THROW 1 +#endif + #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ # define _CRT_SECURE_NO_WARNINGS #endif diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index 46b71d15f..16235f32d 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -8,7 +8,9 @@ *********************/ #include "lv_group.h" #if USE_LV_GROUP != 0 +#include "../lv_themes/lv_theme.h" #include +#include "../lv_misc/lv_gc.h" /********************* * DEFINES @@ -23,7 +25,8 @@ **********************/ static void style_mod_def(lv_style_t * style); static void style_mod_edit_def(lv_style_t * style); -static void lv_group_refocus(lv_group_t *g); +static void refresh_theme(lv_group_t * g, lv_theme_t * th); +static void lv_group_refocus(lv_group_t * g); /********************** * STATIC VARIABLES @@ -37,24 +40,35 @@ static void lv_group_refocus(lv_group_t *g); * GLOBAL FUNCTIONS **********************/ +/** + * Init. the group module + */ +void lv_group_init(void) +{ + lv_ll_init(&LV_GC_ROOT(_lv_group_ll), sizeof(lv_group_t)); +} + /** * Create a new object group * @return pointer to the new object group */ lv_group_t * lv_group_create(void) { - lv_group_t * group = lv_mem_alloc(sizeof(lv_group_t)); + lv_group_t * group = lv_ll_ins_head(&LV_GC_ROOT(_lv_group_ll)); lv_mem_assert(group); if(group == NULL) return NULL; lv_ll_init(&group->obj_ll, sizeof(lv_obj_t *)); - group->style_mod = style_mod_def; - group->style_mod_edit = style_mod_edit_def; group->obj_focus = NULL; group->frozen = 0; group->focus_cb = NULL; group->click_focus = 1; group->editing = 0; + group->refocus_policy = LV_GROUP_REFOCUS_POLICY_PREV; + group->wrap = 1; + + /*Initialize style modification callbacks from current theme*/ + refresh_theme(group, lv_theme_get_current()); return group; } @@ -460,6 +474,25 @@ bool lv_group_get_wrap(lv_group_t * group) return group->wrap ? true : false; } +/** + * Notify the group that current theme changed and style modification callbacks need to be refreshed. + * @param group pointer to group. If NULL then all groups are notified. + */ +void lv_group_report_style_mod(lv_group_t * group) +{ + lv_theme_t * th = lv_theme_get_current(); + + if(group != NULL) { + refresh_theme(group, th); + return; + } + + lv_group_t * i; + LL_READ(LV_GC_ROOT(_lv_group_ll), i) { + refresh_theme(i, th); + } +} + /********************** * STATIC FUNCTIONS **********************/ @@ -522,4 +555,16 @@ static void style_mod_edit_def(lv_style_t * style) } +static void refresh_theme(lv_group_t * g, lv_theme_t * th) +{ + g->style_mod = style_mod_def; + g->style_mod_edit = style_mod_edit_def; + if(th) { + if(th->group.style_mod) + g->style_mod = th->group.style_mod; + if(th->group.style_mod_edit) + g->style_mod_edit = th->group.style_mod_edit; + } +} + #endif /*USE_LV_GROUP != 0*/ diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index 6be9b5cca..7b3a6d482 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -36,6 +36,8 @@ extern "C" { #define LV_GROUP_KEY_ENTER 10 /*0x0A, '\n'*/ #define LV_GROUP_KEY_NEXT 9 /*0x09, '\t'*/ #define LV_GROUP_KEY_PREV 11 /*0x0B, '*/ +#define LV_GROUP_KEY_HOME 2 /*0x02, STX*/ +#define LV_GROUP_KEY_END 3 /*0x03, ETX*/ #if USE_LV_GROUP != 0 /********************** @@ -70,6 +72,12 @@ typedef enum _lv_group_refocus_policy_t { * GLOBAL PROTOTYPES **********************/ +/** +* Init. the group module +* @remarks Internal function, do not call directly. +*/ +void lv_group_init(void); + /** * Create a new object group * @return pointer to the new object group @@ -234,6 +242,12 @@ bool lv_group_get_click_focus(const lv_group_t * group); */ bool lv_group_get_wrap(lv_group_t * group); +/** + * Notify the group that current theme changed and style modification callbacks need to be refreshed. + * @param group pointer to group. If NULL then all groups are notified. + */ +void lv_group_report_style_mod(lv_group_t * group); + /********************** * MACROS **********************/ diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index bdf348d5b..01d1f03ce 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -582,18 +582,20 @@ static void indev_proc_press(lv_indev_proc_t * proc) if(proc->wait_unil_release != 0) return; + lv_disp_t * disp = indev_act->driver.disp; + /*If there is no last object then search*/ if(proc->act_obj == NULL) { - pr_obj = indev_search_obj(proc, lv_layer_sys(NULL)); - if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_layer_top(NULL)); - if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act(NULL)); + pr_obj = indev_search_obj(proc, lv_layer_sys(disp)); + if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_layer_top(disp)); + if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act(disp)); } /*If there is last object but it is not dragged and not protected also search*/ else if(proc->drag_in_prog == 0 && lv_obj_is_protected(proc->act_obj, LV_PROTECT_PRESS_LOST) == false) {/*Now act_obj != NULL*/ - pr_obj = indev_search_obj(proc, lv_layer_sys(NULL)); - if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_layer_top(NULL)); - if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act(NULL)); + pr_obj = indev_search_obj(proc, lv_layer_sys(disp)); + if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_layer_top(disp)); + if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act(disp)); } /*If a dragable or a protected object was the last then keep it*/ else { diff --git a/lv_core/lv_obj.c b/lv_core/lv_obj.c index 891428e04..59c3d2c0f 100644 --- a/lv_core/lv_obj.c +++ b/lv_core/lv_obj.c @@ -38,9 +38,9 @@ /********************** * STATIC PROTOTYPES **********************/ -static void refresh_childen_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff); +static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff); static void report_style_mod_core(void * style_p, lv_obj_t * obj); -static void refresh_childen_style(lv_obj_t * obj); +static void refresh_children_style(lv_obj_t * obj); static void delete_children(lv_obj_t * obj); static bool lv_obj_design(lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode); static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param); @@ -86,6 +86,10 @@ void lv_init(void) lv_anim_init(); #endif +#if USE_LV_GROUP + lv_group_init(); +#endif + /*Init. the sstyles*/ lv_style_init(); @@ -123,9 +127,10 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Create a screen if the parent is NULL*/ if(parent == NULL) { LV_LOG_TRACE("Screen create started"); - lv_disp_t * disp = lv_disp_get_last(); + lv_disp_t * disp = lv_disp_get_default(); if(!disp) { - LV_LOG_WARN("lv_obj_create: not display created to so far. No place to assign the new screen") + LV_LOG_WARN("lv_obj_create: not display created to so far. No place to assign the new screen"); + return NULL; } new_obj = lv_ll_ins_head(&disp->scr_ll); @@ -154,7 +159,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - new_obj->style_p = th->bg; + new_obj->style_p = th->style.bg; } else { new_obj->style_p = &lv_style_scr; } @@ -221,7 +226,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Set appearance*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - new_obj->style_p = th->panel; + new_obj->style_p = th->style.panel; } else { new_obj->style_p = &lv_style_plain_color; } @@ -543,7 +548,7 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) obj->coords.x2 += diff.x; obj->coords.y2 += diff.y; - refresh_childen_position(obj, diff.x, diff.y); + refresh_children_position(obj, diff.x, diff.y); /*Inform the object about its new coordinates*/ obj->signal_func(obj, LV_SIGNAL_CORD_CHG, &ori); @@ -979,7 +984,7 @@ void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style) obj->style_p = style; /*Send a signal about style change to every children with NULL style*/ - refresh_childen_style(obj); + refresh_children_style(obj); /*Notify the object about the style change too*/ lv_obj_refresh_style(obj); @@ -1015,6 +1020,7 @@ void lv_obj_report_style_mod(lv_style_t * style) report_style_mod_core(style, i); } + d = lv_disp_get_next(d); } } @@ -1306,7 +1312,7 @@ void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint1 */ lv_obj_t * lv_scr_act(lv_disp_t * disp) { - if(!disp) disp = lv_disp_get_last(); + if(!disp) disp = lv_disp_get_default(); if(!disp) { LV_LOG_WARN("lv_scr_act: no display registered to get its top layer"); return NULL; @@ -1321,7 +1327,7 @@ lv_obj_t * lv_scr_act(lv_disp_t * disp) */ lv_obj_t * lv_layer_top(lv_disp_t * disp) { - if(!disp) disp = lv_disp_get_last(); + if(!disp) disp = lv_disp_get_default(); if(!disp) { LV_LOG_WARN("lv_layer_top: no display registered to get its top layer"); return NULL; @@ -1336,7 +1342,7 @@ lv_obj_t * lv_layer_top(lv_disp_t * disp) */ lv_obj_t * lv_layer_sys(lv_disp_t * disp) { - if(!disp) disp = lv_disp_get_last(); + if(!disp) disp = lv_disp_get_default(); if(!disp) { LV_LOG_WARN("lv_layer_sys: no display registered to get its top layer"); return NULL; @@ -1908,7 +1914,7 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) * @param x_diff x coordinate shift * @param y_diff y coordinate shift */ -static void refresh_childen_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff) +static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff) { lv_obj_t * i; LL_READ(obj->child_ll, i) { @@ -1917,7 +1923,7 @@ static void refresh_childen_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord i->coords.x2 += x_diff; i->coords.y2 += y_diff; - refresh_childen_position(i, x_diff, y_diff); + refresh_children_position(i, x_diff, y_diff); } } @@ -1931,7 +1937,7 @@ static void report_style_mod_core(void * style_p, lv_obj_t * obj) lv_obj_t * i; LL_READ(obj->child_ll, i) { if(i->style_p == style_p || style_p == NULL) { - refresh_childen_style(i); + refresh_children_style(i); lv_obj_refresh_style(i); } @@ -1944,16 +1950,16 @@ static void report_style_mod_core(void * style_p, lv_obj_t * obj) * because the NULL styles are inherited from the parent * @param obj pointer to an object */ -static void refresh_childen_style(lv_obj_t * obj) +static void refresh_children_style(lv_obj_t * obj) { lv_obj_t * child = lv_obj_get_child(obj, NULL); while(child != NULL) { if(child->style_p == NULL) { - refresh_childen_style(child); /*Check children too*/ + refresh_children_style(child); /*Check children too*/ lv_obj_refresh_style(child); /*Notify the child about the style change*/ } else if(child->style_p->glass) { /*Children with 'glass' parent might be effected if their style == NULL*/ - refresh_childen_style(child); + refresh_children_style(child); } child = lv_obj_get_child(obj, child); } diff --git a/lv_core/lv_refr.c b/lv_core/lv_refr.c index 8d833017e..3f854c1ad 100644 --- a/lv_core/lv_refr.c +++ b/lv_core/lv_refr.c @@ -62,19 +62,6 @@ void lv_refr_init(void) lv_task_ready(task); /*Be sure the screen will be refreshed immediately on start up*/ } -/** - * Call in the display driver's 'disp_flush' function when the flushing is finished - */ -LV_ATTRIBUTE_FLUSH_READY void lv_flush_ready(lv_disp_t * disp) -{ - disp->driver.buffer->internal.flushing = 0; - - /*If the screen is transparent initialize it when the flushing is ready*/ -#if LV_VDB_DOUBLE == 0 && LV_COLOR_SCREEN_TRANSP - memset(vdb_buf, 0x00, LV_VDB_SIZE_IN_BYTES); -#endif -} - /** * Redraw the invalidated areas now. * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can @@ -94,7 +81,7 @@ void lv_refr_now(void) */ void lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p) { - if(!disp) disp = lv_disp_get_last(); + if(!disp) disp = lv_disp_get_default(); if(!disp) return; /*Clear the invalidate buffer if the parameter is NULL*/ @@ -194,7 +181,7 @@ static void lv_refr_task(void * param) if(disp_refr->inv_p != 0) { /*In true double buffered mode copy the refreshed areas to the new VDB to keep it up to date*/ if(lv_disp_is_true_double_buffered(disp_refr)) { - lv_vdb_t * vdb = lv_disp_get_vdb(disp_refr); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp_refr); /*Flush the content of the VDB*/ lv_refr_vdb_flush(); @@ -202,7 +189,7 @@ static void lv_refr_task(void * param) /* With true double buffering the flushing should be only the address change of the current frame buffer. * Wait until the address change is ready and copy the changed content to the other frame buffer (new active VDB) * to keep the buffers synchronized*/ - while(vdb->internal.flushing); + while(vdb->flushing); uint8_t * buf_act = (uint8_t *) vdb->buf_act; uint8_t * buf_ina = (uint8_t *) vdb->buf_act == vdb->buf1 ? vdb->buf2 : vdb->buf1; @@ -304,7 +291,7 @@ static void lv_refr_area(const lv_area_t * area_p) { /*True double buffering: there are two screen sized buffers. Just redraw directly into a buffer*/ if(lv_disp_is_true_double_buffered(disp_refr)) { - lv_vdb_t * vdb = lv_disp_get_vdb(disp_refr); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp_refr); vdb->area.x1 = 0; vdb->area.x2 = LV_HOR_RES-1; vdb->area.y1 = 0; @@ -313,7 +300,7 @@ static void lv_refr_area(const lv_area_t * area_p) } /*The buffer is smaller: refresh the area in parts*/ else { - lv_vdb_t * vdb = lv_disp_get_vdb(disp_refr); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp_refr); /*Calculate the max row num*/ lv_coord_t w = lv_area_get_width(area_p); lv_coord_t h = lv_area_get_height(area_p); @@ -381,11 +368,11 @@ static void lv_refr_area(const lv_area_t * area_p) static void lv_refr_area_part(const lv_area_t * area_p) { - lv_vdb_t * vdb = lv_disp_get_vdb(disp_refr); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp_refr); /*In non double buffered mode, before rendering the next part wait until the previous image is flushed*/ if(lv_disp_is_double_vdb(disp_refr) == false) { - while(vdb->internal.flushing); + while(vdb->flushing); } lv_obj_t * top_p; @@ -565,14 +552,14 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p) */ static void lv_refr_vdb_flush(void) { - lv_vdb_t * vdb = lv_disp_get_vdb(lv_refr_get_disp_refreshing()); + lv_disp_buf_t * vdb = lv_disp_get_vdb(lv_refr_get_disp_refreshing()); /*In double buffered mode wait until the other buffer is flushed before flushing the current one*/ if(vdb->buf1 && vdb->buf2) { - while(vdb->internal.flushing); + while(vdb->flushing); } - vdb->internal.flushing = 1; + vdb->flushing = 1; /*Flush the rendered content to the display*/ lv_disp_t * disp = lv_refr_get_disp_refreshing(); diff --git a/lv_core/lv_refr.h b/lv_core/lv_refr.h index e27252bc7..a00e6ef92 100644 --- a/lv_core/lv_refr.h +++ b/lv_core/lv_refr.h @@ -19,9 +19,6 @@ extern "C" { /********************* * DEFINES *********************/ -#ifndef LV_ATTRIBUTE_FLUSH_READY -# define LV_ATTRIBUTE_FLUSH_READY -#endif /********************** * TYPEDEFS @@ -48,11 +45,6 @@ extern "C" { */ void lv_refr_init(void); -/** - * Call in the display driver's 'disp_flush' function when the flushing is finished - */ -LV_ATTRIBUTE_FLUSH_READY void lv_flush_ready(lv_disp_t * disp); - /** * Redraw the invalidated areas now. * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can diff --git a/lv_draw/lv_draw_basic.c b/lv_draw/lv_draw_basic.c index 7e7a6d1ed..516af1b9e 100644 --- a/lv_draw/lv_draw_basic.c +++ b/lv_draw/lv_draw_basic.c @@ -79,7 +79,7 @@ void lv_draw_px(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t } lv_disp_t * disp = lv_refr_get_disp_refreshing(); - lv_vdb_t * vdb = lv_disp_get_vdb(disp); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp); uint32_t vdb_width = lv_area_get_width(&vdb->area); /*Make the coordinates relative to VDB*/ @@ -129,7 +129,7 @@ void lv_draw_fill(const lv_area_t * cords_p, const lv_area_t * mask_p, if(union_ok == false) return; lv_disp_t * disp = lv_refr_get_disp_refreshing(); - lv_vdb_t * vdb = lv_disp_get_vdb(disp); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp); lv_area_t vdb_rel_a; /*Stores relative coordinates on vdb*/ vdb_rel_a.x1 = res_a.x1 - vdb->area.x1; @@ -290,7 +290,7 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, pos_y + letter_h < mask_p->y1 || pos_y > mask_p->y2) return; lv_disp_t * disp = lv_refr_get_disp_refreshing(); - lv_vdb_t * vdb = lv_disp_get_vdb(disp); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp); lv_coord_t vdb_width = lv_area_get_width(&vdb->area); lv_color_t * vdb_buf_tmp = vdb->buf_act; @@ -409,7 +409,7 @@ void lv_draw_map(const lv_area_t * cords_p, const lv_area_t * mask_p, } lv_disp_t * disp = lv_refr_get_disp_refreshing(); - lv_vdb_t * vdb = lv_disp_get_vdb(disp); + lv_disp_buf_t * vdb = lv_disp_get_vdb(disp); /*Stores coordinates relative to the current VDB*/ masked_a.x1 = masked_a.x1 - vdb->area.x1; diff --git a/lv_draw/lv_draw_label.c b/lv_draw/lv_draw_label.c index 72faf34c6..2441d90be 100644 --- a/lv_draw/lv_draw_label.c +++ b/lv_draw/lv_draw_label.c @@ -77,6 +77,14 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st pos.x = coords->x1; pos.y = coords->y1; + lv_coord_t x_ofs = 0; + lv_coord_t y_ofs = 0; + if(offset != NULL) { + x_ofs = offset->x; + y_ofs = offset->y; + pos.y += y_ofs; + } + uint32_t line_start = 0; uint32_t line_end = lv_txt_get_next_line(txt, font, style->text.letter_space, w, flag); @@ -114,14 +122,6 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st lv_color_t recolor; lv_coord_t letter_w; - lv_coord_t x_ofs = 0; - lv_coord_t y_ofs = 0; - if(offset != NULL) { - x_ofs = offset->x; - y_ofs = offset->y; - pos.y += y_ofs; - } - /*Write out all lines*/ while(txt[line_start] != '\0') { if(offset != NULL) { diff --git a/lv_hal/lv_hal_disp.c b/lv_hal/lv_hal_disp.c index 4c15f28bf..9e02c1fab 100644 --- a/lv_hal/lv_hal_disp.c +++ b/lv_hal/lv_hal_disp.c @@ -24,6 +24,9 @@ /********************* * DEFINES *********************/ +#ifndef LV_ATTRIBUTE_FLUSH_READY +# define LV_ATTRIBUTE_FLUSH_READY +#endif /********************** * TYPEDEFS @@ -36,6 +39,7 @@ /********************** * STATIC VARIABLES **********************/ +static lv_disp_t * disp_def; /********************** * MACROS @@ -53,9 +57,12 @@ */ void lv_disp_drv_init(lv_disp_drv_t * driver) { + memset(driver, 0, sizeof(lv_disp_drv_t)); + driver->disp_flush = NULL; driver->hor_res = LV_HOR_RES_MAX; driver->ver_res = LV_VER_RES_MAX; + driver->buffer = NULL; #if USE_LV_GPU driver->mem_blend = NULL; @@ -65,6 +72,33 @@ void lv_disp_drv_init(lv_disp_drv_t * driver) driver->vdb_wr = NULL; } + +/** + * Initialize a display buffer + * @param disp_buf pointer `lv_disp_buf_t` variable to initialize + * @param buf1 A buffer to be used by LittlevGL to draw the image. + * Always has to specified and can't be NULL. + * Can be an array allocated by the user. E.g. `static lv_color_t disp_buf1[1024 * 10]` + * Or a memory address e.g. in external SRAM + * @param buf2 Optionally specify a second buffer to make image rendering and image flushing + * (sending to the display) parallel. + * In the `disp_drv->flush` you should use DMA or similar hardware to send + * the image to the display in the background. + * It lets LittlevGL to render next frame into the other buffer while previous is being sent. + * Set to `NULL` if unused. + * @param size size of the `buf1` and `buf2` in pixel count. + */ +void lv_disp_buf_init(lv_disp_buf_t * disp_buf, void * buf1, void * buf2, uint32_t size) +{ + memset(disp_buf, 0, sizeof(lv_disp_buf_t)); + + disp_buf->buf1 = buf1; + disp_buf->buf2 = buf2; + disp_buf->buf_act = disp_buf->buf1; + disp_buf->size = size; +} + + /** * Register an initialized display driver. * Automatically set the first display as active. @@ -83,16 +117,25 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) lv_ll_init(&disp->scr_ll, sizeof(lv_obj_t)); + if(disp_def == NULL) disp_def = disp; + disp->act_scr = lv_obj_create(NULL, NULL); /*Create a default screen on the display*/ disp->top_layer = lv_obj_create(NULL, NULL); /*Create top layer on the display*/ disp->sys_layer = lv_obj_create(NULL, NULL); /*Create top layer on the display*/ lv_obj_set_style(disp->top_layer, &lv_style_transp); lv_obj_set_style(disp->sys_layer, &lv_style_transp); + lv_disp_assign_screen(disp, disp->act_scr); + lv_disp_assign_screen(disp, disp->top_layer); + lv_disp_assign_screen(disp, disp->sys_layer); + disp->inv_p = 0; disp->vdb_act = 0; disp->vdb_flushing = 0; + lv_obj_invalidate(disp->act_scr); + + return disp; } @@ -108,19 +151,25 @@ lv_disp_t * lv_disp_get_next(lv_disp_t * disp) } -lv_disp_t * lv_disp_get_last(void) +void lv_disp_set_default(lv_disp_t * disp) { - return lv_ll_get_head(&LV_GC_ROOT(_lv_disp_ll)); + disp_def = disp; } -lv_vdb_t * lv_disp_get_vdb(lv_disp_t * disp) + +lv_disp_t * lv_disp_get_default(void) +{ + return disp_def; +} + +lv_disp_buf_t * lv_disp_get_vdb(lv_disp_t * disp) { return disp->driver.buffer; } lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp) { - if(disp == NULL) disp = lv_disp_get_last(); + if(disp == NULL) disp = lv_disp_get_default(); if(disp == NULL) return LV_HOR_RES_MAX; else return disp->driver.hor_res; @@ -129,7 +178,7 @@ lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp) lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp) { - if(disp == NULL) disp = lv_disp_get_last(); + if(disp == NULL) disp = lv_disp_get_default(); if(disp == NULL) return LV_VER_RES_MAX; else return disp->driver.ver_res; @@ -147,6 +196,21 @@ bool lv_disp_is_true_double_buffered(lv_disp_t * disp) else return false; } + +/** + * Call in the display driver's `flush` function when the flushing is finished + */ +LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_t * disp) +{ + disp->driver.buffer->flushing = 0; + + /*If the screen is transparent initialize it when the flushing is ready*/ +#if LV_COLOR_SCREEN_TRANSP + memset(vdb_buf, 0x00, LV_VDB_SIZE_IN_BYTES); +#endif +} + + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_hal/lv_hal_disp.h b/lv_hal/lv_hal_disp.h index 08fbbfd5f..01be7003a 100644 --- a/lv_hal/lv_hal_disp.h +++ b/lv_hal/lv_hal_disp.h @@ -38,33 +38,28 @@ struct _disp_t; typedef struct { - void * buf_act; void * buf1; void * buf2; - uint32_t size; /*In pixel count*/ - struct { - uint32_t double_buffered :1; - uint32_t true_double_buffered :1; - }mode; + /*Used by the library*/ + void * buf_act; + uint32_t size; /*In pixel count*/ lv_area_t area; - struct { - uint32_t flushing :1; - }internal; -}lv_vdb_t; + uint32_t flushing :1; +}lv_disp_buf_t; /** * Display Driver structure to be registered by HAL */ typedef struct _disp_drv_t { - void * user_data; + int user_data; lv_coord_t hor_res; lv_coord_t ver_res; - lv_vdb_t * buffer; + lv_disp_buf_t * buffer; /*Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished*/ void (*disp_flush)(struct _disp_t * disp, const lv_area_t * area, lv_color_t * color_p); @@ -119,9 +114,29 @@ void lv_disp_drv_init(lv_disp_drv_t *driver); lv_disp_t * lv_disp_drv_register(lv_disp_drv_t *driver); -lv_disp_t * lv_disp_get_last(void); +/** + * Initialize a display buffer + * @param disp_buf pointer `lv_disp_buf_t` variable to initialize + * @param buf1 A buffer to be used by LittlevGL to draw the image. + * Always has to specified and can't be NULL. + * Can be an array allocated by the user. E.g. `static lv_color_t disp_buf1[1024 * 10]` + * Or a memory address e.g. in external SRAM + * @param buf2 Optionally specify a second buffer to make image rendering and image flushing + * (sending to the display) parallel. + * In the `disp_drv->flush` you should use DMA or similar hardware to send + * the image to the display in the background. + * It lets LittlevGL to render next frame into the other buffer while previous is being sent. + * Set to `NULL` if unused. + * @param size size of the `buf1` and `buf2` in pixel count. + */ +void lv_disp_buf_init(lv_disp_buf_t * disp_buf, void * buf1, void * buf2, uint32_t size); -lv_vdb_t * lv_disp_get_vdb(lv_disp_t * disp); + +void lv_disp_set_default(lv_disp_t * disp); + +lv_disp_t * lv_disp_get_default(void); + +lv_disp_buf_t * lv_disp_get_vdb(lv_disp_t * disp); /** * Get the next display. * @param disp pointer to the current display. NULL to initialize. diff --git a/lv_hal/lv_hal_indev.c b/lv_hal/lv_hal_indev.c index 415c35df1..6adb4be96 100644 --- a/lv_hal/lv_hal_indev.c +++ b/lv_hal/lv_hal_indev.c @@ -64,7 +64,7 @@ void lv_indev_drv_init(lv_indev_drv_t * driver) lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver) { - if(driver->disp == NULL) driver->disp = lv_disp_get_last(); + if(driver->disp == NULL) driver->disp = lv_disp_get_default(); if(driver->disp == NULL) { LV_LOG_WARN("lv_indev_drv_register: no display registered hence can't attache the indev to a display"); diff --git a/lv_misc/lv_gc.h b/lv_misc/lv_gc.h index 2ba405fc3..35559f39b 100644 --- a/lv_misc/lv_gc.h +++ b/lv_misc/lv_gc.h @@ -36,6 +36,7 @@ extern "C" { prefix lv_ll_t _lv_drv_ll;\ prefix lv_ll_t _lv_file_ll;\ prefix lv_ll_t _lv_anim_ll;\ + prefix lv_ll_t _lv_group_ll;\ prefix void * _lv_task_act;\ diff --git a/lv_misc/lv_math.c b/lv_misc/lv_math.c index a0d26053e..73c80ad40 100644 --- a/lv_misc/lv_math.c +++ b/lv_misc/lv_math.c @@ -8,6 +8,7 @@ *********************/ #include "lv_math.h" #include +#include /********************* * DEFINES @@ -34,7 +35,7 @@ static int16_t sin0_90_table[] = { 28377, 28659, 28932, 29196, 29451, 29697, 29934, 30162, 30381, 30591, 30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165, 32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762, - 32767 + 32767 }; @@ -54,53 +55,33 @@ static int16_t sin0_90_table[] = { */ char * lv_math_num_to_str(int32_t num, char * buf) { - char * buf_ori = buf; - if(num == 0) { + if (num == 0) { buf[0] = '0'; buf[1] = '\0'; return buf; - } else if(num < 0) { - (*buf) = '-'; - buf++; - num = LV_MATH_ABS(num); } - uint32_t output = 0; - int8_t i; - - for(i = 31; i >= 0; i--) { - if((output & 0xF) >= 5) - output += 3; - if(((output & 0xF0) >> 4) >= 5) - output += (3 << 4); - if(((output & 0xF00) >> 8) >= 5) - output += (3 << 8); - if(((output & 0xF000) >> 12) >= 5) - output += (3 << 12); - if(((output & 0xF0000) >> 16) >= 5) - output += (3 << 16); - if(((output & 0xF00000) >> 20) >= 5) - output += (3 << 20); - if(((output & 0xF000000) >> 24) >= 5) - output += (3 << 24); - if(((output & 0xF0000000) >> 28) >= 5) - output += (3 << 28); - output = (output << 1) | ((num >> i) & 1); + int8_t digitCount = 0; + int8_t i = 0; + if (num < 0) { + buf[digitCount++] = '-'; + num = abs(num); + ++i; } - - uint8_t digit; - bool leading_zero_ready = false; - for(i = 28; i >= 0; i -= 4) { - digit = ((output >> i) & 0xF) + '0'; - if(digit == '0' && leading_zero_ready == false) continue; - - leading_zero_ready = true; - (*buf) = digit; - buf++; + while (num) { + char digit = num % 10; + buf[digitCount++] = digit + 48; + num /= 10; } - - (*buf) = '\0'; - - return buf_ori; + buf[digitCount] = '\0'; + digitCount--; + while (digitCount > i) { + char temp = buf[i]; + buf[i] = buf[digitCount]; + buf[digitCount] = temp; + digitCount--; + i++; + } + return buf; } /** diff --git a/lv_misc/lv_math.h b/lv_misc/lv_math.h index 1f2e402d8..a0229eb1b 100644 --- a/lv_misc/lv_math.h +++ b/lv_misc/lv_math.h @@ -19,9 +19,9 @@ extern "C" { /********************* * DEFINES *********************/ -#define LV_MATH_MIN(a,b) (ab?a:b) -#define LV_MATH_ABS(x) ((x)>0?(x):(-(x))) +#define LV_MATH_MIN(a,b) ((a) < (b) ? (a) : (b)) +#define LV_MATH_MAX(a,b) ((a) > (b) ? (a) : (b)) +#define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) #define LV_TRIGO_SIN_MAX 32767 #define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ diff --git a/lv_misc/lv_symbol_def.h b/lv_misc/lv_symbol_def.h index e8ea76d57..e60952b6a 100644 --- a/lv_misc/lv_symbol_def.h +++ b/lv_misc/lv_symbol_def.h @@ -73,7 +73,7 @@ extern "C" { #define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE1(F0) #define SYMBOL_BLUETOOTH _SYMBOL_VALUE1(F1) #define LV_SYMBOL_GLYPH_LAST 0xF1 -#define SYMBOL_DUMMY _SYMBOL_VALUE1(xFF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/ +#define SYMBOL_DUMMY _SYMBOL_VALUE1(FF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/ #else #define LV_SYMBOL_GLYPH_FIRST 0xF800 diff --git a/lv_objx/lv_arc.c b/lv_objx/lv_arc.c index 683d34345..8f5ed9a6c 100644 --- a/lv_objx/lv_arc.c +++ b/lv_objx/lv_arc.c @@ -80,7 +80,7 @@ lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_arc_set_style(new_arc, LV_ARC_STYLE_MAIN, th->arc); + lv_arc_set_style(new_arc, LV_ARC_STYLE_MAIN, th->style.arc); } else { lv_arc_set_style(new_arc, LV_ARC_STYLE_MAIN, &lv_style_plain_color); } diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index d83a60934..656225eb4 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -84,8 +84,8 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_bar_set_style(new_bar, LV_BAR_STYLE_BG, th->bar.bg); - lv_bar_set_style(new_bar, LV_BAR_STYLE_INDIC, th->bar.indic); + lv_bar_set_style(new_bar, LV_BAR_STYLE_BG, th->style.bar.bg); + lv_bar_set_style(new_bar, LV_BAR_STYLE_INDIC, th->style.bar.indic); } else { lv_obj_set_style(new_bar, &lv_style_pretty); } diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index 2bf8314b3..f96607683 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -123,11 +123,11 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_btn_set_style(new_btn, LV_BTN_STYLE_REL, th->btn.rel); - lv_btn_set_style(new_btn, LV_BTN_STYLE_PR, th->btn.pr); - lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_REL, th->btn.tgl_rel); - lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_PR, th->btn.tgl_pr); - lv_btn_set_style(new_btn, LV_BTN_STYLE_INA, th->btn.ina); + lv_btn_set_style(new_btn, LV_BTN_STYLE_REL, th->style.btn.rel); + lv_btn_set_style(new_btn, LV_BTN_STYLE_PR, th->style.btn.pr); + lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_REL, th->style.btn.tgl_rel); + lv_btn_set_style(new_btn, LV_BTN_STYLE_TGL_PR, th->style.btn.tgl_pr); + lv_btn_set_style(new_btn, LV_BTN_STYLE_INA, th->style.btn.ina); } else { lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_REL]); } diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 0ce1bba3a..dca929111 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -103,12 +103,12 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BG, th->btnm.bg); - lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_REL, th->btnm.btn.rel); - lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_PR, th->btnm.btn.pr); - lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_REL, th->btnm.btn.tgl_rel); - lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_PR, th->btnm.btn.tgl_pr); - lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_INA, th->btnm.btn.ina); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BG, th->style.btnm.bg); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_REL, th->style.btnm.btn.rel); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_PR, th->style.btnm.btn.pr); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_REL, th->style.btnm.btn.tgl_rel); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_TGL_PR, th->style.btnm.btn.tgl_pr); + lv_btnm_set_style(new_btnm, LV_BTNM_STYLE_BTN_INA, th->style.btnm.btn.ina); } else { lv_obj_set_style(new_btnm, &lv_style_pretty); } diff --git a/lv_objx/lv_calendar.c b/lv_objx/lv_calendar.c index 217c08d56..f8260cf4c 100644 --- a/lv_objx/lv_calendar.c +++ b/lv_objx/lv_calendar.c @@ -130,14 +130,14 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy) lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_BG, th->calendar.bg); - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER, th->calendar.header); - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER_PR, th->calendar.header_pr); - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_DAY_NAMES, th->calendar.day_names); - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_WEEK_BOX, th->calendar.week_box); - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_TODAY_BOX, th->calendar.today_box); - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS, th->calendar.highlighted_days); - lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_INACTIVE_DAYS, th->calendar.inactive_days); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_BG, th->style.calendar.bg); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER, th->style.calendar.header); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER_PR, th->style.calendar.header_pr); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_DAY_NAMES, th->style.calendar.day_names); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_WEEK_BOX, th->style.calendar.week_box); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_TODAY_BOX, th->style.calendar.today_box); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS, th->style.calendar.highlighted_days); + lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_INACTIVE_DAYS, th->style.calendar.inactive_days); } else { lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_BG, &lv_style_pretty); lv_calendar_set_style(new_calendar, LV_CALENDAR_STYLE_HEADER, ext->style_header); diff --git a/lv_objx/lv_cb.c b/lv_objx/lv_cb.c index 6b0277e14..7943ba6b2 100644 --- a/lv_objx/lv_cb.c +++ b/lv_objx/lv_cb.c @@ -88,12 +88,12 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_cb_set_style(new_cb, LV_CB_STYLE_BG, th->cb.bg); - lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_REL, th->cb.box.rel); - lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_PR, th->cb.box.pr); - lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_REL, th->cb.box.tgl_rel); - lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_PR, th->cb.box.tgl_pr); - lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_INA, th->cb.box.ina); + lv_cb_set_style(new_cb, LV_CB_STYLE_BG, th->style.cb.bg); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_REL, th->style.cb.box.rel); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_PR, th->style.cb.box.pr); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_REL, th->style.cb.box.tgl_rel); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_TGL_PR, th->style.cb.box.tgl_pr); + lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_INA, th->style.cb.box.ina); } else { lv_cb_set_style(new_cb, LV_CB_STYLE_BG, &lv_style_transp); lv_cb_set_style(new_cb, LV_CB_STYLE_BOX_REL, &lv_style_pretty); diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index a41025b81..8d3e97359 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -95,7 +95,7 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_chart_set_style(new_chart, th->chart); + lv_chart_set_style(new_chart, th->style.chart); } else { lv_chart_set_style(new_chart, &lv_style_pretty); } @@ -175,9 +175,10 @@ void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie) if(chart == NULL || serie == NULL) return; lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); - if(ext == NULL) - return; - for(uint32_t i = 0; i < ext->point_cnt; i++) + if(ext == NULL) return; + + uint32_t i; + for(i = 0; i < ext->point_cnt; i++) { serie->points[i] = LV_CHART_POINT_DEF; } diff --git a/lv_objx/lv_cont.c b/lv_objx/lv_cont.c index c21511bef..330927726 100644 --- a/lv_objx/lv_cont.c +++ b/lv_objx/lv_cont.c @@ -89,7 +89,7 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_cont_set_style(new_cont, th->cont); + lv_cont_set_style(new_cont, th->style.cont); } else { lv_cont_set_style(new_cont, &lv_style_pretty); } diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index c8805d591..bd506c705 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -118,9 +118,9 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, th->ddlist.bg); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, th->ddlist.sel); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, th->ddlist.sb); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, th->style.ddlist.bg); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, th->style.ddlist.sel); + lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, th->style.ddlist.sb); } else { lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, &lv_style_pretty); lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, &lv_style_plain_color); @@ -624,6 +624,7 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par } else if(sign == LV_SIGNAL_CLEANUP) { ext->label = NULL; } else if(sign == LV_SIGNAL_FOCUS) { +#if USE_LV_GROUP lv_group_t * g = lv_obj_get_group(ddlist); bool editing = lv_group_get_editing(g); lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); @@ -651,6 +652,7 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par lv_ddlist_refr_size(ddlist, true); } } +#endif } else if(sign == LV_SIGNAL_DEFOCUS) { if(ext->opened) { ext->opened = false; @@ -686,9 +688,11 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par ext->opened = 0; if(ext->action) ext->action(ddlist); +#if USE_LV_GROUP lv_group_t * g = lv_obj_get_group(ddlist); bool editing = lv_group_get_editing(g); if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ +#endif } else { ext->opened = 1; } diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index ad2ef8d92..bdc6a179a 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -95,7 +95,7 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_gauge_set_style(new_gauge, th->gauge); + lv_gauge_set_style(new_gauge, th->style.gauge); } else { lv_gauge_set_style(new_gauge, &lv_style_pretty_color); } diff --git a/lv_objx/lv_imgbtn.c b/lv_objx/lv_imgbtn.c index 75e545343..ed1d72b42 100644 --- a/lv_objx/lv_imgbtn.c +++ b/lv_objx/lv_imgbtn.c @@ -81,11 +81,10 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) } /*Copy an existing image button*/ else { -#if LV_IMGBTN_TILED == 0 - memset(ext->img_src, 0, sizeof(ext->img_src)); -#else lv_imgbtn_ext_t * copy_ext = lv_obj_get_ext_attr(copy); - +#if LV_IMGBTN_TILED == 0 + memcpy(ext->img_src, copy_ext->img_src, sizeof(ext->img_src)); +#else memcpy(ext->img_src_left, copy_ext->img_src_left, sizeof(ext->img_src_left)); memcpy(ext->img_src_mid, copy_ext->img_src_mid, sizeof(ext->img_src_mid)); memcpy(ext->img_src_right, copy_ext->img_src_right, sizeof(ext->img_src_right)); @@ -386,7 +385,7 @@ static void refr_img(lv_obj_t * imgbtn) ext->act_cf = LV_IMG_CF_UNKOWN; } - + lv_obj_invalidate(imgbtn); } #endif diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c index d41b5962d..be7684760 100644 --- a/lv_objx/lv_kb.c +++ b/lv_objx/lv_kb.c @@ -110,12 +110,12 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_kb_set_style(new_kb, LV_KB_STYLE_BG, th->kb.bg); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_REL, th->kb.btn.rel); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_PR, th->kb.btn.pr); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_REL, th->kb.btn.tgl_rel); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_PR, th->kb.btn.tgl_pr); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_INA, th->kb.btn.ina); + lv_kb_set_style(new_kb, LV_KB_STYLE_BG, th->style.kb.bg); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_REL, th->style.kb.btn.rel); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_PR, th->style.kb.btn.pr); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_REL, th->style.kb.btn.tgl_rel); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_PR, th->style.kb.btn.tgl_pr); + lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_INA, th->style.kb.btn.ina); } else { /*Let the button matrix's styles*/ } diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 106ba564c..1ef781caf 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -555,7 +555,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) uint32_t i = line_start; uint32_t i_current = i; uint32_t letter; - while(i < new_line_start - 1) { + while(i <= new_line_start - 1) { letter = lv_txt_encoded_next(txt, &i); /*Be careful 'i' already points to the next character*/ /*Handle the recolor command*/ if((flag & LV_TXT_FLAG_RECOLOR) != 0) { diff --git a/lv_objx/lv_led.c b/lv_objx/lv_led.c index 29fc967ee..3529eb545 100644 --- a/lv_objx/lv_led.c +++ b/lv_objx/lv_led.c @@ -79,7 +79,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_led_set_style(new_led, th->led); + lv_led_set_style(new_led, th->style.led); } else { lv_led_set_style(new_led, &lv_style_pretty_color); } diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 8accb665a..9bfdb2379 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -109,14 +109,14 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_list_set_style(new_list, LV_LIST_STYLE_BG, th->list.bg); - lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, th->list.scrl); - lv_list_set_style(new_list, LV_LIST_STYLE_SB, th->list.sb); - lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, th->list.btn.rel); - lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, th->list.btn.pr); - lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, th->list.btn.tgl_rel); - lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, th->list.btn.tgl_pr); - lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, th->list.btn.ina); + lv_list_set_style(new_list, LV_LIST_STYLE_BG, th->style.list.bg); + lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, th->style.list.scrl); + lv_list_set_style(new_list, LV_LIST_STYLE_SB, th->style.list.sb); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, th->style.list.btn.rel); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, th->style.list.btn.pr); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, th->style.list.btn.tgl_rel); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, th->style.list.btn.tgl_pr); + lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, th->style.list.btn.ina); } else { lv_list_set_style(new_list, LV_LIST_STYLE_BG, &lv_style_transp_fit); lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, &lv_style_pretty); @@ -300,6 +300,7 @@ void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn) } ext->selected_btn = btn; + ext->last_sel = btn; if(ext->selected_btn) { lv_btn_state_t s = lv_btn_get_state(ext->selected_btn); @@ -760,7 +761,7 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) lv_group_t * g = lv_obj_get_group(list); if(lv_group_get_editing(g)) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - if(NULL != ext->last_sel) { + if(ext->last_sel) { /* Select the last used button */ lv_list_set_btn_selected(list, ext->last_sel); } @@ -779,7 +780,7 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) lv_list_set_btn_selected(list, last_clicked_btn); } else { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - if(NULL != ext->last_sel) { + if(ext->last_sel) { /* Select the last used button */ lv_list_set_btn_selected(list, ext->last_sel); } diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 0fe0c1291..a31877082 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -59,8 +59,8 @@ typedef struct uint32_t size; /*the number of items(buttons) in the list*/ bool single_mode; /* whether single selected mode is enabled */ #if USE_LV_GROUP - lv_obj_t * last_sel; /* Last btn selected */ - lv_obj_t * selected_btn; + lv_obj_t * last_sel; /* The last selected button. It will be reverted when the list is focused again */ + lv_obj_t * selected_btn; /* The button is currently being selected*/ #endif } lv_list_ext_t; diff --git a/lv_objx/lv_lmeter.c b/lv_objx/lv_lmeter.c index 4d78d8ee2..e86e4aa54 100644 --- a/lv_objx/lv_lmeter.c +++ b/lv_objx/lv_lmeter.c @@ -84,7 +84,7 @@ lv_obj_t * lv_lmeter_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_lmeter_set_style(new_lmeter, th->lmeter); + lv_lmeter_set_style(new_lmeter, th->style.lmeter); } else { lv_lmeter_set_style(new_lmeter, &lv_style_pretty_color); } diff --git a/lv_objx/lv_mbox.c b/lv_objx/lv_mbox.c index ac355d10a..486b49cfa 100644 --- a/lv_objx/lv_mbox.c +++ b/lv_objx/lv_mbox.c @@ -97,7 +97,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, th->mbox.bg); + lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, th->style.mbox.bg); } else { lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, &lv_style_pretty); } @@ -144,9 +144,9 @@ void lv_mbox_add_btns(lv_obj_t * mbox, const char ** btn_map, lv_btnm_action_t a /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_BG, th->mbox.btn.bg); - lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_REL, th->mbox.btn.rel); - lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_PR, th->mbox.btn.pr); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_BG, th->style.mbox.btn.bg); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_REL, th->style.mbox.btn.rel); + lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_PR, th->style.mbox.btn.pr); } else { lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, &lv_style_transp_fit); } diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 46c3a2160..3ddbcf141 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -116,14 +116,14 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) lv_theme_t * th = lv_theme_get_current(); if(th) { if(par == NULL) { /*Different styles if it is screen*/ - lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->bg); + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->style.bg); lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_transp); } else { - lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->page.bg); - lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, th->page.scrl); + lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->style.page.bg); + lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, th->style.page.scrl); } - lv_page_set_style(new_page, LV_PAGE_STYLE_SB, th->page.sb); + lv_page_set_style(new_page, LV_PAGE_STYLE_SB, th->style.page.sb); } else { lv_page_set_style(new_page, LV_PAGE_STYLE_BG, &lv_style_pretty_color); lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_pretty); diff --git a/lv_objx/lv_preload.c b/lv_objx/lv_preload.c index 1700a4dab..9532e53c8 100644 --- a/lv_objx/lv_preload.c +++ b/lv_objx/lv_preload.c @@ -93,7 +93,7 @@ lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_preload_set_style(new_preload, LV_PRELOAD_STYLE_MAIN, th->preload); + lv_preload_set_style(new_preload, LV_PRELOAD_STYLE_MAIN, th->style.preload); } else { lv_obj_set_style(new_preload, &lv_style_pretty_color); } diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index ae3419ddb..1f8a75e2e 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -96,8 +96,8 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->roller.bg); - lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->roller.sel); + lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->style.roller.bg); + lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->style.roller.sel); } else { /*Let the ddlist's style*/ lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/ @@ -361,6 +361,7 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par refr_position(roller, false); } } else if(sign == LV_SIGNAL_FOCUS) { +#if USE_LV_GROUP lv_group_t * g = lv_obj_get_group(roller); bool editing = lv_group_get_editing(g); lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); @@ -382,12 +383,15 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Save the current value. Used to revert this state if ENER wont't be pressed*/ } +#endif } else if(sign == LV_SIGNAL_DEFOCUS) { +#if USE_LV_GROUP /*Revert the original state*/ if(ext->ddlist.sel_opt_id != ext->ddlist.sel_opt_id_ori) { ext->ddlist.sel_opt_id = ext->ddlist.sel_opt_id_ori; refr_position(roller, true); } +#endif } else if(sign == LV_SIGNAL_CONTROLL) { char c = *((char *)param); if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { @@ -402,9 +406,11 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Set the entered value as default*/ if(ext->ddlist.action) ext->ddlist.action(roller); +#if USE_LV_GROUP lv_group_t * g = lv_obj_get_group(roller); bool editing = lv_group_get_editing(g); if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ +#endif } } else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index eaf04e8c2..d75f84bd1 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -86,9 +86,9 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_slider_set_style(new_slider, LV_SLIDER_STYLE_BG, th->slider.bg); - lv_slider_set_style(new_slider, LV_SLIDER_STYLE_INDIC, th->slider.indic); - lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, th->slider.knob); + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_BG, th->style.slider.bg); + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_INDIC, th->style.slider.indic); + lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, th->style.slider.knob); } else { lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, ext->style_knob); } diff --git a/lv_objx/lv_spinbox.c b/lv_objx/lv_spinbox.c index 13e19de7a..0d5e4edbf 100644 --- a/lv_objx/lv_spinbox.c +++ b/lv_objx/lv_spinbox.c @@ -10,6 +10,7 @@ #if USE_LV_SPINBOX != 0 #include "../lv_themes/lv_theme.h" +#include "../lv_misc/lv_math.h" /********************* * DEFINES @@ -64,7 +65,7 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy) /*Initialize the allocated 'ext'*/ ext->ta.one_line = 1; ext->ta.pwd_mode = 0; - ext->ta.accapted_chars = "1234567890+-."; + ext->ta.accapted_chars = "1234567890+-. "; ext->value = 0; ext->dec_point_pos = 0; @@ -86,9 +87,9 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_BG, th->spinbox.bg); - lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_CURSOR, th->spinbox.cursor); - lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_SB, th->spinbox.sb); + lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_BG, th->style.spinbox.bg); + lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_CURSOR, th->style.spinbox.cursor); + lv_spinbox_set_style(new_spinbox, LV_SPINBOX_STYLE_SB, th->style.spinbox.sb); } } /*Copy an existing spinbox*/ @@ -188,13 +189,11 @@ void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_m ext->range_max = range_max; ext->range_min = range_min; - if(ext->value > ext->range_max) - { + if(ext->value > ext->range_max) { ext->value = ext->range_max; lv_obj_invalidate(spinbox); } - if(ext->value < ext->range_min) - { + if(ext->value < ext->range_min) { ext->value = ext->range_min; lv_obj_invalidate(spinbox); } @@ -251,11 +250,9 @@ void lv_spinbox_step_next(lv_obj_t * spinbox) { lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - - if((ext->step / 10) < ext->range_max && (ext->step / 10) > ext->range_min && (ext->step / 10) > 0) - { - ext->step /= 10; - } + int32_t new_step = ext->step / 10; + if((new_step) > 0) ext->step = new_step; + else ext->step = 1; lv_spinbox_updatevalue(spinbox); } @@ -267,12 +264,10 @@ void lv_spinbox_step_next(lv_obj_t * spinbox) void lv_spinbox_step_previous(lv_obj_t * spinbox) { lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - - - if((ext->step * 10) <= ext->range_max && (ext->step * 10) > ext->range_min && (ext->step * 10) > 0) - { - ext->step *= 10; - } + int32_t step_limit; + step_limit = LV_MATH_MAX(ext->range_max, (ext->range_min < 0 ? (-ext->range_min) : ext->range_min)); + int32_t new_step = ext->step * 10; + if(new_step <= step_limit) ext->step = new_step; lv_spinbox_updatevalue(spinbox); } @@ -285,20 +280,16 @@ void lv_spinbox_increment(lv_obj_t * spinbox) { lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - if(ext->value + ext->step <= ext->range_max) - { + if(ext->value + ext->step <= ext->range_max) { /*Special mode when zero crossing*/ - if((ext->value + ext->step) > 0 && ext->value < 0) - { - ext->value = -ext->value; - }/*end special mode*/ + if((ext->value + ext->step) > 0 && ext->value < 0) ext->value = -ext->value; ext->value += ext->step; - if(ext->value_changed_cb != NULL) - { - ext->value_changed_cb(spinbox, ext->value); - } + } else { + ext->value = ext->range_max; } + + if(ext->value_changed_cb != NULL) ext->value_changed_cb(spinbox, ext->value); lv_spinbox_updatevalue(spinbox); } @@ -310,20 +301,15 @@ void lv_spinbox_decrement(lv_obj_t * spinbox) { lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - if(ext->value - ext->step >= ext->range_min) - { + if(ext->value - ext->step >= ext->range_min) { /*Special mode when zero crossing*/ - if((ext->value - ext->step) < 0 && ext->value > 0) - { - ext->value = -ext->value; - }/*end special mode*/ + if((ext->value - ext->step) < 0 && ext->value > 0) ext->value = -ext->value; ext->value -= ext->step; - - if(ext->value_changed_cb != NULL) - { - ext->value_changed_cb(spinbox, ext->value); - } + } else { + ext->value = ext->range_min; } + + if(ext->value_changed_cb != NULL) ext->value_changed_cb(spinbox, ext->value); lv_spinbox_updatevalue(spinbox); } @@ -365,137 +351,121 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * p if(buf->type[i] == NULL) break; } buf->type[i] = "lv_spinbox"; - }else if(sign == LV_SIGNAL_CONTROLL) - { + } + else if(sign == LV_SIGNAL_CONTROLL) { lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/ - if(c == LV_GROUP_KEY_RIGHT) - { - if(indev_type == LV_INDEV_TYPE_ENCODER) - { - lv_spinbox_increment(spinbox); - } - else - { - lv_spinbox_step_next(spinbox); - } + if(c == LV_GROUP_KEY_RIGHT) { + if(indev_type == LV_INDEV_TYPE_ENCODER) lv_spinbox_increment(spinbox); + else lv_spinbox_step_next(spinbox); } - else if(c == LV_GROUP_KEY_LEFT) - { - if(indev_type == LV_INDEV_TYPE_ENCODER) - { - lv_spinbox_decrement(spinbox); - } - else - { + else if(c == LV_GROUP_KEY_LEFT) { + if(indev_type == LV_INDEV_TYPE_ENCODER) lv_spinbox_decrement(spinbox); + else lv_spinbox_step_previous(spinbox); + } + else if(c == LV_GROUP_KEY_UP) { + lv_spinbox_increment(spinbox); + } + else if(c == LV_GROUP_KEY_DOWN) { + lv_spinbox_decrement(spinbox); + } + else if(c == LV_GROUP_KEY_ENTER) { + + if(ext->step > 1) { + lv_spinbox_step_next(spinbox); + } else { + /*Restart from the MSB*/ + ext->step = 1; + uint32_t i; + for(i = 0; i < ext->digit_count; i++) { + int32_t new_step = ext->step * 10; + if(new_step >= ext->range_max) break; + ext->step = new_step; + } lv_spinbox_step_previous(spinbox); } } - else if(c == LV_GROUP_KEY_UP) - { - lv_spinbox_increment(spinbox); - } - else if(c == LV_GROUP_KEY_DOWN) - { - lv_spinbox_decrement(spinbox); - } - else - { - if(c == LV_GROUP_KEY_ENTER) - { - int p = lv_ta_get_cursor_pos(spinbox); - if(p == (1 + ext->digit_padding_left + ext->digit_count)) - { - for(int i = 0; i < ext->digit_count; i++) - lv_spinbox_step_previous(spinbox); - } else - { - lv_spinbox_step_next(spinbox); - } - - - lv_spinbox_updatevalue(spinbox); - } - else - { - lv_ta_add_char(spinbox, c); - } + else { + lv_ta_add_char(spinbox, c); } } - return res; } static void lv_spinbox_updatevalue(lv_obj_t * spinbox) { lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - int32_t v = ext->value; - int32_t intDigits, decDigits; - uint8_t dc = ext->digit_count; - intDigits = (ext->dec_point_pos==0) ? ext->digit_count : ext->dec_point_pos; - decDigits = ext->digit_count - intDigits; + char buf[LV_SPINBOX_MAX_DIGIT_COUNT + 8]; + memset(buf, 0, sizeof(buf)); + char * buf_p = buf; - ext->digits[0] = v>=0 ? '+' : '-'; + /*Add the sign*/ + (*buf_p) = ext->value >= 0 ? '+' : '-'; + buf_p++; - int pl; /*padding left*/ - for(pl = 0; pl < ext->digit_padding_left; pl++) - { - ext->digits[1 + pl] = ' '; + int i; + /*padding left*/ + for(i = 0; i < ext->digit_padding_left; i++) { + (*buf_p) = ' '; + buf_p++; } - int i = 0; - uint8_t digits[16]; + char digits[64]; + /*Convert the numbers to string (the sign is already handled so always covert positive number)*/ + lv_math_num_to_str(ext->value < 0 ? -ext->value : ext->value, digits); - if(v < 0) v = -v; - - for(i = 0; i < dc; i++) - { - digits[i] = v%10; - v = v/10; + /*Add leading zeros*/ + int lz_cnt = ext->digit_count - (int)strlen(digits); + if(lz_cnt > 0) { + for(i = strlen(digits); i >= 0; i--) { + digits[i + lz_cnt] = digits[i]; + } + for(i = 0; i < lz_cnt; i++) { + digits[i] = '0'; + } } - int k; - for(k = 0; k < intDigits; k++) - { - ext->digits[1 + pl + k] = '0' + digits[--i]; + int32_t intDigits; + intDigits = (ext->dec_point_pos == 0) ? ext->digit_count : ext->dec_point_pos; + + /*Add the decimal part*/ + for(i = 0; i < intDigits && digits[i] != '\0'; i++) { + (*buf_p) = digits[i]; + buf_p++; } if(ext->dec_point_pos != 0) { - ext->digits[1 + pl + intDigits] = '.'; + /*Insert the decimal point*/ + (*buf_p) = '.'; + buf_p++; - int d; - - for(d = 0; d < decDigits; d++) - { - ext->digits[1 + pl + intDigits + 1 + d] = '0' + digits[--i]; + for(/*Leave i*/ ;i < ext->digit_count && digits[i] != '\0'; i++) { + (*buf_p) = digits[i]; + buf_p++; } - - ext->digits[1 + pl + intDigits + 1 + decDigits] = '\0'; - } else { - ext->digits[1 + pl + intDigits] = '\0'; - } + /*Refresh the text*/ + lv_ta_set_text(spinbox, (char*)buf); - lv_ta_set_text(spinbox, (char*)ext->digits); + /*Set the cursor position*/ int32_t step = ext->step; - uint8_t cPos = ext->digit_count + pl; + uint8_t cur_pos = ext->digit_count; while(step >= 10) { step /= 10; - cPos--; + cur_pos--; } - if(cPos > pl + intDigits ) - { - cPos ++; - } + if(cur_pos > intDigits ) cur_pos ++; /*Skip teh decimal point*/ - lv_ta_set_cursor_pos(spinbox, cPos); + cur_pos += ext->digit_padding_left; + + lv_ta_set_cursor_pos(spinbox, cur_pos); } #endif diff --git a/lv_objx/lv_spinbox.h b/lv_objx/lv_spinbox.h index c2956d055..ca5761487 100644 --- a/lv_objx/lv_spinbox.h +++ b/lv_objx/lv_spinbox.h @@ -50,11 +50,9 @@ typedef struct { int32_t range_max; int32_t range_min; int32_t step; - uint8_t digit_count:4; - uint8_t dec_point_pos:4; /*if 0, there is no separator and the number is an integer*/ - uint8_t digit_padding_left:4; - uint8_t digit_padding_right:4; - uint8_t digits[1+1+LV_SPINBOX_MAX_DIGIT_COUNT]; /*1 sign, 1 point, 16 num digits*/ + uint16_t digit_count:4; + uint16_t dec_point_pos:4; /*if 0, there is no separator and the number is an integer*/ + uint16_t digit_padding_left:4; lv_spinbox_value_changed_cb_t value_changed_cb; } lv_spinbox_ext_t; diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index 2b09354ae..35fe47674 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -88,10 +88,10 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_sw_set_style(new_sw, LV_SW_STYLE_BG, th->sw.bg); - lv_sw_set_style(new_sw, LV_SW_STYLE_INDIC, th->sw.indic); - lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_OFF, th->sw.knob_off); - lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_ON, th->sw.knob_on); + lv_sw_set_style(new_sw, LV_SW_STYLE_BG, th->style.sw.bg); + lv_sw_set_style(new_sw, LV_SW_STYLE_INDIC, th->style.sw.indic); + lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_OFF, th->style.sw.knob_off); + lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_ON, th->style.sw.knob_on); } else { /*Let the slider' style*/ } diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 8427891a6..d3d076885 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -53,6 +53,8 @@ static void pwd_char_hider(lv_obj_t * ta); static bool char_is_accepted(lv_obj_t * ta, uint32_t c); static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res); static void refr_cursor_area(lv_obj_t * ta); +static void placeholder_update(lv_obj_t * ta); +static void update_cursor_position_on_click(lv_obj_t * ta, lv_indev_t * click_source); /********************** * STATIC VARIABLES @@ -127,8 +129,8 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_ta_set_style(new_ta, LV_TA_STYLE_BG, th->ta.area); - lv_ta_set_style(new_ta, LV_TA_STYLE_SB, th->ta.sb); + lv_ta_set_style(new_ta, LV_TA_STYLE_BG, th->style.ta.area); + lv_ta_set_style(new_ta, LV_TA_STYLE_SB, th->style.ta.sb); } else { lv_ta_set_style(new_ta, LV_TA_STYLE_BG, &lv_style_pretty); } @@ -247,6 +249,8 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c) /*Revert the original edge flash state*/ lv_ta_set_edge_flash(ta, edge_flash_en); + + placeholder_update(ta); } /** @@ -310,6 +314,8 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) /*Revert the original edge flash state*/ lv_ta_set_edge_flash(ta, edge_flash_en); + + placeholder_update(ta); } /** @@ -349,6 +355,19 @@ void lv_ta_del_char(lv_obj_t * ta) /*Move the cursor to the place of the deleted character*/ lv_ta_set_cursor_pos(ta, ext->cursor.pos - 1); + + placeholder_update(ta); +} + +/** + * Delete the right character from the current cursor position + * @param ta pointer to a text area object + */ +void lv_ta_del_char_forward(lv_obj_t * ta) +{ + uint16_t cp = lv_ta_get_cursor_pos(ta); + lv_ta_set_cursor_pos(ta, cp + 1); + if(cp != lv_ta_get_cursor_pos(ta)) lv_ta_del_char(ta); } /*===================== @@ -411,6 +430,33 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt) pwd_char_hider(ta); #endif } + + placeholder_update(ta); +} + +/** +* Set the placeholder text of a text area +* @param ta pointer to a text area +* @param txt pointer to the text +*/ +void lv_ta_set_placeholder_text(lv_obj_t * ta, const char * txt) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + /*Create the placeholder label only when it is needed*/ + if(ext->placeholder == NULL) { + ext->placeholder = lv_label_create(ta, NULL); + + if(ext->one_line) { + lv_label_set_long_mode(ext->placeholder, LV_LABEL_LONG_EXPAND); + } else { + lv_label_set_long_mode(ext->placeholder, LV_LABEL_LONG_BREAK); + } + } + + lv_label_set_text(ext->placeholder, txt); + + placeholder_update(ta); } /** @@ -564,6 +610,7 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en) lv_page_set_scrl_fit(ta, true, true); lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND); + if(ext->placeholder) lv_label_set_long_mode(ext->placeholder, LV_LABEL_LONG_EXPAND); lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver); } else { lv_style_t * style_ta = lv_obj_get_style(ta); @@ -571,10 +618,13 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en) ext->one_line = 0; lv_page_set_scrl_fit(ta, false, true); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); + if(ext->placeholder) lv_label_set_long_mode(ext->placeholder, LV_LABEL_LONG_BREAK); + lv_obj_set_height(ta, LV_TA_DEF_HEIGHT); lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver); } + placeholder_update(ta); refr_cursor_area(ta); } @@ -663,6 +713,9 @@ void lv_ta_set_style(lv_obj_t * ta, lv_ta_style_t type, lv_style_t * style) lv_obj_refresh_ext_size(lv_page_get_scrl(ta)); /*Refresh ext. size because of cursor drawing*/ refr_cursor_area(ta); break; + case LV_TA_STYLE_PLACEHOLDER: + if(ext->placeholder) lv_label_set_style(ext->placeholder, style); + break; } } @@ -689,6 +742,21 @@ const char * lv_ta_get_text(const lv_obj_t * ta) return txt; } +/** +* Get the placeholder text of a text area +* @param ta pointer to a text area object +* @return pointer to the text +*/ +const char * lv_ta_get_placeholder_text(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + const char * txt = NULL; + + if(ext->placeholder) txt = lv_label_get_text(ext->label); + + return txt; +} /** * Get the label of a text area @@ -793,6 +861,9 @@ lv_style_t * lv_ta_get_style(const lv_obj_t * ta, lv_ta_style_t type) case LV_TA_STYLE_CURSOR: style = ext->cursor.style; break; + case LV_TA_STYLE_PLACEHOLDER: + if(ext->placeholder) style = lv_label_get_style(ext->placeholder); + break; default: style = NULL; break; @@ -1026,6 +1097,11 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) /*In not one line mode refresh the Label width because 'hpad' can modify it*/ lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); /*Be sure the Label is in the correct position*/ + + if(ext->placeholder) { + lv_obj_set_width(ext->placeholder, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_pos(ext->placeholder, style_scrl->body.padding.hor, style_scrl->body.padding.ver); /*Be sure the placeholder is in the correct position*/ + } } lv_label_set_text(ext->label, NULL); @@ -1041,6 +1117,19 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); lv_label_set_text(ext->label, NULL); /*Refresh the label*/ + refr_cursor_area(ta); + } + } + /*Set the placeholder width according to the text area width*/ + if(ext->placeholder) { + if(lv_obj_get_width(ta) != lv_area_get_width(param) || + lv_obj_get_height(ta) != lv_area_get_height(param)) { + lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + lv_obj_set_width(ext->placeholder, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_pos(ext->placeholder, style_scrl->body.padding.hor, style_scrl->body.padding.ver); + lv_label_set_text(ext->placeholder, NULL); /*Refresh the label*/ + refr_cursor_area(ta); } } @@ -1051,11 +1140,9 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) else if(c == LV_GROUP_KEY_UP) lv_ta_cursor_up(ta); else if(c == LV_GROUP_KEY_DOWN) lv_ta_cursor_down(ta); else if(c == LV_GROUP_KEY_BACKSPACE) lv_ta_del_char(ta); - else if(c == LV_GROUP_KEY_DEL) { - uint16_t cp = lv_ta_get_cursor_pos(ta); - lv_ta_set_cursor_pos(ta, cp + 1); - if(cp != lv_ta_get_cursor_pos(ta)) lv_ta_del_char(ta); - } + else if(c == LV_GROUP_KEY_DEL) lv_ta_del_char_forward(ta); + else if(c == LV_GROUP_KEY_HOME) lv_ta_set_cursor_pos(ta, 0); + else if(c == LV_GROUP_KEY_END) lv_ta_set_cursor_pos(ta, LV_TA_CURSOR_LAST); else { lv_ta_add_char(ta, c); } @@ -1091,6 +1178,9 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) } #endif } + else if(sign == LV_SIGNAL_PRESSED) { + update_cursor_position_on_click(ta, (lv_indev_t *) param); + } return res; } @@ -1109,14 +1199,18 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void res = scrl_signal(scrl, sign, param); if(res != LV_RES_OK) return res; + lv_obj_t * ta = lv_obj_get_parent(scrl); + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); if(sign == LV_SIGNAL_REFR_EXT_SIZE) { /*Set ext. size because the cursor might be out of this object*/ - lv_obj_t * ta = lv_obj_get_parent(scrl); - lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); lv_style_t * style_label = lv_obj_get_style(ext->label); lv_coord_t font_h = lv_font_get_height(style_label->text.font); scrl->ext_size = LV_MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h); } + else if(sign == LV_SIGNAL_PRESSED) { + update_cursor_position_on_click(ta, (lv_indev_t *)param); + } + return res; } @@ -1347,4 +1441,56 @@ static void refr_cursor_area(lv_obj_t * ta) lv_inv_area(disp, &area_tmp); } +static void placeholder_update(lv_obj_t * ta) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + const char * ta_text; + + if(ext->placeholder == NULL) return; + + ta_text = lv_ta_get_text(ta); + + if(ta_text[0] == '\0') { + /*Be sure the main label and the placeholder has the same coordinates*/ + lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + lv_obj_set_pos(ext->placeholder, style_scrl->body.padding.hor, style_scrl->body.padding.ver); + lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); + + lv_obj_set_width(ext->placeholder, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_hidden(ext->placeholder, false); + } + else lv_obj_set_hidden(ext->placeholder, true); +} + +static void update_cursor_position_on_click(lv_obj_t * ta, lv_indev_t * click_source) +{ + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + + lv_area_t label_coords; + uint16_t index_of_char_at_position; + + lv_obj_get_coords(ext->label, &label_coords); + + lv_point_t relative_position; + relative_position.x = click_source->proc.act_point.x - label_coords.x1; + relative_position.y = click_source->proc.act_point.y - label_coords.y1; + + lv_coord_t label_width = lv_obj_get_width(ext->label); + + /*Check if the click happened on the left side of the area outside the label*/ + if (relative_position.x < 0) { + index_of_char_at_position = 0; + } + /*Check if the click happened on the right side of the area outside the label*/ + else if (relative_position.x >= label_width) { + index_of_char_at_position = LV_TA_CURSOR_LAST; + } + else { + index_of_char_at_position = lv_label_get_letter_on(ext->label, &relative_position); + } + + lv_ta_set_cursor_pos(ta, index_of_char_at_position); +} + #endif diff --git a/lv_objx/lv_ta.h b/lv_objx/lv_ta.h index 3227873a7..a993459b1 100644 --- a/lv_objx/lv_ta.h +++ b/lv_objx/lv_ta.h @@ -59,6 +59,7 @@ typedef struct lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * label; /*Label of the text area*/ + lv_obj_t * placeholder; /*Place holder label of the text area, only visible if text is an empty string*/ char * pwd_tmp; /*Used to store the original text in password mode*/ const char * accapted_chars;/*Only these characters will be accepted. NULL: accept all*/ uint16_t max_length; /*The max. number of characters. 0: no limit*/ @@ -80,6 +81,7 @@ enum { LV_TA_STYLE_SB, LV_TA_STYLE_EDGE_FLASH, LV_TA_STYLE_CURSOR, + LV_TA_STYLE_PLACEHOLDER, }; typedef uint8_t lv_ta_style_t; @@ -122,6 +124,12 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt); */ void lv_ta_del_char(lv_obj_t * ta); +/** + * Delete the right character from the current cursor position + * @param ta pointer to a text area object + */ +void lv_ta_del_char_forward(lv_obj_t * ta); + /*===================== * Setter functions *====================*/ @@ -133,6 +141,13 @@ void lv_ta_del_char(lv_obj_t * ta); */ void lv_ta_set_text(lv_obj_t * ta, const char * txt); +/** +* Set the placeholder text of a text area +* @param ta pointer to a text area +* @param txt pointer to the text +*/ +void lv_ta_set_placeholder_text(lv_obj_t * ta, const char * txt); + /** * Set the cursor position * @param obj pointer to a text area object @@ -245,6 +260,13 @@ void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style); */ const char * lv_ta_get_text(const lv_obj_t * ta); +/** +* Get the placeholder text of a text area +* @param ta pointer to a text area object +* @return pointer to the text +*/ +const char * lv_ta_get_placeholder_text(lv_obj_t * ta); + /** * Get the label of a text area * @param ta pointer to a text area object diff --git a/lv_objx/lv_table.c b/lv_objx/lv_table.c index f1446ce33..55cb12896 100644 --- a/lv_objx/lv_table.c +++ b/lv_objx/lv_table.c @@ -89,11 +89,11 @@ lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_table_set_style(new_table, LV_TABLE_STYLE_BG, th->table.bg); - lv_table_set_style(new_table, LV_TABLE_STYLE_CELL1, th->table.cell); - lv_table_set_style(new_table, LV_TABLE_STYLE_CELL2, th->table.cell); - lv_table_set_style(new_table, LV_TABLE_STYLE_CELL3, th->table.cell); - lv_table_set_style(new_table, LV_TABLE_STYLE_CELL4, th->table.cell); + lv_table_set_style(new_table, LV_TABLE_STYLE_BG, th->style.table.bg); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL1, th->style.table.cell); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL2, th->style.table.cell); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL3, th->style.table.cell); + lv_table_set_style(new_table, LV_TABLE_STYLE_CELL4, th->style.table.cell); } else { lv_table_set_style(new_table, LV_TABLE_STYLE_BG, &lv_style_plain_color); } diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index 44e166807..584356f08 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -130,13 +130,13 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, th->tabview.bg); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, th->tabview.indic); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, th->tabview.btn.bg); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_REL, th->tabview.btn.rel); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_PR, th->tabview.btn.pr); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_REL, th->tabview.btn.tgl_rel); - lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_PR, th->tabview.btn.tgl_pr); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, th->style.tabview.bg); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_INDIC, th->style.tabview.indic); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, th->style.tabview.btn.bg); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_REL, th->style.tabview.btn.rel); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_PR, th->style.tabview.btn.pr); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_REL, th->style.tabview.btn.tgl_rel); + lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_TGL_PR, th->style.tabview.btn.tgl_pr); } else { lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BG, &lv_style_plain); lv_tabview_set_style(new_tabview, LV_TABVIEW_STYLE_BTN_BG, &lv_style_transp); @@ -622,12 +622,14 @@ static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * p lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); /*With ENCODER select the first button only in edit mode*/ if(indev_type == LV_INDEV_TYPE_ENCODER) { +#if USE_LV_GROUP lv_group_t * g = lv_obj_get_group(tabview); if(lv_group_get_editing(g)) { lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns); btnm_ext->btn_id_pr = 0; lv_obj_invalidate(ext->btns); } +#endif } else { lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns); btnm_ext->btn_id_pr = 0; diff --git a/lv_objx/lv_tileview.c b/lv_objx/lv_tileview.c index 447534f32..7ae6f63a4 100644 --- a/lv_objx/lv_tileview.c +++ b/lv_objx/lv_tileview.c @@ -95,9 +95,9 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_page_set_style(new_tileview, LV_PAGE_STYLE_BG, th->tileview.bg); - lv_page_set_style(new_tileview, LV_PAGE_STYLE_SCRL, th->tileview.scrl); - lv_page_set_style(new_tileview, LV_PAGE_STYLE_SB, th->tileview.sb); + lv_page_set_style(new_tileview, LV_PAGE_STYLE_BG, th->style.tileview.bg); + lv_page_set_style(new_tileview, LV_PAGE_STYLE_SCRL, th->style.tileview.scrl); + lv_page_set_style(new_tileview, LV_PAGE_STYLE_SB, th->style.tileview.sb); } else { lv_page_set_style(new_tileview, LV_PAGE_STYLE_BG, &lv_style_transp_tight); lv_page_set_style(new_tileview, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); diff --git a/lv_objx/lv_win.c b/lv_objx/lv_win.c index c2abebb9e..49fb3eb1c 100644 --- a/lv_objx/lv_win.c +++ b/lv_objx/lv_win.c @@ -95,13 +95,13 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { - lv_win_set_style(new_win, LV_WIN_STYLE_BG, th->win.bg); - lv_win_set_style(new_win, LV_WIN_STYLE_SB, th->win.sb); - lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, th->win.header); - lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, th->win.content.bg); - lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_SCRL, th->win.content.scrl); - lv_win_set_style(new_win, LV_WIN_STYLE_BTN_REL, th->win.btn.rel); - lv_win_set_style(new_win, LV_WIN_STYLE_BTN_PR, th->win.btn.pr); + lv_win_set_style(new_win, LV_WIN_STYLE_BG, th->style.win.bg); + lv_win_set_style(new_win, LV_WIN_STYLE_SB, th->style.win.sb); + lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, th->style.win.header); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, th->style.win.content.bg); + lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_SCRL, th->style.win.content.scrl); + lv_win_set_style(new_win, LV_WIN_STYLE_BTN_REL, th->style.win.btn.rel); + lv_win_set_style(new_win, LV_WIN_STYLE_BTN_PR, th->style.win.btn.pr); } else { lv_win_set_style(new_win, LV_WIN_STYLE_BG, &lv_style_plain); lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, &lv_style_plain); diff --git a/lv_themes/lv_theme.c b/lv_themes/lv_theme.c index 59a048991..3db5a4cdc 100644 --- a/lv_themes/lv_theme.c +++ b/lv_themes/lv_theme.c @@ -34,10 +34,8 @@ static lv_theme_t * current_theme; * This way the theme styles will always point to the same memory address even after theme is change. * (The pointers in the theme points to the styles declared by the theme itself) */ -/* Store the styles in this array. - * Can't determine the size in compile time because sizeof is not evaluated (should be `sizeof(lv_theme_t) / sizeof(lv_style_t*)`). - * Error will be generated in run time if too small.*/ -static lv_style_t th_styles[120]; +/* Store the styles in this array. */ +static lv_style_t th_styles[LV_THEME_STYLE_COUNT]; static bool inited = false; static lv_theme_t current_theme; #endif @@ -60,18 +58,12 @@ void lv_theme_set_current(lv_theme_t * th) #if LV_THEME_LIVE_UPDATE == 0 current_theme = th; #else - uint32_t style_num = sizeof(lv_theme_t) / sizeof(lv_style_t *); /*Number of styles in a theme*/ + uint32_t style_num = sizeof(th->style) / sizeof(lv_style_t *); /*Number of styles in a theme*/ if(!inited) { - /*It's not sure `th_styles` is big enough. Check it now!*/ - if(style_num > sizeof(th_styles) / sizeof(lv_style_t)) { - LV_LOG_ERROR("Themes: th_styles array is too small. Increase it's size!"); - while(1); - } - /*Initialize the style pointers `current_theme` to point to the `th_styles` style array */ uint16_t i; - lv_style_t ** cur_th_style_p = (lv_style_t **) ¤t_theme; + lv_style_t ** cur_th_style_p = (lv_style_t **) ¤t_theme.style; for(i = 0; i < style_num; i++) { uintptr_t adr = (uintptr_t)&th_styles[i]; memcpy(&cur_th_style_p[i], &adr, sizeof(lv_style_t *)); @@ -82,14 +74,24 @@ void lv_theme_set_current(lv_theme_t * th) /*Copy the styles pointed by the new theme to the `th_styles` style array*/ uint16_t i; - lv_style_t ** th_style = (lv_style_t **) th; + lv_style_t ** th_style = (lv_style_t **) &th->style; for(i = 0; i < style_num; i++) { uintptr_t s = (uintptr_t)th_style[i]; if(s) memcpy(&th_styles[i], (void *)s, sizeof(lv_style_t)); } +#if USE_LV_GROUP + /*Copy group style modification callback functions*/ + memcpy(¤t_theme.group, &th->group, sizeof(th->group)); +#endif + /*Let the object know their style might change*/ lv_obj_report_style_mod(NULL); + +#if USE_LV_GROUP + lv_group_report_style_mod(NULL); +#endif + #endif } diff --git a/lv_themes/lv_theme.h b/lv_themes/lv_theme.h index 72c40aec5..66bbd3d2d 100644 --- a/lv_themes/lv_theme.h +++ b/lv_themes/lv_theme.h @@ -20,6 +20,7 @@ extern "C" { #endif #include "../lv_core/lv_style.h" +#include "../lv_core/lv_group.h" /********************* * DEFINES @@ -30,264 +31,274 @@ extern "C" { **********************/ typedef struct { - lv_style_t *bg; - lv_style_t *panel; + struct { + lv_style_t *bg; + lv_style_t *panel; #if USE_LV_CONT != 0 - lv_style_t *cont; + lv_style_t *cont; #endif #if USE_LV_BTN != 0 - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; #endif #if USE_LV_IMGBTN != 0 - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } imgbtn; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } imgbtn; #endif #if USE_LV_LABEL != 0 - struct { - lv_style_t *prim; - lv_style_t *sec; - lv_style_t *hint; - } label; + struct { + lv_style_t *prim; + lv_style_t *sec; + lv_style_t *hint; + } label; #endif #if USE_LV_IMG != 0 - struct { - lv_style_t *light; - lv_style_t *dark; - } img; + struct { + lv_style_t *light; + lv_style_t *dark; + } img; #endif #if USE_LV_LINE != 0 - struct { - lv_style_t *decor; - } line; + struct { + lv_style_t *decor; + } line; #endif #if USE_LV_LED != 0 - lv_style_t *led; + lv_style_t *led; #endif #if USE_LV_BAR != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - } bar; + struct { + lv_style_t *bg; + lv_style_t *indic; + } bar; #endif #if USE_LV_SLIDER != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - lv_style_t *knob; - } slider; + struct { + lv_style_t *bg; + lv_style_t *indic; + lv_style_t *knob; + } slider; #endif #if USE_LV_LMETER != 0 - lv_style_t *lmeter; + lv_style_t *lmeter; #endif #if USE_LV_GAUGE != 0 - lv_style_t *gauge; + lv_style_t *gauge; #endif #if USE_LV_ARC != 0 - lv_style_t *arc; + lv_style_t *arc; #endif #if USE_LV_PRELOAD != 0 - lv_style_t *preload; + lv_style_t *preload; #endif #if USE_LV_SW != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - lv_style_t *knob_off; - lv_style_t *knob_on; - } sw; + struct { + lv_style_t *bg; + lv_style_t *indic; + lv_style_t *knob_off; + lv_style_t *knob_on; + } sw; #endif #if USE_LV_CHART != 0 - lv_style_t *chart; + lv_style_t *chart; #endif #if USE_LV_CALENDAR != 0 - struct { - lv_style_t *bg; - lv_style_t *header; - lv_style_t *header_pr; - lv_style_t *day_names; - lv_style_t *highlighted_days; - lv_style_t *inactive_days; - lv_style_t *week_box; - lv_style_t *today_box; - } calendar; + struct { + lv_style_t *bg; + lv_style_t *header; + lv_style_t *header_pr; + lv_style_t *day_names; + lv_style_t *highlighted_days; + lv_style_t *inactive_days; + lv_style_t *week_box; + lv_style_t *today_box; + } calendar; #endif #if USE_LV_CB != 0 - struct { - lv_style_t *bg; struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } box; - } cb; + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } box; + } cb; #endif #if USE_LV_BTNM != 0 - struct { - lv_style_t *bg; struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } btnm; + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; + } btnm; #endif #if USE_LV_KB != 0 - struct { - lv_style_t *bg; struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } kb; + lv_style_t *bg; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; + } kb; #endif #if USE_LV_MBOX != 0 - struct { - lv_style_t *bg; struct { lv_style_t *bg; - lv_style_t *rel; - lv_style_t *pr; - } btn; - } mbox; + struct { + lv_style_t *bg; + lv_style_t *rel; + lv_style_t *pr; + } btn; + } mbox; #endif #if USE_LV_PAGE != 0 - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - } page; -#endif - -#if USE_LV_TA != 0 - struct { - lv_style_t *area; - lv_style_t *oneline; - lv_style_t *cursor; - lv_style_t *sb; - } ta; -#endif - -#if USE_LV_SPINBOX != 0 - struct { - lv_style_t *bg; - lv_style_t *cursor; - lv_style_t *sb; - } spinbox; -#endif - -#if USE_LV_LIST - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } list; -#endif - -#if USE_LV_DDLIST != 0 - struct { - lv_style_t *bg; - lv_style_t *sel; - lv_style_t *sb; - } ddlist; -#endif - -#if USE_LV_ROLLER != 0 - struct { - lv_style_t *bg; - lv_style_t *sel; - } roller; -#endif - -#if USE_LV_TABVIEW != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - struct { - lv_style_t *bg; - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - } btn; - } tabview; -#endif - -#if USE_LV_TILEVIEW != 0 - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - } tileview; -#endif - -#if USE_LV_TABLE != 0 - struct { - lv_style_t *bg; - lv_style_t *cell; - } table; -#endif - -#if USE_LV_WIN != 0 - struct { - lv_style_t *bg; - lv_style_t *sb; - lv_style_t *header; struct { lv_style_t *bg; lv_style_t *scrl; - } content; + lv_style_t *sb; + } page; +#endif + +#if USE_LV_TA != 0 struct { - lv_style_t *rel; - lv_style_t *pr; - } btn; - } win; + lv_style_t *area; + lv_style_t *oneline; + lv_style_t *cursor; + lv_style_t *sb; + } ta; +#endif + +#if USE_LV_SPINBOX != 0 + struct { + lv_style_t *bg; + lv_style_t *cursor; + lv_style_t *sb; + } spinbox; +#endif + +#if USE_LV_LIST + struct { + lv_style_t *bg; + lv_style_t *scrl; + lv_style_t *sb; + struct { + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + lv_style_t *ina; + } btn; + } list; +#endif + +#if USE_LV_DDLIST != 0 + struct { + lv_style_t *bg; + lv_style_t *sel; + lv_style_t *sb; + } ddlist; +#endif + +#if USE_LV_ROLLER != 0 + struct { + lv_style_t *bg; + lv_style_t *sel; + } roller; +#endif + +#if USE_LV_TABVIEW != 0 + struct { + lv_style_t *bg; + lv_style_t *indic; + struct { + lv_style_t *bg; + lv_style_t *rel; + lv_style_t *pr; + lv_style_t *tgl_rel; + lv_style_t *tgl_pr; + } btn; + } tabview; +#endif + +#if USE_LV_TILEVIEW != 0 + struct { + lv_style_t *bg; + lv_style_t *scrl; + lv_style_t *sb; + } tileview; +#endif + +#if USE_LV_TABLE != 0 + struct { + lv_style_t *bg; + lv_style_t *cell; + } table; +#endif + +#if USE_LV_WIN != 0 + struct { + lv_style_t *bg; + lv_style_t *sb; + lv_style_t *header; + struct { + lv_style_t *bg; + lv_style_t *scrl; + } content; + struct { + lv_style_t *rel; + lv_style_t *pr; + } btn; + } win; +#endif + } style; + +#if USE_LV_GROUP + struct + { + lv_group_style_mod_func_t style_mod; + lv_group_style_mod_func_t style_mod_edit; + } group; #endif } lv_theme_t; @@ -312,6 +323,9 @@ lv_theme_t * lv_theme_get_current(void); * MACROS **********************/ +/* Returns number of styles within the `lv_theme_t` structure. */ +#define LV_THEME_STYLE_COUNT (sizeof(((lv_theme_t *)0)->style) / sizeof(lv_style_t *)) + /********************** * POST INCLUDE *********************/ diff --git a/lv_themes/lv_theme_alien.c b/lv_themes/lv_theme_alien.c index a928df1fc..45f706ee4 100644 --- a/lv_themes/lv_theme_alien.c +++ b/lv_themes/lv_theme_alien.c @@ -130,15 +130,15 @@ static void basic_init(void) sb.body.padding.ver = 1; sb.body.padding.inner = LV_DPI / 15; /*Scrollbar width*/ - theme.bg = &bg; - theme.panel = &panel; + theme.style.bg = &bg; + theme.style.panel = &panel; } static void cont_init(void) { #if USE_LV_CONT != 0 - theme.cont = &panel; + theme.style.cont = &panel; #endif } @@ -197,11 +197,11 @@ static void btn_init(void) btn_ina.text.font = _font; btn_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 90); - theme.btn.rel = &btn_rel; - theme.btn.pr = &btn_pr; - theme.btn.tgl_rel = &btn_trel; - theme.btn.tgl_pr = &btn_tpr; - theme.btn.ina = &btn_ina; + theme.style.btn.rel = &btn_rel; + theme.style.btn.pr = &btn_pr; + theme.style.btn.tgl_rel = &btn_trel; + theme.style.btn.tgl_pr = &btn_tpr; + theme.style.btn.ina = &btn_ina; #endif } @@ -221,9 +221,9 @@ static void label_init(void) lv_style_copy(&label_hint, &label_prim); label_hint.text.color = lv_color_hsv_to_rgb(_hue, 20, 70); - theme.label.prim = &label_prim; - theme.label.sec = &label_sec; - theme.label.hint = &label_hint; + theme.style.label.prim = &label_prim; + theme.style.label.sec = &label_sec; + theme.style.label.hint = &label_hint; #endif } @@ -255,8 +255,8 @@ static void bar_init(void) bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 80); bar_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 80); - theme.bar.bg = &bar_bg; - theme.bar.indic = &bar_indic; + theme.style.bar.bg = &bar_bg; + theme.style.bar.indic = &bar_indic; #endif } @@ -272,8 +272,8 @@ static void img_init(void) img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 65); img_light.image.intense = LV_OPA_80; - theme.img.light = &img_light; - theme.img.dark = &img_dark; + theme.style.img.light = &img_light; + theme.style.img.dark = &img_dark; #endif } @@ -285,7 +285,7 @@ static void line_init(void) line_decor.line.color = lv_color_hsv_to_rgb(_hue, 50, 50); line_decor.line.width = 1; - theme.line.decor = &line_decor; + theme.style.line.decor = &line_decor; #endif } @@ -303,7 +303,7 @@ static void led_init(void) led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60); led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100); - theme.led = &led; + theme.style.led = &led; #endif } @@ -319,9 +319,9 @@ static void slider_init(void) slider_knob.body.border.color = LV_COLOR_GRAY; slider_knob.body.border.opa = LV_OPA_50; - theme.slider.bg = &bar_bg; - theme.slider.indic = &bar_indic; - theme.slider.knob = &slider_knob; + theme.style.slider.bg = &bar_bg; + theme.style.slider.indic = &bar_indic; + theme.style.slider.knob = &slider_knob; #endif } @@ -346,10 +346,10 @@ static void sw_init(void) lv_style_copy(&sw_knob, &slider_knob); sw_knob.body.opa = LV_OPA_80; - theme.sw.bg = &sw_bg; - theme.sw.indic = &sw_indic; - theme.sw.knob_off = &sw_knob; - theme.sw.knob_on = &sw_knob; + theme.style.sw.bg = &sw_bg; + theme.style.sw.indic = &sw_indic; + theme.style.sw.knob_off = &sw_knob; + theme.style.sw.knob_on = &sw_knob; #endif } @@ -364,7 +364,7 @@ static void lmeter_init(void) lmeter_bg.line.color = LV_COLOR_HEX3(0x222); lmeter_bg.line.width = 2; - theme.lmeter = &lmeter_bg; + theme.style.lmeter = &lmeter_bg; #endif } @@ -385,7 +385,7 @@ static void gauge_init(void) gauge_bg.text.color = lv_color_hsv_to_rgb(_hue, 10, 90); gauge_bg.text.font = _font; - theme.gauge = &gauge_bg; + theme.style.gauge = &gauge_bg; #endif } @@ -405,7 +405,7 @@ static void arc_init(void) arc.body.padding.hor = 3; arc.body.padding.ver = 3; - theme.arc = &arc; + theme.style.arc = &arc; #endif } @@ -413,14 +413,14 @@ static void preload_init(void) { #if USE_LV_PRELOAD != 0 - theme.preload = theme.arc; + theme.style.preload = theme.style.arc; #endif } static void chart_init(void) { #if USE_LV_CHART - theme.chart = &panel; + theme.style.chart = &panel; #endif } @@ -454,13 +454,13 @@ static void calendar_init(void) lv_style_copy(&gray_text, &def); gray_text.text.color = lv_color_hsv_to_rgb(_hue, 10, 65); - theme.calendar.bg = &panel; - theme.calendar.header = &header; - theme.calendar.week_box = &header; - theme.calendar.today_box = &today_box; - theme.calendar.day_names = &color_text; - theme.calendar.highlighted_days = &color_text; - theme.calendar.inactive_days = &gray_text; + theme.style.calendar.bg = &panel; + theme.style.calendar.header = &header; + theme.style.calendar.week_box = &header; + theme.style.calendar.today_box = &today_box; + theme.style.calendar.day_names = &color_text; + theme.style.calendar.highlighted_days = &color_text; + theme.style.calendar.inactive_days = &gray_text; #endif } @@ -506,12 +506,12 @@ static void cb_init(void) cb_ina.body.main_color = LV_COLOR_SILVER; cb_ina.body.grad_color = LV_COLOR_SILVER; - theme.cb.bg = &cb_bg; - theme.cb.box.rel = &cb_rel; - theme.cb.box.pr = &cb_pr; - theme.cb.box.tgl_rel = &cb_trel; - theme.cb.box.tgl_pr = &cb_tpr; - theme.cb.box.ina = &cb_ina; + theme.style.cb.bg = &cb_bg; + theme.style.cb.box.rel = &cb_rel; + theme.style.cb.box.pr = &cb_pr; + theme.style.cb.box.tgl_rel = &cb_trel; + theme.style.cb.box.tgl_pr = &cb_tpr; + theme.style.cb.box.ina = &cb_ina; #endif } @@ -545,24 +545,24 @@ static void btnm_init(void) lv_style_copy(&btnm_ina, &btnm_rel); btnm_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 60); - theme.btnm.bg = &btnm_bg; - theme.btnm.btn.rel = &btnm_rel; - theme.btnm.btn.pr = &btnm_pr; - theme.btnm.btn.tgl_rel = &btnm_trel; - theme.btnm.btn.tgl_pr = &btnm_pr; - theme.btnm.btn.ina = &btnm_ina; + theme.style.btnm.bg = &btnm_bg; + theme.style.btnm.btn.rel = &btnm_rel; + theme.style.btnm.btn.pr = &btnm_pr; + theme.style.btnm.btn.tgl_rel = &btnm_trel; + theme.style.btnm.btn.tgl_pr = &btnm_pr; + theme.style.btnm.btn.ina = &btnm_ina; #endif } static void kb_init(void) { #if USE_LV_KB - theme.kb.bg = &btnm_bg; - theme.kb.btn.rel = &btnm_rel; - theme.kb.btn.pr = &btnm_pr; - theme.kb.btn.tgl_rel = &btnm_trel; - theme.kb.btn.tgl_pr = &btnm_pr; - theme.kb.btn.ina = &btnm_ina; + theme.style.kb.bg = &btnm_bg; + theme.style.kb.btn.rel = &btnm_rel; + theme.style.kb.btn.pr = &btnm_pr; + theme.style.kb.btn.tgl_rel = &btnm_trel; + theme.style.kb.btn.tgl_pr = &btnm_pr; + theme.style.kb.btn.ina = &btnm_ina; #endif } @@ -574,38 +574,38 @@ static void mbox_init(void) lv_style_copy(&mbox_bg, &panel); mbox_bg.body.shadow.width = LV_DPI / 12; - theme.mbox.bg = &mbox_bg; - theme.mbox.btn.bg = &lv_style_transp; - theme.mbox.btn.rel = &btn_trel; - theme.mbox.btn.pr = &btn_tpr; + theme.style.mbox.bg = &mbox_bg; + theme.style.mbox.btn.bg = &lv_style_transp; + theme.style.mbox.btn.rel = &btn_trel; + theme.style.mbox.btn.pr = &btn_tpr; #endif } static void page_init(void) { #if USE_LV_PAGE - theme.page.bg = &panel; - theme.page.scrl = &lv_style_transp_fit; - theme.page.sb = &sb; + theme.style.page.bg = &panel; + theme.style.page.scrl = &lv_style_transp_fit; + theme.style.page.sb = &sb; #endif } static void ta_init(void) { #if USE_LV_TA - theme.ta.area = &panel; - theme.ta.oneline = &panel; - theme.ta.cursor = NULL; - theme.ta.sb = &sb; + theme.style.ta.area = &panel; + theme.style.ta.oneline = &panel; + theme.style.ta.cursor = NULL; + theme.style.ta.sb = &sb; #endif } static void spinbox_init(void) { #if USE_LV_SPINBOX - theme.spinbox.bg= &panel; - theme.spinbox.cursor = theme.ta.cursor; - theme.spinbox.sb = theme.ta.sb; + theme.style.spinbox.bg= &panel; + theme.style.spinbox.cursor = theme.style.ta.cursor; + theme.style.spinbox.sb = theme.style.ta.sb; #endif } @@ -638,14 +638,14 @@ static void list_init(void) list_bg.body.padding.hor = 0; list_bg.body.padding.ver = 0; - theme.list.sb = &sb; - theme.list.bg = &list_bg; - theme.list.scrl = &lv_style_transp_tight; - theme.list.btn.rel = &list_rel; - theme.list.btn.pr = &list_pr; - theme.list.btn.tgl_rel = &list_trel; - theme.list.btn.tgl_pr = &list_tpr; - theme.list.btn.ina = &list_ina; + theme.style.list.sb = &sb; + theme.style.list.bg = &list_bg; + theme.style.list.scrl = &lv_style_transp_tight; + theme.style.list.btn.rel = &list_rel; + theme.style.list.btn.pr = &list_pr; + theme.style.list.btn.tgl_rel = &list_trel; + theme.style.list.btn.tgl_pr = &list_tpr; + theme.style.list.btn.ina = &list_ina; #endif } @@ -663,9 +663,9 @@ static void ddlist_init(void) ddlist_sel.body.opa = LV_OPA_COVER; ddlist_sel.body.radius = 0; - theme.ddlist.bg = &ddlist_bg; - theme.ddlist.sel = &ddlist_sel; - theme.ddlist.sb = &sb; + theme.style.ddlist.bg = &ddlist_bg; + theme.style.ddlist.sel = &ddlist_sel; + theme.style.ddlist.sb = &sb; #endif } @@ -689,8 +689,8 @@ static void roller_init(void) roller_sel.text.opa = LV_OPA_COVER; roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 70, 95); - theme.roller.bg = &roller_bg; - theme.roller.sel = &roller_sel; + theme.style.roller.bg = &roller_bg; + theme.style.roller.sel = &roller_sel; #endif } @@ -743,22 +743,22 @@ static void tabview_init(void) tab_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 87); tab_indic.body.padding.inner = LV_DPI / 10; /*Indicator height*/ - theme.tabview.bg = &bg; - theme.tabview.indic = &tab_indic; - theme.tabview.btn.bg = &lv_style_transp_tight; - theme.tabview.btn.rel = &tab_rel; - theme.tabview.btn.pr = &tab_pr; - theme.tabview.btn.tgl_rel = &tab_trel; - theme.tabview.btn.tgl_pr = &tab_tpr; + theme.style.tabview.bg = &bg; + theme.style.tabview.indic = &tab_indic; + theme.style.tabview.btn.bg = &lv_style_transp_tight; + theme.style.tabview.btn.rel = &tab_rel; + theme.style.tabview.btn.pr = &tab_pr; + theme.style.tabview.btn.tgl_rel = &tab_trel; + theme.style.tabview.btn.tgl_pr = &tab_tpr; #endif } static void tileview_init(void) { #if USE_LV_TILEVIEW != 0 - theme.tileview.bg = &lv_style_transp_tight; - theme.tileview.scrl = &lv_style_transp_tight; - theme.tileview.sb = theme.page.sb; + theme.style.tileview.bg = &lv_style_transp_tight; + theme.style.tileview.scrl = &lv_style_transp_tight; + theme.style.tileview.sb = theme.style.page.sb; #endif } @@ -773,8 +773,8 @@ static void table_init(void) cell.body.padding.ver = LV_DPI / 12; - theme.table.bg = &lv_style_transp_tight; - theme.table.cell = &cell; + theme.style.table.bg = &lv_style_transp_tight; + theme.style.table.cell = &cell; #endif } @@ -796,16 +796,55 @@ static void win_init(void) header.text.color = lv_color_hsv_to_rgb(_hue, 5, 100); header.image.color = lv_color_hsv_to_rgb(_hue, 5, 100); - theme.win.bg = &bg; - theme.win.sb = &sb; - theme.win.header = &header; - theme.win.content.bg = &lv_style_transp; - theme.win.content.scrl = &lv_style_transp; - theme.win.btn.rel = &btn_rel; - theme.win.btn.pr = &btn_pr; + theme.style.win.bg = &bg; + theme.style.win.sb = &sb; + theme.style.win.header = &header; + theme.style.win.content.bg = &lv_style_transp; + theme.style.win.content.scrl = &lv_style_transp; + theme.style.win.btn.rel = &btn_rel; + theme.style.win.btn.pr = &btn_pr; #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = lv_color_hsv_to_rgb(_hue, 70, 90); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +static void style_mod_edit(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_GREEN; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -825,8 +864,8 @@ lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -862,6 +901,11 @@ lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t * font) table_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod_edit; +#endif + return &theme; } diff --git a/lv_themes/lv_theme_default.c b/lv_themes/lv_theme_default.c index a6ddb7276..3a65455d4 100644 --- a/lv_themes/lv_theme_default.c +++ b/lv_themes/lv_theme_default.c @@ -63,19 +63,19 @@ static void basic_init(void) plain_bordered.body.border.width = 2; plain_bordered.body.border.color = LV_COLOR_HEX3(0xbbb); - theme.bg = &lv_style_plain; - theme.panel = &lv_style_pretty; + theme.style.bg = &lv_style_plain; + theme.style.panel = &lv_style_pretty; } static void btn_init(void) { #if USE_LV_BTN != 0 - theme.btn.rel = &lv_style_btn_rel; - theme.btn.pr = &lv_style_btn_pr; - theme.btn.tgl_rel = &lv_style_btn_tgl_rel; - theme.btn.tgl_pr = &lv_style_btn_tgl_pr; - theme.btn.ina = &lv_style_btn_ina; + theme.style.btn.rel = &lv_style_btn_rel; + theme.style.btn.pr = &lv_style_btn_pr; + theme.style.btn.tgl_rel = &lv_style_btn_tgl_rel; + theme.style.btn.tgl_pr = &lv_style_btn_tgl_pr; + theme.style.btn.ina = &lv_style_btn_ina; #endif } @@ -92,9 +92,9 @@ static void label_init(void) label_hint.text.color = LV_COLOR_HEX3(0xaaa); - theme.label.prim = &label_prim; - theme.label.sec = &label_sec; - theme.label.hint = &label_hint; + theme.style.label.prim = &label_prim; + theme.style.label.sec = &label_sec; + theme.style.label.hint = &label_hint; #endif } @@ -104,8 +104,8 @@ static void img_init(void) #if USE_LV_IMG != 0 - theme.img.light = &def; - theme.img.dark = &def; + theme.style.img.light = &def; + theme.style.img.dark = &def; #endif } @@ -113,7 +113,7 @@ static void line_init(void) { #if USE_LV_LINE != 0 - theme.line.decor = &def; + theme.style.line.decor = &def; #endif } @@ -130,7 +130,7 @@ static void led_init(void) led.body.shadow.color = led.body.main_color; - theme.led = &led; + theme.style.led = &led; #endif } @@ -138,8 +138,8 @@ static void bar_init(void) { #if USE_LV_BAR - theme.bar.bg = &lv_style_pretty; - theme.bar.indic = &lv_style_pretty_color; + theme.style.bar.bg = &lv_style_pretty; + theme.style.bar.indic = &lv_style_pretty_color; #endif } @@ -150,9 +150,9 @@ static void slider_init(void) slider_bg.body.padding.hor = LV_DPI / 20; slider_bg.body.padding.ver = LV_DPI / 20; - theme.slider.bg = &slider_bg; - theme.slider.indic = &lv_style_pretty_color; - theme.slider.knob = &lv_style_pretty; + theme.style.slider.bg = &slider_bg; + theme.style.slider.indic = &lv_style_pretty_color; + theme.style.slider.knob = &lv_style_pretty; #endif } @@ -163,10 +163,10 @@ static void sw_init(void) sw_bg.body.padding.hor = 3; sw_bg.body.padding.ver = 3; - theme.sw.bg = &sw_bg; - theme.sw.indic = &lv_style_pretty_color; - theme.sw.knob_off = &lv_style_pretty; - theme.sw.knob_on = &lv_style_pretty; + theme.style.sw.bg = &sw_bg; + theme.style.sw.indic = &lv_style_pretty_color; + theme.style.sw.knob_off = &lv_style_pretty; + theme.style.sw.knob_on = &lv_style_pretty; #endif } @@ -181,7 +181,7 @@ static void lmeter_init(void) lmeter.body.main_color = lv_color_mix(lmeter.body.main_color, LV_COLOR_WHITE, LV_OPA_50); lmeter.body.grad_color = lv_color_mix(lmeter.body.grad_color, LV_COLOR_BLACK, LV_OPA_50); - theme.lmeter = &lmeter; + theme.style.lmeter = &lmeter; #endif } @@ -196,7 +196,7 @@ static void gauge_init(void) gauge.body.grad_color = lmeter.body.main_color; gauge.text.color = LV_COLOR_HEX3(0x888); - theme.gauge = &gauge; + theme.style.gauge = &gauge; #endif } @@ -205,7 +205,7 @@ static void chart_init(void) #if USE_LV_CHART - theme.chart = &lv_style_pretty; + theme.style.chart = &lv_style_pretty; #endif } @@ -214,12 +214,12 @@ static void cb_init(void) #if USE_LV_CB != 0 - theme.cb.bg = &lv_style_transp; - theme.cb.box.rel = &lv_style_pretty; - theme.cb.box.pr = &lv_style_btn_pr; - theme.cb.box.tgl_rel = &lv_style_btn_tgl_rel; - theme.cb.box.tgl_pr = &lv_style_btn_tgl_pr; - theme.cb.box.ina = &lv_style_btn_ina; + theme.style.cb.bg = &lv_style_transp; + theme.style.cb.box.rel = &lv_style_pretty; + theme.style.cb.box.pr = &lv_style_btn_pr; + theme.style.cb.box.tgl_rel = &lv_style_btn_tgl_rel; + theme.style.cb.box.tgl_pr = &lv_style_btn_tgl_pr; + theme.style.cb.box.ina = &lv_style_btn_ina; #endif } @@ -229,12 +229,12 @@ static void btnm_init(void) #if USE_LV_BTNM - theme.btnm.bg = &lv_style_pretty; - theme.btnm.btn.rel = &lv_style_btn_rel; - theme.btnm.btn.pr = &lv_style_btn_pr; - theme.btnm.btn.tgl_rel = &lv_style_btn_tgl_rel; - theme.btnm.btn.tgl_pr = &lv_style_btn_tgl_pr; - theme.btnm.btn.ina = &lv_style_btn_ina; + theme.style.btnm.bg = &lv_style_pretty; + theme.style.btnm.btn.rel = &lv_style_btn_rel; + theme.style.btnm.btn.pr = &lv_style_btn_pr; + theme.style.btnm.btn.tgl_rel = &lv_style_btn_tgl_rel; + theme.style.btnm.btn.tgl_pr = &lv_style_btn_tgl_pr; + theme.style.btnm.btn.ina = &lv_style_btn_ina; #endif } @@ -243,12 +243,12 @@ static void kb_init(void) #if USE_LV_KB - theme.kb.bg = &lv_style_pretty; - theme.kb.btn.rel = &lv_style_btn_rel; - theme.kb.btn.pr = &lv_style_btn_pr; - theme.kb.btn.tgl_rel = &lv_style_btn_tgl_rel; - theme.kb.btn.tgl_pr = &lv_style_btn_tgl_pr; - theme.kb.btn.ina = &lv_style_btn_ina; + theme.style.kb.bg = &lv_style_pretty; + theme.style.kb.btn.rel = &lv_style_btn_rel; + theme.style.kb.btn.pr = &lv_style_btn_pr; + theme.style.kb.btn.tgl_rel = &lv_style_btn_tgl_rel; + theme.style.kb.btn.tgl_pr = &lv_style_btn_tgl_pr; + theme.style.kb.btn.ina = &lv_style_btn_ina; #endif } @@ -258,10 +258,10 @@ static void mbox_init(void) #if USE_LV_MBOX - theme.mbox.bg = &lv_style_pretty; - theme.mbox.btn.bg = &lv_style_transp; - theme.mbox.btn.rel = &lv_style_btn_rel; - theme.mbox.btn.pr = &lv_style_btn_tgl_pr; + theme.style.mbox.bg = &lv_style_pretty; + theme.style.mbox.btn.bg = &lv_style_transp; + theme.style.mbox.btn.rel = &lv_style_btn_rel; + theme.style.mbox.btn.pr = &lv_style_btn_tgl_pr; #endif } @@ -270,9 +270,9 @@ static void page_init(void) #if USE_LV_PAGE - theme.page.bg = &lv_style_pretty; - theme.page.scrl = &lv_style_transp_tight; - theme.page.sb = &sb; + theme.style.page.bg = &lv_style_pretty; + theme.style.page.scrl = &lv_style_transp_tight; + theme.style.page.sb = &sb; #endif } @@ -281,10 +281,10 @@ static void ta_init(void) #if USE_LV_TA - theme.ta.area = &lv_style_pretty; - theme.ta.oneline = &lv_style_pretty; - theme.ta.cursor = NULL; - theme.ta.sb = &sb; + theme.style.ta.area = &lv_style_pretty; + theme.style.ta.oneline = &lv_style_pretty; + theme.style.ta.cursor = NULL; + theme.style.ta.sb = &sb; #endif } @@ -292,14 +292,14 @@ static void list_init(void) { #if USE_LV_LIST != 0 - theme.list.bg = &lv_style_pretty; - theme.list.scrl = &lv_style_transp_fit; - theme.list.sb = &sb; - theme.list.btn.rel = &lv_style_btn_rel; - theme.list.btn.pr = &lv_style_btn_pr; - theme.list.btn.tgl_rel = &lv_style_btn_tgl_rel; - theme.list.btn.tgl_pr = &lv_style_btn_tgl_pr; - theme.list.btn.ina = &lv_style_btn_ina; + theme.style.list.bg = &lv_style_pretty; + theme.style.list.scrl = &lv_style_transp_fit; + theme.style.list.sb = &sb; + theme.style.list.btn.rel = &lv_style_btn_rel; + theme.style.list.btn.pr = &lv_style_btn_pr; + theme.style.list.btn.tgl_rel = &lv_style_btn_tgl_rel; + theme.style.list.btn.tgl_pr = &lv_style_btn_tgl_pr; + theme.style.list.btn.ina = &lv_style_btn_ina; #endif } @@ -308,9 +308,9 @@ static void ddlist_init(void) #if USE_LV_DDLIST != 0 - theme.ddlist.bg = &lv_style_pretty; - theme.ddlist.sel = &lv_style_plain_color; - theme.ddlist.sb = &sb; + theme.style.ddlist.bg = &lv_style_pretty; + theme.style.ddlist.sel = &lv_style_plain_color; + theme.style.ddlist.sb = &sb; #endif } @@ -319,8 +319,8 @@ static void roller_init(void) #if USE_LV_ROLLER != 0 - theme.roller.bg = &lv_style_pretty; - theme.roller.sel = &lv_style_plain_color; + theme.style.roller.bg = &lv_style_pretty; + theme.style.roller.sel = &lv_style_plain_color; #endif } @@ -329,13 +329,13 @@ static void tabview_init(void) #if USE_LV_TABVIEW != 0 - theme.tabview.bg = &plain_bordered; - theme.tabview.indic = &lv_style_plain_color; - theme.tabview.btn.bg = &lv_style_transp; - theme.tabview.btn.rel = &lv_style_btn_rel; - theme.tabview.btn.pr = &lv_style_btn_pr; - theme.tabview.btn.tgl_rel = &lv_style_btn_tgl_rel; - theme.tabview.btn.tgl_pr = &lv_style_btn_tgl_pr; + theme.style.tabview.bg = &plain_bordered; + theme.style.tabview.indic = &lv_style_plain_color; + theme.style.tabview.btn.bg = &lv_style_transp; + theme.style.tabview.btn.rel = &lv_style_btn_rel; + theme.style.tabview.btn.pr = &lv_style_btn_pr; + theme.style.tabview.btn.tgl_rel = &lv_style_btn_tgl_rel; + theme.style.tabview.btn.tgl_pr = &lv_style_btn_tgl_pr; #endif } @@ -345,16 +345,64 @@ static void win_init(void) #if USE_LV_WIN != 0 - theme.win.bg = &plain_bordered; - theme.win.sb = &sb; - theme.win.header = &lv_style_plain_color; - theme.win.content.bg = &lv_style_transp; - theme.win.content.scrl = &lv_style_transp; - theme.win.btn.rel = &lv_style_btn_rel; - theme.win.btn.pr = &lv_style_btn_pr; + theme.style.win.bg = &plain_bordered; + theme.style.win.sb = &sb; + theme.style.win.header = &lv_style_plain_color; + theme.style.win.content.bg = &lv_style_transp; + theme.style.win.content.scrl = &lv_style_transp; + theme.style.win.btn.rel = &lv_style_btn_rel; + theme.style.win.btn.pr = &lv_style_btn_pr; #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_ORANGE; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_ORANGE, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_ORANGE, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +static void style_mod_edit(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_GREEN; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -376,8 +424,8 @@ lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -406,6 +454,11 @@ lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t * font) tabview_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod_edit; +#endif + return &theme; } diff --git a/lv_themes/lv_theme_material.c b/lv_themes/lv_theme_material.c index 01e4791e4..812dfd362 100644 --- a/lv_themes/lv_theme_material.c +++ b/lv_themes/lv_theme_material.c @@ -80,8 +80,8 @@ static void basic_init(void) sb.body.opa = LV_OPA_40; sb.body.padding.hor = LV_DPI / 25; - theme.bg = &bg; - theme.panel = &panel; + theme.style.bg = &bg; + theme.style.panel = &panel; } @@ -90,7 +90,7 @@ static void cont_init(void) #if USE_LV_CONT != 0 - theme.cont = theme.panel; + theme.style.cont = theme.style.panel; #endif } @@ -135,11 +135,11 @@ static void btn_init(void) ina.text.color = lv_color_hsv_to_rgb(_hue, 95, 5); ina.image.color = lv_color_hsv_to_rgb(_hue, 95, 5); - theme.btn.rel = &rel; - theme.btn.pr = ≺ - theme.btn.tgl_rel = &tgl_rel; - theme.btn.tgl_pr = &tgl_pr; - theme.btn.ina = &ina; + theme.style.btn.rel = &rel; + theme.style.btn.pr = ≺ + theme.style.btn.tgl_rel = &tgl_rel; + theme.style.btn.tgl_pr = &tgl_pr; + theme.style.btn.ina = &ina; #endif } @@ -159,9 +159,9 @@ static void label_init(void) lv_style_copy(&hint, &prim); hint.text.color = lv_color_hsv_to_rgb(_hue, 40, 90); - theme.label.prim = &prim; - theme.label.sec = &sec; - theme.label.hint = &hint; + theme.style.label.prim = &prim; + theme.style.label.sec = &sec; + theme.style.label.hint = &hint; #endif } @@ -178,8 +178,8 @@ static void img_init(void) img_light.image.intense = LV_OPA_80; - theme.img.light = &def; - theme.img.dark = &def; + theme.style.img.light = &def; + theme.style.img.dark = &def; #endif } @@ -188,7 +188,7 @@ static void line_init(void) #if USE_LV_LINE != 0 - theme.line.decor = &def; + theme.style.line.decor = &def; #endif } @@ -207,7 +207,7 @@ static void led_init(void) led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100); - theme.led = &led; + theme.style.led = &led; #endif } @@ -230,8 +230,8 @@ static void bar_init(void) bar_indic.body.padding.hor = 0; bar_indic.body.padding.ver = 0; - theme.bar.bg = &bar_bg; - theme.bar.indic = &bar_indic; + theme.style.bar.bg = &bar_bg; + theme.style.bar.indic = &bar_indic; #endif } @@ -243,12 +243,12 @@ static void slider_init(void) lv_style_copy(&knob, &def); knob.body.radius = LV_RADIUS_CIRCLE; knob.body.border.width = 0; - knob.body.main_color = theme.bar.indic->body.main_color; + knob.body.main_color = theme.style.bar.indic->body.main_color; knob.body.grad_color = knob.body.main_color; - theme.slider.bg = theme.bar.bg; - theme.slider.indic = theme.bar.indic; - theme.slider.knob = &knob; + theme.style.slider.bg = theme.style.bar.bg; + theme.style.slider.indic = theme.style.bar.indic; + theme.style.slider.knob = &knob; #endif } @@ -256,13 +256,13 @@ static void sw_init(void) { #if USE_LV_SW != 0 static lv_style_t sw_bg, sw_indic, sw_knob_off, sw_knob_on; - lv_style_copy(&sw_bg, theme.slider.bg); + lv_style_copy(&sw_bg, theme.style.slider.bg); sw_bg.body.radius = LV_RADIUS_CIRCLE; - lv_style_copy(&sw_indic, theme.slider.bg); + lv_style_copy(&sw_indic, theme.style.slider.bg); sw_indic.body.radius = LV_RADIUS_CIRCLE; - lv_style_copy(&sw_knob_on, theme.slider.knob); + lv_style_copy(&sw_knob_on, theme.style.slider.knob); sw_knob_on.body.shadow.width = 3; sw_knob_on.body.shadow.type = LV_SHADOW_BOTTOM; sw_knob_on.body.shadow.color = DEF_SHADOW_COLOR; @@ -275,10 +275,10 @@ static void sw_init(void) sw_knob_off.body.border.color = LV_COLOR_HEX3(0x999); sw_knob_off.body.border.opa = LV_OPA_COVER; - theme.sw.bg = &sw_bg; - theme.sw.indic = &sw_indic; - theme.sw.knob_off = &sw_knob_off; - theme.sw.knob_on = &sw_knob_on; + theme.style.sw.bg = &sw_bg; + theme.style.sw.indic = &sw_indic; + theme.style.sw.knob_off = &sw_knob_off; + theme.style.sw.knob_on = &sw_knob_on; #endif } @@ -294,7 +294,7 @@ static void lmeter_init(void) lmeter.line.color = LV_COLOR_HEX3(0x999); lmeter.line.width = 2; - theme.lmeter = &lmeter; + theme.style.lmeter = &lmeter; #endif } @@ -313,7 +313,7 @@ static void gauge_init(void) gauge.line.width = 3; gauge.line.color = lv_color_hsv_to_rgb(_hue, 95, 70); - theme.gauge = &gauge; + theme.style.gauge = &gauge; #endif } @@ -332,7 +332,7 @@ static void arc_init(void) arc.body.padding.hor = 0; arc.body.padding.ver = 0; - theme.arc = &arc; + theme.style.arc = &arc; #endif } @@ -340,14 +340,14 @@ static void preload_init(void) { #if USE_LV_PRELOAD != 0 - theme.preload = theme.arc; + theme.style.preload = theme.style.arc; #endif } static void chart_init(void) { #if USE_LV_CHART - theme.chart = theme.panel; + theme.style.chart = theme.style.panel; #endif } @@ -367,9 +367,9 @@ static void calendar_init(void) week_box.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 100); week_box.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 100); week_box.body.padding.ver = LV_DPI / 20; - week_box.body.padding.hor = theme.panel->body.padding.hor; - week_box.body.border.color = theme.panel->body.border.color; - week_box.body.border.width = theme.panel->body.border.width; + week_box.body.padding.hor = theme.style.panel->body.padding.hor; + week_box.body.border.color = theme.style.panel->body.border.color; + week_box.body.border.width = theme.style.panel->body.border.width; week_box.body.border.part = LV_BORDER_LEFT | LV_BORDER_RIGHT; week_box.body.radius = 0; @@ -380,12 +380,12 @@ static void calendar_init(void) today_box.body.padding.ver = LV_DPI / 20; today_box.body.radius = 0; - theme.calendar.bg = theme.panel; - theme.calendar.header = &lv_style_transp; - theme.calendar.inactive_days = &ina_days; - theme.calendar.highlighted_days = &high_days; - theme.calendar.week_box = &week_box; - theme.calendar.today_box = &today_box; + theme.style.calendar.bg = theme.style.panel; + theme.style.calendar.header = &lv_style_transp; + theme.style.calendar.inactive_days = &ina_days; + theme.style.calendar.highlighted_days = &high_days; + theme.style.calendar.week_box = &week_box; + theme.style.calendar.today_box = &today_box; #endif } @@ -393,7 +393,7 @@ static void cb_init(void) { #if USE_LV_CB != 0 static lv_style_t rel, pr, tgl_rel, tgl_pr, ina; - lv_style_copy(&rel, theme.panel); + lv_style_copy(&rel, theme.style.panel); rel.body.shadow.type = LV_SHADOW_BOTTOM; rel.body.shadow.width = 3; @@ -413,14 +413,14 @@ static void cb_init(void) tgl_pr.body.grad_color = tgl_pr.body.main_color; tgl_pr.body.shadow.width = 0; - lv_style_copy(&ina, theme.btn.ina); + lv_style_copy(&ina, theme.style.btn.ina); - theme.cb.bg = &lv_style_transp; - theme.cb.box.rel = &rel; - theme.cb.box.pr = ≺ - theme.cb.box.tgl_rel = &tgl_rel; - theme.cb.box.tgl_pr = &tgl_pr; - theme.cb.box.ina = &ina; + theme.style.cb.bg = &lv_style_transp; + theme.style.cb.box.rel = &rel; + theme.style.cb.box.pr = ≺ + theme.style.cb.box.tgl_rel = &tgl_rel; + theme.style.cb.box.tgl_pr = &tgl_pr; + theme.style.cb.box.ina = &ina; #endif } @@ -430,13 +430,13 @@ static void btnm_init(void) #if USE_LV_BTNM static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina; - lv_style_copy(&bg, theme.panel); + lv_style_copy(&bg, theme.style.panel); bg.body.padding.hor = 0; bg.body.padding.ver = 0; bg.body.padding.inner = 0; bg.text.color = LV_COLOR_HEX3(0x555); - lv_style_copy(&rel, theme.panel); + lv_style_copy(&rel, theme.style.panel); rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL; rel.body.border.width = 1; rel.body.border.color = LV_COLOR_HEX3(0xbbb); @@ -465,12 +465,12 @@ static void btnm_init(void) ina.body.main_color = LV_COLOR_HEX3(0xccc); ina.body.grad_color = ina.body.main_color; - theme.btnm.bg = &bg; - theme.btnm.btn.rel = &rel; - theme.btnm.btn.pr = ≺ - theme.btnm.btn.tgl_rel = &tgl_rel; - theme.btnm.btn.tgl_pr = &tgl_pr; - theme.btnm.btn.ina = &def; + theme.style.btnm.bg = &bg; + theme.style.btnm.btn.rel = &rel; + theme.style.btnm.btn.pr = ≺ + theme.style.btnm.btn.tgl_rel = &tgl_rel; + theme.style.btnm.btn.tgl_pr = &tgl_pr; + theme.style.btnm.btn.ina = &def; #endif } @@ -482,12 +482,12 @@ static void kb_init(void) lv_style_copy(&rel, &lv_style_transp); rel.text.font = _font; - theme.kb.bg = theme.btnm.bg; - theme.kb.btn.rel = &rel; - theme.kb.btn.pr = theme.btnm.btn.pr; - theme.kb.btn.tgl_rel = theme.btnm.btn.tgl_rel; - theme.kb.btn.tgl_pr = theme.btnm.btn.tgl_pr; - theme.kb.btn.ina = theme.btnm.btn.ina; + theme.style.kb.bg = theme.style.btnm.bg; + theme.style.kb.btn.rel = &rel; + theme.style.kb.btn.pr = theme.style.btnm.btn.pr; + theme.style.kb.btn.tgl_rel = theme.style.btnm.btn.tgl_rel; + theme.style.kb.btn.tgl_pr = theme.style.btnm.btn.tgl_pr; + theme.style.kb.btn.ina = theme.style.btnm.btn.ina; #endif } @@ -502,13 +502,13 @@ static void mbox_init(void) rel.text.font = _font; rel.text.color = lv_color_hsv_to_rgb(_hue, 85, 75); - lv_style_copy(&pr, theme.btnm.btn.pr); + lv_style_copy(&pr, theme.style.btnm.btn.pr); pr.text.color = lv_color_hsv_to_rgb(_hue, 85, 60); - theme.mbox.bg = theme.panel; - theme.mbox.btn.bg = &lv_style_transp; - theme.mbox.btn.rel = &rel; - theme.mbox.btn.pr = ≺ + theme.style.mbox.bg = theme.style.panel; + theme.style.mbox.btn.bg = &lv_style_transp; + theme.style.mbox.btn.rel = &rel; + theme.style.mbox.btn.pr = ≺ #endif } @@ -517,9 +517,9 @@ static void page_init(void) #if USE_LV_PAGE - theme.page.bg = theme.panel; - theme.page.scrl = &lv_style_transp; - theme.page.sb = &sb; + theme.style.page.bg = theme.style.panel; + theme.style.page.scrl = &lv_style_transp; + theme.style.page.sb = &sb; #endif } @@ -537,19 +537,19 @@ static void ta_init(void) oneline.body.border.opa = LV_OPA_COVER; oneline.text.color = LV_COLOR_HEX3(0x333); - theme.ta.area = theme.panel; - theme.ta.oneline = &oneline; - theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ - theme.ta.sb = &sb; + theme.style.ta.area = theme.style.panel; + theme.style.ta.oneline = &oneline; + theme.style.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ + theme.style.ta.sb = &sb; #endif } static void spinbox_init(void) { #if USE_LV_SPINBOX - theme.spinbox.bg= theme.panel; - theme.spinbox.cursor = theme.ta.cursor; - theme.spinbox.sb = theme.ta.sb; + theme.style.spinbox.bg= theme.style.panel; + theme.style.spinbox.cursor = theme.style.ta.cursor; + theme.style.spinbox.sb = theme.style.ta.sb; #endif } @@ -559,7 +559,7 @@ static void list_init(void) static lv_style_t list_bg, rel, pr, tgl_rel, tgl_pr, ina; - lv_style_copy(&list_bg, theme.panel); + lv_style_copy(&list_bg, theme.style.panel); list_bg.body.padding.hor = 0; list_bg.body.padding.ver = 0; list_bg.body.padding.inner = 0; @@ -597,14 +597,14 @@ static void list_init(void) ina.body.grad_color = ina.body.main_color; - theme.list.sb = &sb; - theme.list.bg = &list_bg; - theme.list.scrl = &lv_style_transp_tight; - theme.list.btn.rel = &rel; - theme.list.btn.pr = ≺ - theme.list.btn.tgl_rel = &tgl_rel; - theme.list.btn.tgl_pr = &tgl_pr; - theme.list.btn.ina = &ina; + theme.style.list.sb = &sb; + theme.style.list.bg = &list_bg; + theme.style.list.scrl = &lv_style_transp_tight; + theme.style.list.btn.rel = &rel; + theme.style.list.btn.pr = ≺ + theme.style.list.btn.tgl_rel = &tgl_rel; + theme.style.list.btn.tgl_pr = &tgl_pr; + theme.style.list.btn.ina = &ina; #endif } @@ -612,7 +612,7 @@ static void ddlist_init(void) { #if USE_LV_DDLIST != 0 static lv_style_t bg, sel; - lv_style_copy(&bg, theme.panel); + lv_style_copy(&bg, theme.style.panel); bg.body.padding.hor = LV_DPI / 6; bg.body.padding.ver = LV_DPI / 6; bg.text.line_space = LV_DPI / 8; @@ -626,9 +626,9 @@ static void ddlist_init(void) sel.text.color = lv_color_hsv_to_rgb(_hue, 5, 95); - theme.ddlist.bg = &bg; - theme.ddlist.sel = &sel; - theme.ddlist.sb = &sb; + theme.style.ddlist.bg = &bg; + theme.style.ddlist.sel = &sel; + theme.style.ddlist.sb = &sb; #endif } @@ -648,8 +648,8 @@ static void roller_init(void) roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 90, 70); - theme.roller.bg = &roller_bg; - theme.roller.sel = &roller_sel; + theme.style.roller.bg = &roller_bg; + theme.style.roller.sel = &roller_sel; #endif } @@ -711,22 +711,22 @@ static void tabview_init(void) tgl_pr.body.radius = 0; tgl_pr.text.color = lv_color_hsv_to_rgb(_hue, 90, 60); - theme.tabview.bg = theme.bg; - theme.tabview.indic = &indic; - theme.tabview.btn.bg = &btn_bg; - theme.tabview.btn.rel = &rel; - theme.tabview.btn.pr = ≺ - theme.tabview.btn.tgl_rel = &tgl_rel; - theme.tabview.btn.tgl_pr = &tgl_pr; + theme.style.tabview.bg = theme.style.bg; + theme.style.tabview.indic = &indic; + theme.style.tabview.btn.bg = &btn_bg; + theme.style.tabview.btn.rel = &rel; + theme.style.tabview.btn.pr = ≺ + theme.style.tabview.btn.tgl_rel = &tgl_rel; + theme.style.tabview.btn.tgl_pr = &tgl_pr; #endif } static void tileview_init(void) { #if USE_LV_TILEVIEW != 0 - theme.tileview.bg = &lv_style_transp_tight; - theme.tileview.scrl = &lv_style_transp_tight; - theme.tileview.sb = theme.page.sb; + theme.style.tileview.bg = &lv_style_transp_tight; + theme.style.tileview.scrl = &lv_style_transp_tight; + theme.style.tileview.sb = theme.style.page.sb; #endif } @@ -734,15 +734,15 @@ static void table_init(void) { #if USE_LV_TABLE != 0 static lv_style_t cell; - lv_style_copy(&cell, theme.panel); + lv_style_copy(&cell, theme.style.panel); cell.body.radius = 0; cell.body.border.width = 1; cell.body.padding.hor = LV_DPI / 12; cell.body.padding.ver = LV_DPI / 12; - theme.table.bg = &lv_style_transp_tight; - theme.table.cell = &cell; + theme.style.table.bg = &lv_style_transp_tight; + theme.style.table.cell = &cell; #endif } @@ -775,16 +775,64 @@ static void win_init(void) pr.image.color = LV_COLOR_HEX3(0x111); - theme.win.bg = theme.panel; - theme.win.sb = &sb; - theme.win.header = &header; - theme.win.content.bg = &lv_style_transp; - theme.win.content.scrl = &lv_style_transp; - theme.win.btn.rel = &lv_style_transp; - theme.win.btn.pr = ≺ + theme.style.win.bg = theme.style.panel; + theme.style.win.sb = &sb; + theme.style.win.header = &header; + theme.style.win.content.bg = &lv_style_transp; + theme.style.win.content.scrl = &lv_style_transp; + theme.style.win.btn.rel = &lv_style_transp; + theme.style.win.btn.pr = ≺ #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = lv_color_hsv_to_rgb(_hue, 90, 70); + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, lv_color_hsv_to_rgb(_hue, 90, 70), LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, lv_color_hsv_to_rgb(_hue, 90, 70), LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, lv_color_hsv_to_rgb(_hue, 90, 70), LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, lv_color_hsv_to_rgb(_hue, 90, 70), LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +static void style_mod_edit(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_GREEN; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -806,8 +854,8 @@ lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -843,6 +891,11 @@ lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t * font) table_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod_edit; +#endif + return &theme; } diff --git a/lv_themes/lv_theme_mono.c b/lv_themes/lv_theme_mono.c index af18f8a5d..25ce93f89 100644 --- a/lv_themes/lv_theme_mono.c +++ b/lv_themes/lv_theme_mono.c @@ -91,8 +91,8 @@ static void basic_init(void) lv_style_copy(&dark_frame, &dark_plain); dark_frame.body.radius = LV_DPI / 20; - theme.bg = &def; - theme.panel = &light_frame; + theme.style.bg = &def; + theme.style.panel = &light_frame; } @@ -101,7 +101,7 @@ static void cont_init(void) #if USE_LV_CONT != 0 - theme.cont = &def; + theme.style.cont = &def; #endif } @@ -110,11 +110,11 @@ static void btn_init(void) #if USE_LV_BTN != 0 - theme.btn.rel = &light_frame; - theme.btn.pr = &dark_frame; - theme.btn.tgl_rel = &dark_frame; - theme.btn.tgl_pr = &light_frame; - theme.btn.ina = &light_frame; + theme.style.btn.rel = &light_frame; + theme.style.btn.pr = &dark_frame; + theme.style.btn.tgl_rel = &dark_frame; + theme.style.btn.tgl_pr = &light_frame; + theme.style.btn.ina = &light_frame; #endif } @@ -124,9 +124,9 @@ static void label_init(void) #if USE_LV_LABEL != 0 - theme.label.prim = NULL; - theme.label.sec = NULL; - theme.label.hint = NULL; + theme.style.label.prim = NULL; + theme.style.label.sec = NULL; + theme.style.label.hint = NULL; #endif } @@ -135,15 +135,15 @@ static void img_init(void) #if USE_LV_IMG != 0 - theme.img.light = &def; - theme.img.dark = &def; + theme.style.img.light = &def; + theme.style.img.dark = &def; #endif } static void line_init(void) { #if USE_LV_LINE != 0 - theme.line.decor = NULL; + theme.style.line.decor = NULL; #endif } @@ -157,7 +157,7 @@ static void led_init(void) led.body.shadow.color = LV_COLOR_BLACK; led.body.shadow.type = LV_SHADOW_FULL; - theme.led = &led; + theme.style.led = &led; #endif } @@ -177,8 +177,8 @@ static void bar_init(void) bar_indic.body.padding.ver = LV_DPI / 30; bar_indic.body.radius = LV_RADIUS_CIRCLE; - theme.bar.bg = &bar_bg; - theme.bar.indic = &bar_indic; + theme.style.bar.bg = &bar_bg; + theme.style.bar.indic = &bar_indic; #endif } @@ -191,9 +191,9 @@ static void slider_init(void) slider_knob.body.padding.hor = LV_DPI / 30; slider_knob.body.padding.ver = LV_DPI / 30; - theme.slider.bg = theme.bar.bg; - theme.slider.indic = theme.bar.indic; - theme.slider.knob = &slider_knob; + theme.style.slider.bg = theme.style.bar.bg; + theme.style.slider.indic = theme.style.bar.indic; + theme.style.slider.knob = &slider_knob; #endif } @@ -202,10 +202,10 @@ static void sw_init(void) #if USE_LV_SW != 0 - theme.sw.bg = theme.slider.bg; - theme.sw.indic = theme.slider.indic; - theme.sw.knob_off = theme.slider.knob; - theme.sw.knob_on = theme.slider.knob; + theme.style.sw.bg = theme.style.slider.bg; + theme.style.sw.indic = theme.style.slider.indic; + theme.style.sw.knob_off = theme.style.slider.knob; + theme.style.sw.knob_on = theme.style.slider.knob; #endif } @@ -223,7 +223,7 @@ static void lmeter_init(void) lmeter_bg.line.color = LV_COLOR_WHITE; lmeter_bg.line.width = 1; - theme.lmeter = &lmeter_bg; + theme.style.lmeter = &lmeter_bg; #endif } @@ -231,19 +231,19 @@ static void gauge_init(void) { #if USE_LV_GAUGE != 0 static lv_style_t gauge_bg; - lv_style_copy(&gauge_bg, theme.lmeter); + lv_style_copy(&gauge_bg, theme.style.lmeter); gauge_bg.line.color = LV_COLOR_BLACK; gauge_bg.line.width = 1; - theme.gauge = &gauge_bg; + theme.style.gauge = &gauge_bg; #endif } static void chart_init(void) { #if USE_LV_CHART - theme.chart = &light_frame; + theme.style.chart = &light_frame; #endif } @@ -255,8 +255,8 @@ static void calendar_init(void) box.body.padding.ver = LV_DPI / 20; /*Can't handle highlighted dates in this theme*/ - theme.calendar.week_box = &box; - theme.calendar.today_box = &box; + theme.style.calendar.week_box = &box; + theme.style.calendar.today_box = &box; #endif } @@ -265,12 +265,12 @@ static void cb_init(void) #if USE_LV_CB != 0 - theme.cb.bg = &lv_style_transp; - theme.cb.box.rel = &light_frame; - theme.cb.box.pr = &dark_frame; - theme.cb.box.tgl_rel = &dark_frame; - theme.cb.box.tgl_pr = &light_frame; - theme.cb.box.ina = &light_frame; + theme.style.cb.bg = &lv_style_transp; + theme.style.cb.box.rel = &light_frame; + theme.style.cb.box.pr = &dark_frame; + theme.style.cb.box.tgl_rel = &dark_frame; + theme.style.cb.box.tgl_pr = &light_frame; + theme.style.cb.box.ina = &light_frame; #endif } @@ -280,24 +280,24 @@ static void btnm_init(void) #if USE_LV_BTNM - theme.btnm.bg = &light_frame; - theme.btnm.btn.rel = &light_frame; - theme.btnm.btn.pr = &dark_frame; - theme.btnm.btn.tgl_rel = &dark_frame; - theme.btnm.btn.tgl_pr = &light_frame; - theme.btnm.btn.ina = &light_frame; + theme.style.btnm.bg = &light_frame; + theme.style.btnm.btn.rel = &light_frame; + theme.style.btnm.btn.pr = &dark_frame; + theme.style.btnm.btn.tgl_rel = &dark_frame; + theme.style.btnm.btn.tgl_pr = &light_frame; + theme.style.btnm.btn.ina = &light_frame; #endif } static void kb_init(void) { #if USE_LV_KB - theme.kb.bg = &lv_style_transp_fit; - theme.kb.btn.rel = &light_frame; - theme.kb.btn.pr = &light_frame; - theme.kb.btn.tgl_rel = &dark_frame; - theme.kb.btn.tgl_pr = &dark_frame; - theme.kb.btn.ina = &light_frame; + theme.style.kb.bg = &lv_style_transp_fit; + theme.style.kb.btn.rel = &light_frame; + theme.style.kb.btn.pr = &light_frame; + theme.style.kb.btn.tgl_rel = &dark_frame; + theme.style.kb.btn.tgl_pr = &dark_frame; + theme.style.kb.btn.ina = &light_frame; #endif } @@ -307,10 +307,10 @@ static void mbox_init(void) #if USE_LV_MBOX - theme.mbox.bg = &dark_frame; - theme.mbox.btn.bg = &lv_style_transp_fit; - theme.mbox.btn.rel = &light_frame; - theme.mbox.btn.pr = &dark_frame; + theme.style.mbox.bg = &dark_frame; + theme.style.mbox.btn.bg = &lv_style_transp_fit; + theme.style.mbox.btn.rel = &light_frame; + theme.style.mbox.btn.pr = &dark_frame; #endif } @@ -319,9 +319,9 @@ static void page_init(void) #if USE_LV_PAGE - theme.page.bg = &light_frame; - theme.page.scrl = &light_frame; - theme.page.sb = &dark_frame; + theme.style.page.bg = &light_frame; + theme.style.page.scrl = &light_frame; + theme.style.page.sb = &dark_frame; #endif } @@ -330,10 +330,10 @@ static void ta_init(void) #if USE_LV_TA - theme.ta.area = &light_frame; - theme.ta.oneline = &light_frame; - theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ - theme.ta.sb = &dark_frame; + theme.style.ta.area = &light_frame; + theme.style.ta.oneline = &light_frame; + theme.style.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ + theme.style.ta.sb = &dark_frame; #endif } @@ -342,14 +342,14 @@ static void list_init(void) #if USE_LV_LIST != 0 - theme.list.sb = &dark_frame; - theme.list.bg = &light_frame; - theme.list.scrl = &lv_style_transp_fit; - theme.list.btn.rel = &light_plain; - theme.list.btn.pr = &dark_plain; - theme.list.btn.tgl_rel = &dark_plain; - theme.list.btn.tgl_pr = &light_plain; - theme.list.btn.ina = &light_plain; + theme.style.list.sb = &dark_frame; + theme.style.list.bg = &light_frame; + theme.style.list.scrl = &lv_style_transp_fit; + theme.style.list.btn.rel = &light_plain; + theme.style.list.btn.pr = &dark_plain; + theme.style.list.btn.tgl_rel = &dark_plain; + theme.style.list.btn.tgl_pr = &light_plain; + theme.style.list.btn.ina = &light_plain; #endif } @@ -360,9 +360,9 @@ static void ddlist_init(void) lv_style_copy(&bg, &light_frame); bg.text.line_space = LV_DPI / 12; - theme.ddlist.bg = &bg; - theme.ddlist.sel = &dark_plain; - theme.ddlist.sb = &dark_frame; + theme.style.ddlist.bg = &bg; + theme.style.ddlist.sel = &dark_plain; + theme.style.ddlist.sb = &dark_frame; #endif } @@ -373,8 +373,8 @@ static void roller_init(void) lv_style_copy(&bg, &light_frame); bg.text.line_space = LV_DPI / 12; - theme.roller.bg = &bg; - theme.roller.sel = &dark_frame; + theme.style.roller.bg = &bg; + theme.style.roller.sel = &dark_frame; #endif } @@ -383,13 +383,13 @@ static void tabview_init(void) #if USE_LV_TABVIEW != 0 - theme.tabview.bg = &light_frame; - theme.tabview.indic = &light_plain; - theme.tabview.btn.bg = &lv_style_transp_fit; - theme.tabview.btn.rel = &light_frame; - theme.tabview.btn.pr = &dark_frame; - theme.tabview.btn.tgl_rel = &dark_frame; - theme.tabview.btn.tgl_pr = &light_frame; + theme.style.tabview.bg = &light_frame; + theme.style.tabview.indic = &light_plain; + theme.style.tabview.btn.bg = &lv_style_transp_fit; + theme.style.tabview.btn.rel = &light_frame; + theme.style.tabview.btn.pr = &dark_frame; + theme.style.tabview.btn.tgl_rel = &dark_frame; + theme.style.tabview.btn.tgl_pr = &light_frame; #endif } @@ -402,16 +402,52 @@ static void win_init(void) win_header.body.padding.hor = LV_DPI / 30; win_header.body.padding.ver = LV_DPI / 30; - theme.win.bg = &light_frame; - theme.win.sb = &dark_frame; - theme.win.header = &win_header; - theme.win.content.bg = &lv_style_transp; - theme.win.content.scrl = &lv_style_transp; - theme.win.btn.rel = &light_frame; - theme.win.btn.pr = &dark_frame; + theme.style.win.bg = &light_frame; + theme.style.win.sb = &dark_frame; + theme.style.win.header = &win_header; + theme.style.win.content.bg = &lv_style_transp; + theme.style.win.content.scrl = &lv_style_transp; + theme.style.win.btn.rel = &light_frame; + theme.style.win.btn.pr = &dark_frame; #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +static void style_mod_edit(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -435,8 +471,8 @@ lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -467,6 +503,11 @@ lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t * font) tabview_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod_edit; +#endif + return &theme; } diff --git a/lv_themes/lv_theme_nemo.c b/lv_themes/lv_theme_nemo.c index 0e6cb0a88..5550a5352 100644 --- a/lv_themes/lv_theme_nemo.c +++ b/lv_themes/lv_theme_nemo.c @@ -132,8 +132,8 @@ static void basic_init(void) sb.body.padding.ver = 1; sb.body.padding.inner = LV_DPI / 15; /*Scrollbar width*/ - theme.bg = &bg; - theme.panel = &panel; + theme.style.bg = &bg; + theme.style.panel = &panel; } @@ -188,11 +188,11 @@ static void btn_init(void) btn_ina.text.font = _font; btn_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 90); - theme.btn.rel = &btn_rel; - theme.btn.pr = &btn_pr; - theme.btn.tgl_rel = &btn_trel; - theme.btn.tgl_pr = &btn_tpr; - theme.btn.ina = &btn_ina; + theme.style.btn.rel = &btn_rel; + theme.style.btn.pr = &btn_pr; + theme.style.btn.tgl_rel = &btn_trel; + theme.style.btn.tgl_pr = &btn_tpr; + theme.style.btn.ina = &btn_ina; #endif } @@ -214,9 +214,9 @@ static void label_init(void) lv_style_copy(&label_hint, &label_prim); label_hint.text.color = lv_color_hsv_to_rgb(_hue, 20, 70); - theme.label.prim = &label_prim; - theme.label.sec = &label_sec; - theme.label.hint = &label_hint; + theme.style.label.prim = &label_prim; + theme.style.label.sec = &label_sec; + theme.style.label.hint = &label_hint; #endif } @@ -248,8 +248,8 @@ static void bar_init(void) bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 80); bar_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 80); - theme.bar.bg = &bar_bg; - theme.bar.indic = &bar_indic; + theme.style.bar.bg = &bar_bg; + theme.style.bar.indic = &bar_indic; #endif } @@ -265,8 +265,8 @@ static void img_init(void) img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 65); img_light.image.intense = LV_OPA_80; - theme.img.light = &img_light; - theme.img.dark = &img_dark; + theme.style.img.light = &img_light; + theme.style.img.dark = &img_dark; #endif } @@ -278,7 +278,7 @@ static void line_init(void) line_decor.line.color = lv_color_hsv_to_rgb(_hue, 50, 50); line_decor.line.width = 1; - theme.line.decor = &line_decor; + theme.style.line.decor = &line_decor; #endif } @@ -296,7 +296,7 @@ static void led_init(void) led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60); led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100); - theme.led = &led; + theme.style.led = &led; #endif } @@ -312,9 +312,9 @@ static void slider_init(void) slider_knob.body.border.color = LV_COLOR_ORANGE; slider_knob.body.border.opa = LV_OPA_50; - theme.slider.bg = &bar_bg; - theme.slider.indic = &bar_indic; - theme.slider.knob = &slider_knob; + theme.style.slider.bg = &bar_bg; + theme.style.slider.indic = &bar_indic; + theme.style.slider.knob = &slider_knob; #endif } @@ -339,10 +339,10 @@ static void sw_init(void) lv_style_copy(&sw_knob, &slider_knob); sw_knob.body.opa = LV_OPA_80; - theme.sw.bg = &sw_bg; - theme.sw.indic = &sw_indic; - theme.sw.knob_off = &sw_knob; - theme.sw.knob_on = &sw_knob; + theme.style.sw.bg = &sw_bg; + theme.style.sw.indic = &sw_indic; + theme.style.sw.knob_off = &sw_knob; + theme.style.sw.knob_on = &sw_knob; #endif } @@ -357,7 +357,7 @@ static void lmeter_init(void) lmeter_bg.line.color = LV_COLOR_HEX3(0x500); lmeter_bg.line.width = 2; - theme.lmeter = &lmeter_bg; + theme.style.lmeter = &lmeter_bg; #endif } @@ -378,7 +378,7 @@ static void gauge_init(void) gauge_bg.text.color = lv_color_hsv_to_rgb(_hue, 10, 90); gauge_bg.text.font = _font; - theme.gauge = &gauge_bg; + theme.style.gauge = &gauge_bg; #endif } @@ -395,7 +395,7 @@ static void arc_init(void) /*For preloader*/ arc.body.border.width = 0; - theme.arc = &arc; + theme.style.arc = &arc; #endif } @@ -403,14 +403,14 @@ static void preload_init(void) { #if USE_LV_PRELOAD != 0 - theme.preload = theme.arc; + theme.style.preload = theme.style.arc; #endif } static void chart_init(void) { #if USE_LV_CHART - theme.chart = &panel; + theme.style.chart = &panel; #endif } @@ -428,7 +428,7 @@ static void calendar_init(void) static lv_style_t week_box; lv_style_copy(&week_box, &def); week_box.body.empty = 1; - week_box.body.border.color = theme.panel->body.border.color; + week_box.body.border.color = theme.style.panel->body.border.color; week_box.body.padding.ver = LV_DPI / 20; static lv_style_t today_box; @@ -438,13 +438,13 @@ static void calendar_init(void) today_box.body.padding.ver = LV_DPI / 20; today_box.body.radius = 0; - theme.calendar.bg = theme.panel; - theme.calendar.header = theme.label.prim; - theme.calendar.inactive_days = theme.label.hint; - theme.calendar.highlighted_days = theme.label.sec; - theme.calendar.week_box = &week_box; - theme.calendar.today_box = &week_box; - theme.calendar.header_pr = theme.label.prim; + theme.style.calendar.bg = theme.style.panel; + theme.style.calendar.header = theme.style.label.prim; + theme.style.calendar.inactive_days = theme.style.label.hint; + theme.style.calendar.highlighted_days = theme.style.label.sec; + theme.style.calendar.week_box = &week_box; + theme.style.calendar.today_box = &week_box; + theme.style.calendar.header_pr = theme.style.label.prim; #endif } @@ -490,12 +490,12 @@ static void cb_init(void) cb_ina.body.main_color = LV_COLOR_PURPLE; cb_ina.body.grad_color = LV_COLOR_SILVER; - theme.cb.bg = &cb_bg; - theme.cb.box.rel = &cb_rel; - theme.cb.box.pr = &cb_pr; - theme.cb.box.tgl_rel = &cb_trel; - theme.cb.box.tgl_pr = &cb_tpr; - theme.cb.box.ina = &cb_ina; + theme.style.cb.bg = &cb_bg; + theme.style.cb.box.rel = &cb_rel; + theme.style.cb.box.pr = &cb_pr; + theme.style.cb.box.tgl_rel = &cb_trel; + theme.style.cb.box.tgl_pr = &cb_tpr; + theme.style.cb.box.ina = &cb_ina; #endif } @@ -529,24 +529,24 @@ static void btnm_init(void) lv_style_copy(&btnm_ina, &btnm_rel); btnm_ina.text.color = lv_color_hsv_to_rgb(_hue, 10, 60); - theme.btnm.bg = &btnm_bg; - theme.btnm.btn.rel = &btnm_rel; - theme.btnm.btn.pr = &btnm_pr; - theme.btnm.btn.tgl_rel = &btnm_trel; - theme.btnm.btn.tgl_pr = &btnm_pr; - theme.btnm.btn.ina = &btnm_ina; + theme.style.btnm.bg = &btnm_bg; + theme.style.btnm.btn.rel = &btnm_rel; + theme.style.btnm.btn.pr = &btnm_pr; + theme.style.btnm.btn.tgl_rel = &btnm_trel; + theme.style.btnm.btn.tgl_pr = &btnm_pr; + theme.style.btnm.btn.ina = &btnm_ina; #endif } static void kb_init(void) { #if USE_LV_KB - theme.kb.bg = &btnm_bg; - theme.kb.btn.rel = &btnm_rel; - theme.kb.btn.pr = &btnm_pr; - theme.kb.btn.tgl_rel = &btnm_trel; - theme.kb.btn.tgl_pr = &btnm_pr; - theme.kb.btn.ina = &btnm_ina; + theme.style.kb.bg = &btnm_bg; + theme.style.kb.btn.rel = &btnm_rel; + theme.style.kb.btn.pr = &btnm_pr; + theme.style.kb.btn.tgl_rel = &btnm_trel; + theme.style.kb.btn.tgl_pr = &btnm_pr; + theme.style.kb.btn.ina = &btnm_ina; #endif } @@ -558,38 +558,38 @@ static void mbox_init(void) lv_style_copy(&mbox_bg, &panel); mbox_bg.body.shadow.width = LV_DPI / 12; - theme.mbox.bg = &mbox_bg; - theme.mbox.btn.bg = &lv_style_transp; - theme.mbox.btn.rel = &btn_trel; - theme.mbox.btn.pr = &btn_tpr; + theme.style.mbox.bg = &mbox_bg; + theme.style.mbox.btn.bg = &lv_style_transp; + theme.style.mbox.btn.rel = &btn_trel; + theme.style.mbox.btn.pr = &btn_tpr; #endif } static void page_init(void) { #if USE_LV_PAGE - theme.page.bg = &panel; - theme.page.scrl = &lv_style_transp_fit; - theme.page.sb = &sb; + theme.style.page.bg = &panel; + theme.style.page.scrl = &lv_style_transp_fit; + theme.style.page.sb = &sb; #endif } static void ta_init(void) { #if USE_LV_TA - theme.ta.area = &panel; - theme.ta.oneline = &panel; - theme.ta.cursor = NULL; - theme.ta.sb = &sb; + theme.style.ta.area = &panel; + theme.style.ta.oneline = &panel; + theme.style.ta.cursor = NULL; + theme.style.ta.sb = &sb; #endif } static void spinbox_init(void) { #if USE_LV_SPINBOX - theme.spinbox.bg= &panel; - theme.spinbox.cursor = theme.ta.cursor; - theme.spinbox.sb = theme.ta.sb; + theme.style.spinbox.bg= &panel; + theme.style.spinbox.cursor = theme.style.ta.cursor; + theme.style.spinbox.sb = theme.style.ta.sb; #endif } @@ -620,14 +620,14 @@ static void list_init(void) list_bg.body.padding.hor = 0; list_bg.body.padding.ver = 0; - theme.list.sb = &sb; - theme.list.bg = &list_bg; - theme.list.scrl = &lv_style_transp_tight; - theme.list.btn.rel = &list_rel; - theme.list.btn.pr = &list_pr; - theme.list.btn.tgl_rel = &list_trel; - theme.list.btn.tgl_pr = &list_tpr; - theme.list.btn.ina = &list_ina; + theme.style.list.sb = &sb; + theme.style.list.bg = &list_bg; + theme.style.list.scrl = &lv_style_transp_tight; + theme.style.list.btn.rel = &list_rel; + theme.style.list.btn.pr = &list_pr; + theme.style.list.btn.tgl_rel = &list_trel; + theme.style.list.btn.tgl_pr = &list_tpr; + theme.style.list.btn.ina = &list_ina; #endif } @@ -645,9 +645,9 @@ static void ddlist_init(void) ddlist_sel.body.opa = LV_OPA_COVER; ddlist_sel.body.radius = 0; - theme.ddlist.bg = &ddlist_bg; - theme.ddlist.sel = &ddlist_sel; - theme.ddlist.sb = &sb; + theme.style.ddlist.bg = &ddlist_bg; + theme.style.ddlist.sel = &ddlist_sel; + theme.style.ddlist.sb = &sb; #endif } @@ -671,8 +671,8 @@ static void roller_init(void) roller_sel.text.opa = LV_OPA_COVER; roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 70, 95); - theme.roller.bg = &roller_bg; - theme.roller.sel = &roller_sel; + theme.style.roller.bg = &roller_bg; + theme.style.roller.sel = &roller_sel; #endif } @@ -725,22 +725,22 @@ static void tabview_init(void) tab_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 87); tab_indic.body.padding.inner = LV_DPI / 10; /*Indicator height*/ - theme.tabview.bg = &bg; - theme.tabview.indic = &tab_indic; - theme.tabview.btn.bg = &lv_style_transp_tight; - theme.tabview.btn.rel = &tab_rel; - theme.tabview.btn.pr = &tab_pr; - theme.tabview.btn.tgl_rel = &tab_trel; - theme.tabview.btn.tgl_pr = &tab_tpr; + theme.style.tabview.bg = &bg; + theme.style.tabview.indic = &tab_indic; + theme.style.tabview.btn.bg = &lv_style_transp_tight; + theme.style.tabview.btn.rel = &tab_rel; + theme.style.tabview.btn.pr = &tab_pr; + theme.style.tabview.btn.tgl_rel = &tab_trel; + theme.style.tabview.btn.tgl_pr = &tab_tpr; #endif } static void tileview_init(void) { #if USE_LV_TILEVIEW != 0 - theme.tileview.bg = &lv_style_transp_tight; - theme.tileview.scrl = &lv_style_transp_tight; - theme.tileview.sb = theme.page.sb; + theme.style.tileview.bg = &lv_style_transp_tight; + theme.style.tileview.scrl = &lv_style_transp_tight; + theme.style.tileview.sb = theme.style.page.sb; #endif } @@ -752,8 +752,8 @@ static void table_init(void) cell.body.radius = 0; cell.body.border.width = 1; - theme.table.bg = &lv_style_transp_tight; - theme.table.cell = &cell; + theme.style.table.bg = &lv_style_transp_tight; + theme.style.table.cell = &cell; #endif } @@ -771,16 +771,39 @@ static void win_init(void) win_header.body.border.color = lv_color_hsv_to_rgb(_hue, 20, 80); win_header.text.color = lv_color_hsv_to_rgb(_hue, 5, 100); - theme.win.bg = &bg; - theme.win.sb = &sb; - theme.win.header = &win_header; - theme.win.content.bg = &lv_style_transp; - theme.win.content.scrl = &lv_style_transp; - theme.win.btn.rel = &btn_rel; - theme.win.btn.pr = &btn_pr; + theme.style.win.bg = &bg; + theme.style.win.sb = &sb; + theme.style.win.header = &win_header; + theme.style.win.content.bg = &lv_style_transp; + theme.style.win.content.scrl = &lv_style_transp; + theme.style.win.btn.rel = &btn_rel; + theme.style.win.btn.pr = &btn_pr; #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + style->body.border.width = 2; + style->body.border.color = LV_COLOR_SILVER; + style->body.border.opa = LV_OPA_70; + style->body.padding.hor = 0; + style->body.padding.ver = 0; + style->body.shadow.width = LV_DPI / 20; + style->body.shadow.color = lv_color_hsv_to_rgb(_hue, 20, 90); + style->body.main_color = lv_color_hsv_to_rgb(_hue, 40, 80); + style->body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 80); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -800,8 +823,8 @@ lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -836,6 +859,11 @@ lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t * font) table_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod; +#endif + return &theme; } diff --git a/lv_themes/lv_theme_night.c b/lv_themes/lv_theme_night.c index ec78a4fe0..047c811a6 100644 --- a/lv_themes/lv_theme_night.c +++ b/lv_themes/lv_theme_night.c @@ -82,8 +82,8 @@ static void basic_init(void) panel.body.padding.hor = LV_DPI / 10; panel.line.color = lv_color_hsv_to_rgb(_hue, 20, 40); panel.line.width = 1; - theme.bg = &bg; - theme.panel = &def; + theme.style.bg = &bg; + theme.style.panel = &def; } static void cont_init(void) @@ -91,7 +91,7 @@ static void cont_init(void) #if USE_LV_CONT != 0 - theme.cont = &panel; + theme.style.cont = &panel; #endif } static void btn_init(void) @@ -137,11 +137,11 @@ static void btn_init(void) btn_ina.text.color = LV_COLOR_HEX3(0xaaa); btn_ina.image.color = LV_COLOR_HEX3(0xaaa); - theme.btn.rel = &btn_rel; - theme.btn.pr = &btn_pr; - theme.btn.tgl_rel = &btn_tgl_rel; - theme.btn.tgl_pr = &btn_tgl_pr; - theme.btn.ina = &btn_ina; + theme.style.btn.rel = &btn_rel; + theme.style.btn.pr = &btn_pr; + theme.style.btn.tgl_rel = &btn_tgl_rel; + theme.style.btn.tgl_pr = &btn_tgl_pr; + theme.style.btn.ina = &btn_ina; #endif } @@ -159,9 +159,9 @@ static void label_init(void) lv_style_copy(&hint, &bg); hint.text.color = lv_color_hsv_to_rgb(_hue, 20, 55); - theme.label.prim = &prim; - theme.label.sec = &sec; - theme.label.hint = &hint; + theme.style.label.prim = &prim; + theme.style.label.sec = &sec; + theme.style.label.hint = &hint; #endif } @@ -170,7 +170,7 @@ static void line_init(void) #if USE_LV_LINE != 0 - theme.line.decor = &def; + theme.style.line.decor = &def; #endif } @@ -188,7 +188,7 @@ static void led_init(void) led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60); led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100); - theme.led = &led; + theme.style.led = &led; #endif } @@ -197,8 +197,8 @@ static void img_init(void) #if USE_LV_IMG != 0 - theme.img.light = &def; - theme.img.dark = &def; + theme.style.img.light = &def; + theme.style.img.dark = &def; #endif } @@ -220,8 +220,8 @@ static void bar_init(void) bar_indic.body.padding.hor = 0; bar_indic.body.padding.ver = 0; - theme.bar.bg = &bar_bg; - theme.bar.indic = &bar_indic; + theme.style.bar.bg = &bar_bg; + theme.style.bar.indic = &bar_indic; #endif } @@ -232,9 +232,9 @@ static void slider_init(void) lv_style_copy(&slider_knob, &btn_rel); slider_knob.body.radius = LV_RADIUS_CIRCLE; - theme.slider.bg = &bar_bg; - theme.slider.indic = &bar_indic; - theme.slider.knob = &slider_knob; + theme.style.slider.bg = &bar_bg; + theme.style.slider.indic = &bar_indic; + theme.style.slider.knob = &slider_knob; #endif } @@ -243,10 +243,10 @@ static void sw_init(void) #if USE_LV_SW != 0 - theme.sw.bg = &bar_bg; - theme.sw.indic = &bar_indic; - theme.sw.knob_off = &slider_knob; - theme.sw.knob_on = &slider_knob; + theme.style.sw.bg = &bar_bg; + theme.style.sw.indic = &bar_indic; + theme.style.sw.knob_off = &slider_knob; + theme.style.sw.knob_on = &slider_knob; #endif } @@ -264,7 +264,7 @@ static void lmeter_init(void) lmeter_bg.line.width = 1; lmeter_bg.text.color = LV_COLOR_HEX3(0xddd); - theme.lmeter = &lmeter_bg; + theme.style.lmeter = &lmeter_bg; #endif } @@ -279,7 +279,7 @@ static void gauge_init(void) gauge_bg.line.width = 1; gauge_bg.text.color = LV_COLOR_HEX3(0xddd); - theme.gauge = &gauge_bg; + theme.style.gauge = &gauge_bg; #endif } @@ -299,7 +299,7 @@ static void arc_init(void) arc.body.padding.hor = 1; arc.body.padding.ver = 1; - theme.arc = &arc; + theme.style.arc = &arc; #endif } @@ -307,14 +307,14 @@ static void preload_init(void) { #if USE_LV_PRELOAD != 0 - theme.preload = theme.arc; + theme.style.preload = theme.style.arc; #endif } static void chart_init(void) { #if USE_LV_CHART - theme.chart = &panel; + theme.style.chart = &panel; #endif } @@ -366,13 +366,13 @@ static void calendar_init(void) lv_style_copy(&ina_days, &bg); ina_days.text.color = lv_color_hsv_to_rgb(_hue, 0, 60); - theme.calendar.bg = &cal_bg; - theme.calendar.header = &cal_header; - theme.calendar.week_box = &week_box; - theme.calendar.today_box = &today_box; - theme.calendar.highlighted_days = &highlighted_days; - theme.calendar.day_names = &cal_bg; - theme.calendar.inactive_days = &ina_days; + theme.style.calendar.bg = &cal_bg; + theme.style.calendar.header = &cal_header; + theme.style.calendar.week_box = &week_box; + theme.style.calendar.today_box = &today_box; + theme.style.calendar.highlighted_days = &highlighted_days; + theme.style.calendar.day_names = &cal_bg; + theme.style.calendar.inactive_days = &ina_days; #endif } @@ -412,12 +412,12 @@ static void cb_init(void) ina.body.grad_color = LV_COLOR_HEX3(0x777); ina.body.border.width = 0; - theme.cb.bg = &lv_style_transp; - theme.cb.box.rel = &rel; - theme.cb.box.pr = ≺ - theme.cb.box.tgl_rel = &tgl_rel; - theme.cb.box.tgl_pr = &tgl_pr; - theme.cb.box.ina = &def; + theme.style.cb.bg = &lv_style_transp; + theme.style.cb.box.rel = &rel; + theme.style.cb.box.pr = ≺ + theme.style.cb.box.tgl_rel = &tgl_rel; + theme.style.cb.box.tgl_pr = &tgl_pr; + theme.style.cb.box.ina = &def; #endif } @@ -458,24 +458,24 @@ static void btnm_init(void) ina.body.border.width = rel.body.border.width; ina.body.radius = rel.body.radius; - theme.btnm.bg = &btnm_bg; - theme.btnm.btn.rel = &rel; - theme.btnm.btn.pr = ≺ - theme.btnm.btn.tgl_rel = &tgl_rel; - theme.btnm.btn.tgl_pr = &tgl_pr; - theme.btnm.btn.ina = &ina; + theme.style.btnm.bg = &btnm_bg; + theme.style.btnm.btn.rel = &rel; + theme.style.btnm.btn.pr = ≺ + theme.style.btnm.btn.tgl_rel = &tgl_rel; + theme.style.btnm.btn.tgl_pr = &tgl_pr; + theme.style.btnm.btn.ina = &ina; #endif } static void kb_init(void) { #if USE_LV_KB - theme.kb.bg = &bg; - theme.kb.btn.rel = &btn_rel; - theme.kb.btn.pr = &btn_pr; - theme.kb.btn.tgl_rel = &btn_tgl_rel; - theme.kb.btn.tgl_pr = &btn_tgl_pr; - theme.kb.btn.ina = &btn_ina; + theme.style.kb.bg = &bg; + theme.style.kb.btn.rel = &btn_rel; + theme.style.kb.btn.pr = &btn_pr; + theme.style.kb.btn.tgl_rel = &btn_tgl_rel; + theme.style.kb.btn.tgl_pr = &btn_tgl_pr; + theme.style.kb.btn.ina = &btn_ina; #endif } @@ -492,10 +492,10 @@ static void mbox_init(void) mbox_bg.body.shadow.width = LV_DPI / 10; mbox_bg.body.shadow.color = LV_COLOR_HEX3(0x222); mbox_bg.body.radius = LV_DPI / 20; - theme.mbox.bg = &mbox_bg; - theme.mbox.btn.bg = &lv_style_transp; - theme.mbox.btn.rel = &btn_rel; - theme.mbox.btn.pr = &btn_pr; + theme.style.mbox.bg = &mbox_bg; + theme.style.mbox.btn.bg = &lv_style_transp; + theme.style.mbox.btn.rel = &btn_rel; + theme.style.mbox.btn.pr = &btn_pr; #endif } @@ -511,28 +511,28 @@ static void page_init(void) page_scrl.body.border.width = 1; page_scrl.body.radius = LV_DPI / 20; - theme.page.bg = &panel; - theme.page.scrl = &page_scrl; - theme.page.sb = &sb; + theme.style.page.bg = &panel; + theme.style.page.scrl = &page_scrl; + theme.style.page.sb = &sb; #endif } static void ta_init(void) { #if USE_LV_TA - theme.ta.area = &panel; - theme.ta.oneline = &panel; - theme.ta.cursor = NULL; - theme.ta.sb = &def; + theme.style.ta.area = &panel; + theme.style.ta.oneline = &panel; + theme.style.ta.cursor = NULL; + theme.style.ta.sb = &def; #endif } static void spinbox_init(void) { #if USE_LV_SPINBOX - theme.spinbox.bg= &panel; - theme.spinbox.cursor = theme.ta.cursor; - theme.spinbox.sb = theme.ta.sb; + theme.style.spinbox.bg= &panel; + theme.style.spinbox.cursor = theme.style.ta.cursor; + theme.style.spinbox.sb = theme.style.ta.sb; #endif } @@ -576,14 +576,14 @@ static void list_init(void) list_btn_tgl_pr.body.main_color = btn_tgl_pr.body.main_color; list_btn_tgl_pr.body.grad_color = btn_tgl_pr.body.grad_color; - theme.list.sb = &sb; - theme.list.bg = &list_bg; - theme.list.scrl = &lv_style_transp_tight; - theme.list.btn.rel = &list_btn_rel; - theme.list.btn.pr = &list_btn_pr; - theme.list.btn.tgl_rel = &list_btn_tgl_rel; - theme.list.btn.tgl_pr = &list_btn_tgl_pr; - theme.list.btn.ina = &def; + theme.style.list.sb = &sb; + theme.style.list.bg = &list_bg; + theme.style.list.scrl = &lv_style_transp_tight; + theme.style.list.btn.rel = &list_btn_rel; + theme.style.list.btn.pr = &list_btn_pr; + theme.style.list.btn.tgl_rel = &list_btn_tgl_rel; + theme.style.list.btn.tgl_pr = &list_btn_tgl_pr; + theme.style.list.btn.ina = &def; #endif } @@ -601,9 +601,9 @@ static void ddlist_init(void) ddlist_sel.body.grad_color = lv_color_hsv_to_rgb(_hue, 20, 50); ddlist_sel.body.radius = 0; - theme.ddlist.bg = &ddlist_bg; - theme.ddlist.sel = &ddlist_sel; - theme.ddlist.sb = &def; + theme.style.ddlist.bg = &ddlist_bg; + theme.style.ddlist.sel = &ddlist_sel; + theme.style.ddlist.sb = &def; #endif } @@ -618,30 +618,30 @@ static void roller_init(void) roller_bg.text.color = lv_color_hsv_to_rgb(_hue, 5, 70); roller_bg.text.opa = LV_OPA_60; - theme.roller.bg = &roller_bg; - theme.roller.sel = &ddlist_sel; + theme.style.roller.bg = &roller_bg; + theme.style.roller.sel = &ddlist_sel; #endif } static void tabview_init(void) { #if USE_LV_TABVIEW != 0 - theme.tabview.bg = &bg; - theme.tabview.indic = &lv_style_transp; - theme.tabview.btn.bg = &lv_style_transp; - theme.tabview.btn.rel = &btn_rel; - theme.tabview.btn.pr = &btn_pr; - theme.tabview.btn.tgl_rel = &btn_tgl_rel; - theme.tabview.btn.tgl_pr = &btn_tgl_pr; + theme.style.tabview.bg = &bg; + theme.style.tabview.indic = &lv_style_transp; + theme.style.tabview.btn.bg = &lv_style_transp; + theme.style.tabview.btn.rel = &btn_rel; + theme.style.tabview.btn.pr = &btn_pr; + theme.style.tabview.btn.tgl_rel = &btn_tgl_rel; + theme.style.tabview.btn.tgl_pr = &btn_tgl_pr; #endif } static void tileview_init(void) { #if USE_LV_TILEVIEW != 0 - theme.tileview.bg = &lv_style_transp_tight; - theme.tileview.scrl = &lv_style_transp_tight; - theme.tileview.sb = theme.page.sb; + theme.style.tileview.bg = &lv_style_transp_tight; + theme.style.tileview.scrl = &lv_style_transp_tight; + theme.style.tileview.sb = theme.style.page.sb; #endif } @@ -656,8 +656,8 @@ static void table_init(void) cell.body.padding.ver = LV_DPI / 12; - theme.table.bg = &lv_style_transp_tight; - theme.table.cell = &cell; + theme.style.table.bg = &lv_style_transp_tight; + theme.style.table.cell = &cell; #endif } @@ -685,16 +685,52 @@ static void win_init(void) win_btn_pr.text.color = LV_COLOR_HEX3(0xaaa); win_btn_pr.image.color = LV_COLOR_HEX3(0xaaa); - theme.win.bg = &win_bg; - theme.win.sb = &sb; - theme.win.header = &win_header; - theme.win.content.bg = &lv_style_transp; - theme.win.content.scrl = &lv_style_transp; - theme.win.btn.rel = &lv_style_transp; - theme.win.btn.pr = &win_btn_pr; + theme.style.win.bg = &win_bg; + theme.style.win.sb = &sb; + theme.style.win.header = &win_header; + theme.style.win.content.bg = &lv_style_transp; + theme.style.win.content.scrl = &lv_style_transp; + theme.style.win.btn.rel = &lv_style_transp; + theme.style.win.btn.pr = &win_btn_pr; #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = lv_color_hsv_to_rgb(_hue, 80, 70); + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +static void style_mod_edit(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_GREEN; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -716,8 +752,8 @@ lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -753,6 +789,11 @@ lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t * font) table_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod_edit; +#endif + return &theme; } diff --git a/lv_themes/lv_theme_templ.c b/lv_themes/lv_theme_templ.c index b9359d4bc..46f3793b7 100644 --- a/lv_themes/lv_theme_templ.c +++ b/lv_themes/lv_theme_templ.c @@ -47,8 +47,8 @@ static void basic_init(void) lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/ def.text.font = _font; - theme.bg = &def; - theme.panel = &def; + theme.style.bg = &def; + theme.style.panel = &def; } @@ -57,7 +57,7 @@ static void cont_init(void) #if USE_LV_CONT != 0 - theme.cont = &def; + theme.style.cont = &def; #endif } @@ -66,22 +66,22 @@ static void btn_init(void) #if USE_LV_BTN != 0 - theme.btn.rel = &def; - theme.btn.pr = &def; - theme.btn.tgl_rel = &def; - theme.btn.tgl_pr = &def; - theme.btn.ina = &def; + theme.style.btn.rel = &def; + theme.style.btn.pr = &def; + theme.style.btn.tgl_rel = &def; + theme.style.btn.tgl_pr = &def; + theme.style.btn.ina = &def; #endif } static void imgbtn_init(void) { #if USE_LV_IMGBTN != 0 - theme.imgbtn.rel = &def; - theme.imgbtn.pr = &def; - theme.imgbtn.tgl_rel = &def; - theme.imgbtn.tgl_pr = &def; - theme.imgbtn.ina = &def; + theme.style.imgbtn.rel = &def; + theme.style.imgbtn.pr = &def; + theme.style.imgbtn.tgl_rel = &def; + theme.style.imgbtn.tgl_pr = &def; + theme.style.imgbtn.ina = &def; #endif } @@ -90,9 +90,9 @@ static void label_init(void) #if USE_LV_LABEL != 0 - theme.label.prim = &def; - theme.label.sec = &def; - theme.label.hint = &def; + theme.style.label.prim = &def; + theme.style.label.sec = &def; + theme.style.label.hint = &def; #endif } @@ -101,8 +101,8 @@ static void img_init(void) #if USE_LV_IMG != 0 - theme.img.light = &def; - theme.img.dark = &def; + theme.style.img.light = &def; + theme.style.img.dark = &def; #endif } @@ -111,7 +111,7 @@ static void line_init(void) #if USE_LV_LINE != 0 - theme.line.decor = &def; + theme.style.line.decor = &def; #endif } @@ -120,7 +120,7 @@ static void led_init(void) #if USE_LV_LED != 0 - theme.led = &def; + theme.style.led = &def; #endif } @@ -129,8 +129,8 @@ static void bar_init(void) #if USE_LV_BAR - theme.bar.bg = &def; - theme.bar.indic = &def; + theme.style.bar.bg = &def; + theme.style.bar.indic = &def; #endif } @@ -139,9 +139,9 @@ static void slider_init(void) #if USE_LV_SLIDER != 0 - theme.slider.bg = &def; - theme.slider.indic = &def; - theme.slider.knob = &def; + theme.style.slider.bg = &def; + theme.style.slider.indic = &def; + theme.style.slider.knob = &def; #endif } @@ -150,10 +150,10 @@ static void sw_init(void) #if USE_LV_SW != 0 - theme.sw.bg = &def; - theme.sw.indic = &def; - theme.sw.knob_off = &def; - theme.sw.knob_on = &def; + theme.style.sw.bg = &def; + theme.style.sw.indic = &def; + theme.style.sw.knob_off = &def; + theme.style.sw.knob_on = &def; #endif } @@ -163,7 +163,7 @@ static void lmeter_init(void) #if USE_LV_LMETER != 0 - theme.lmeter = &def; + theme.style.lmeter = &def; #endif } @@ -172,7 +172,7 @@ static void gauge_init(void) #if USE_LV_GAUGE != 0 - theme.gauge = &def; + theme.style.gauge = &def; #endif } @@ -181,7 +181,7 @@ static void arc_init(void) #if USE_LV_ARC != 0 - theme.arc = &def; + theme.style.arc = &def; #endif } @@ -190,7 +190,7 @@ static void preload_init(void) #if USE_LV_PRELOAD != 0 - theme.preload = &def; + theme.style.preload = &def; #endif } @@ -198,7 +198,7 @@ static void chart_init(void) { #if USE_LV_CHART - theme.chart = &def; + theme.style.chart = &def; #endif } @@ -206,14 +206,14 @@ static void calendar_init(void) { #if USE_LV_CALENDAR - theme.calendar.bg = theme.panel; - theme.calendar.header = &def; - theme.calendar.inactive_days = &def; - theme.calendar.highlighted_days = &def; - theme.calendar.week_box = &def; - theme.calendar.today_box = &def; - theme.calendar.header_pr = &def; - theme.calendar.day_names = &def; + theme.style.calendar.bg = theme.style.panel; + theme.style.calendar.header = &def; + theme.style.calendar.inactive_days = &def; + theme.style.calendar.highlighted_days = &def; + theme.style.calendar.week_box = &def; + theme.style.calendar.today_box = &def; + theme.style.calendar.header_pr = &def; + theme.style.calendar.day_names = &def; #endif } @@ -222,12 +222,12 @@ static void cb_init(void) #if USE_LV_CB != 0 - theme.cb.bg = &def; - theme.cb.box.rel = &def; - theme.cb.box.pr = &def; - theme.cb.box.tgl_rel = &def; - theme.cb.box.tgl_pr = &def; - theme.cb.box.ina = &def; + theme.style.cb.bg = &def; + theme.style.cb.box.rel = &def; + theme.style.cb.box.pr = &def; + theme.style.cb.box.tgl_rel = &def; + theme.style.cb.box.tgl_pr = &def; + theme.style.cb.box.ina = &def; #endif } @@ -237,12 +237,12 @@ static void btnm_init(void) #if USE_LV_BTNM - theme.btnm.bg = &def; - theme.btnm.btn.rel = &def; - theme.btnm.btn.pr = &def; - theme.btnm.btn.tgl_rel = &def; - theme.btnm.btn.tgl_pr = &def; - theme.btnm.btn.ina = &def; + theme.style.btnm.bg = &def; + theme.style.btnm.btn.rel = &def; + theme.style.btnm.btn.pr = &def; + theme.style.btnm.btn.tgl_rel = &def; + theme.style.btnm.btn.tgl_pr = &def; + theme.style.btnm.btn.ina = &def; #endif } @@ -251,12 +251,12 @@ static void kb_init(void) #if USE_LV_KB - theme.kb.bg = &def; - theme.kb.btn.rel = &def; - theme.kb.btn.pr = &def; - theme.kb.btn.tgl_rel = &def; - theme.kb.btn.tgl_pr = &def; - theme.kb.btn.ina = &def; + theme.style.kb.bg = &def; + theme.style.kb.btn.rel = &def; + theme.style.kb.btn.pr = &def; + theme.style.kb.btn.tgl_rel = &def; + theme.style.kb.btn.tgl_pr = &def; + theme.style.kb.btn.ina = &def; #endif } @@ -266,10 +266,10 @@ static void mbox_init(void) #if USE_LV_MBOX - theme.mbox.bg = &def; - theme.mbox.btn.bg = &def; - theme.mbox.btn.rel = &def; - theme.mbox.btn.pr = &def; + theme.style.mbox.bg = &def; + theme.style.mbox.btn.bg = &def; + theme.style.mbox.btn.rel = &def; + theme.style.mbox.btn.pr = &def; #endif } @@ -278,9 +278,9 @@ static void page_init(void) #if USE_LV_PAGE - theme.page.bg = &def; - theme.page.scrl = &def; - theme.page.sb = &def; + theme.style.page.bg = &def; + theme.style.page.scrl = &def; + theme.style.page.sb = &def; #endif } @@ -289,10 +289,10 @@ static void ta_init(void) #if USE_LV_TA - theme.ta.area = &def; - theme.ta.oneline = &def; - theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ - theme.ta.sb = &def; + theme.style.ta.area = &def; + theme.style.ta.oneline = &def; + theme.style.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ + theme.style.ta.sb = &def; #endif } @@ -301,14 +301,14 @@ static void list_init(void) #if USE_LV_LIST != 0 - theme.list.sb = &def; - theme.list.bg = &def; - theme.list.scrl = &def; - theme.list.btn.rel = &def; - theme.list.btn.pr = &def; - theme.list.btn.tgl_rel = &def; - theme.list.btn.tgl_pr = &def; - theme.list.btn.ina = &def; + theme.style.list.sb = &def; + theme.style.list.bg = &def; + theme.style.list.scrl = &def; + theme.style.list.btn.rel = &def; + theme.style.list.btn.pr = &def; + theme.style.list.btn.tgl_rel = &def; + theme.style.list.btn.tgl_pr = &def; + theme.style.list.btn.ina = &def; #endif } @@ -317,9 +317,9 @@ static void ddlist_init(void) #if USE_LV_DDLIST != 0 - theme.ddlist.bg = &def; - theme.ddlist.sel = &def; - theme.ddlist.sb = &def; + theme.style.ddlist.bg = &def; + theme.style.ddlist.sel = &def; + theme.style.ddlist.sb = &def; #endif } @@ -328,8 +328,8 @@ static void roller_init(void) #if USE_LV_ROLLER != 0 - theme.roller.bg = &def; - theme.roller.sel = &def; + theme.style.roller.bg = &def; + theme.style.roller.sel = &def; #endif } @@ -338,13 +338,13 @@ static void tabview_init(void) #if USE_LV_TABVIEW != 0 - theme.tabview.bg = &def; - theme.tabview.indic = &def; - theme.tabview.btn.bg = &def; - theme.tabview.btn.rel = &def; - theme.tabview.btn.pr = &def; - theme.tabview.btn.tgl_rel = &def; - theme.tabview.btn.tgl_pr = &def; + theme.style.tabview.bg = &def; + theme.style.tabview.indic = &def; + theme.style.tabview.btn.bg = &def; + theme.style.tabview.btn.rel = &def; + theme.style.tabview.btn.pr = &def; + theme.style.tabview.btn.tgl_rel = &def; + theme.style.tabview.btn.tgl_pr = &def; #endif } @@ -354,16 +354,64 @@ static void win_init(void) #if USE_LV_WIN != 0 - theme.win.bg = &def; - theme.win.sb = &def; - theme.win.header = &def; - theme.win.content.bg = &def; - theme.win.content.scrl = &def; - theme.win.btn.rel = &def; - theme.win.btn.pr = &def; + theme.style.win.bg = &def; + theme.style.win.sb = &def; + theme.style.win.header = &def; + theme.style.win.content.bg = &def; + theme.style.win.content.scrl = &def; + theme.style.win.btn.rel = &def; + theme.style.win.btn.pr = &def; #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_ORANGE; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_ORANGE, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_ORANGE, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +static void style_mod_edit(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_GREEN; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -385,8 +433,8 @@ lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -419,6 +467,11 @@ lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t * font) tabview_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod_edit; +#endif + return &theme; } diff --git a/lv_themes/lv_theme_zen.c b/lv_themes/lv_theme_zen.c index 4c87e9073..c55e8c8de 100644 --- a/lv_themes/lv_theme_zen.c +++ b/lv_themes/lv_theme_zen.c @@ -79,8 +79,8 @@ static void basic_init(void) sb.body.radius = LV_RADIUS_CIRCLE; sb.body.padding.inner = LV_DPI / 10; - theme.bg = &bg; - theme.panel = &panel; + theme.style.bg = &bg; + theme.style.panel = &panel; } static void cont_init(void) @@ -88,7 +88,7 @@ static void cont_init(void) #if USE_LV_CONT != 0 - theme.cont = theme.panel; + theme.style.cont = theme.style.panel; #endif } @@ -125,11 +125,11 @@ static void btn_init(void) ina.text.color = LV_COLOR_HEX3(0xbbb); ina.image.color = LV_COLOR_HEX3(0xbbb); - theme.btn.rel = &rel; - theme.btn.pr = ≺ - theme.btn.tgl_rel = ≺ - theme.btn.tgl_pr = &tgl_pr; - theme.btn.ina = &ina; + theme.style.btn.rel = &rel; + theme.style.btn.pr = ≺ + theme.style.btn.tgl_rel = ≺ + theme.style.btn.tgl_pr = &tgl_pr; + theme.style.btn.ina = &ina; #endif } @@ -145,9 +145,9 @@ static void label_init(void) sec.text.color = lv_color_hsv_to_rgb(_hue, 50, 80); hint.text.color = lv_color_hsv_to_rgb(_hue, 25, 85); - theme.label.prim = &prim; - theme.label.sec = &sec; - theme.label.hint = &hint; + theme.style.label.prim = &prim; + theme.style.label.sec = &sec; + theme.style.label.hint = &hint; #endif } @@ -163,8 +163,8 @@ static void img_init(void) img_light.image.color = lv_color_hsv_to_rgb(_hue, 85, 55); img_light.image.intense = LV_OPA_80; - theme.img.light = &img_light; - theme.img.dark = &img_dark; + theme.style.img.light = &img_light; + theme.style.img.dark = &img_dark; #endif } @@ -173,7 +173,7 @@ static void line_init(void) #if USE_LV_LINE != 0 - theme.line.decor = &def; + theme.style.line.decor = &def; #endif } @@ -192,7 +192,7 @@ static void led_init(void) led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60); led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 80, 100); - theme.led = &led; + theme.style.led = &led; #endif } @@ -217,8 +217,8 @@ static void bar_init(void) indic.body.padding.ver = LV_DPI / 20; - theme.bar.bg = &bg; - theme.bar.indic = &indic; + theme.style.bar.bg = &bg; + theme.style.bar.indic = &indic; #endif } @@ -228,14 +228,14 @@ static void slider_init(void) static lv_style_t knob; lv_style_copy(&knob, &def); - knob.body.main_color = theme.bar.indic->body.main_color; + knob.body.main_color = theme.style.bar.indic->body.main_color; knob.body.grad_color = knob.body.main_color; knob.body.radius = LV_RADIUS_CIRCLE; knob.body.border.width = 0; - theme.slider.bg = theme.bar.bg; - theme.slider.indic = theme.bar.indic; - theme.slider.knob = &knob; + theme.style.slider.bg = theme.style.bar.bg; + theme.style.slider.indic = theme.style.bar.indic; + theme.style.slider.knob = &knob; #endif } @@ -244,22 +244,22 @@ static void sw_init(void) #if USE_LV_SW != 0 static lv_style_t indic; - lv_style_copy(&indic, theme.slider.indic); + lv_style_copy(&indic, theme.style.slider.indic); indic.body.radius = LV_RADIUS_CIRCLE; indic.body.main_color = lv_color_hsv_to_rgb(_hue, 15, 95); indic.body.grad_color = indic.body.main_color; - indic.body.border.width = theme.slider.bg->body.border.width; - indic.body.border.color = theme.slider.bg->body.border.color; - indic.body.border.opa = theme.slider.bg->body.border.opa; + indic.body.border.width = theme.style.slider.bg->body.border.width; + indic.body.border.color = theme.style.slider.bg->body.border.color; + indic.body.border.opa = theme.style.slider.bg->body.border.opa; indic.body.padding.hor = 0; indic.body.padding.ver = 0; - theme.sw.bg = theme.slider.bg; - theme.sw.indic = &indic; - theme.sw.knob_off = theme.slider.knob; - theme.sw.knob_on = theme.slider.knob; + theme.style.sw.bg = theme.style.slider.bg; + theme.style.sw.indic = &indic; + theme.style.sw.knob_off = theme.style.slider.knob; + theme.style.sw.knob_on = theme.style.slider.knob; #endif } @@ -276,7 +276,7 @@ static void lmeter_init(void) lmeter.body.grad_color = lmeter.body.main_color; lmeter.body.padding.hor = LV_DPI / 8; - theme.lmeter = &lmeter; + theme.style.lmeter = &lmeter; #endif } @@ -293,7 +293,7 @@ static void gauge_init(void) gauge.body.padding.hor = LV_DPI / 16; gauge.body.border.color = LV_COLOR_HEX3(0x666); /*Needle middle color*/ - theme.gauge = &gauge; + theme.style.gauge = &gauge; #endif } @@ -310,7 +310,7 @@ static void arc_init(void) /*For preloader*/ arc.body.border.width = 0; - theme.arc = &arc; + theme.style.arc = &arc; #endif } @@ -318,14 +318,14 @@ static void preload_init(void) { #if USE_LV_PRELOAD != 0 - theme.preload = theme.arc; + theme.style.preload = theme.style.arc; #endif } static void chart_init(void) { #if USE_LV_CHART - theme.chart = theme.panel; + theme.style.chart = theme.style.panel; #endif } @@ -343,16 +343,16 @@ static void calendar_init(void) static lv_style_t today_box; lv_style_copy(&today_box, &def); today_box.body.empty = 1; - today_box.body.border.color = theme.panel->body.border.color; + today_box.body.border.color = theme.style.panel->body.border.color; today_box.body.padding.ver = LV_DPI / 20; today_box.body.radius = LV_RADIUS_CIRCLE; - theme.calendar.bg = theme.panel; - theme.calendar.header = &lv_style_transp; - theme.calendar.inactive_days = &ina_days; - theme.calendar.highlighted_days = &high_days; - theme.calendar.week_box = &lv_style_transp_fit; - theme.calendar.today_box = &today_box; + theme.style.calendar.bg = theme.style.panel; + theme.style.calendar.header = &lv_style_transp; + theme.style.calendar.inactive_days = &ina_days; + theme.style.calendar.highlighted_days = &high_days; + theme.style.calendar.week_box = &lv_style_transp_fit; + theme.style.calendar.today_box = &today_box; #endif } @@ -389,12 +389,12 @@ static void cb_init(void) ina.body.border.color = LV_COLOR_HEX3(0xaaa); - theme.cb.bg = &lv_style_transp; - theme.cb.box.rel = &rel; - theme.cb.box.pr = ≺ - theme.cb.box.tgl_rel = &tgl_rel; - theme.cb.box.tgl_pr = &tgl_pr; - theme.cb.box.ina = &ina; + theme.style.cb.bg = &lv_style_transp; + theme.style.cb.box.rel = &rel; + theme.style.cb.box.pr = ≺ + theme.style.cb.box.tgl_rel = &tgl_rel; + theme.style.cb.box.tgl_pr = &tgl_pr; + theme.style.cb.box.ina = &ina; #endif } @@ -439,12 +439,12 @@ static void btnm_init(void) ina.body.grad_color = tgl_pr.body.main_color; ina.text.color = LV_COLOR_HEX3(0x888);; - theme.btnm.bg = &bg; - theme.btnm.btn.rel = &rel; - theme.btnm.btn.pr = ≺ - theme.btnm.btn.tgl_rel = &tgl_rel; - theme.btnm.btn.tgl_pr = &tgl_pr; - theme.btnm.btn.ina = &ina; + theme.style.btnm.bg = &bg; + theme.style.btnm.btn.rel = &rel; + theme.style.btnm.btn.pr = ≺ + theme.style.btnm.btn.tgl_rel = &tgl_rel; + theme.style.btnm.btn.tgl_pr = &tgl_pr; + theme.style.btnm.btn.ina = &ina; #endif } @@ -494,12 +494,12 @@ static void kb_init(void) ina.body.grad_color = ina.body.main_color; ina.text.color = LV_COLOR_HEX3(0xbbb); - theme.kb.bg = &bg; - theme.kb.btn.rel = &rel; - theme.kb.btn.pr = ≺ - theme.kb.btn.tgl_rel = &tgl_rel; - theme.kb.btn.tgl_pr = &tgl_pr; - theme.kb.btn.ina = &ina; + theme.style.kb.bg = &bg; + theme.style.kb.btn.rel = &rel; + theme.style.kb.btn.pr = ≺ + theme.style.kb.btn.tgl_rel = &tgl_rel; + theme.style.kb.btn.tgl_pr = &tgl_pr; + theme.style.kb.btn.ina = &ina; #endif } @@ -508,7 +508,7 @@ static void mbox_init(void) { #if USE_LV_MBOX static lv_style_t bg, rel, pr; - lv_style_copy(&bg, theme.panel); + lv_style_copy(&bg, theme.style.panel); bg.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 95); bg.body.grad_color = bg.body.main_color; bg.text.color = lv_color_hsv_to_rgb(_hue, 40, 25); @@ -530,10 +530,10 @@ static void mbox_init(void) pr.body.grad_color = pr.body.main_color; - theme.mbox.bg = &bg; - theme.mbox.btn.bg = &lv_style_transp; - theme.mbox.btn.rel = &rel; - theme.mbox.btn.pr = ≺ + theme.style.mbox.bg = &bg; + theme.style.mbox.btn.bg = &lv_style_transp; + theme.style.mbox.btn.rel = &rel; + theme.style.mbox.btn.pr = ≺ #endif } @@ -542,9 +542,9 @@ static void page_init(void) #if USE_LV_PAGE - theme.page.bg = theme.panel; - theme.page.scrl = &lv_style_transp; - theme.page.sb = &sb; + theme.style.page.bg = theme.style.panel; + theme.style.page.scrl = &lv_style_transp; + theme.style.page.sb = &sb; #endif } @@ -552,25 +552,25 @@ static void ta_init(void) { #if USE_LV_TA static lv_style_t oneline; - lv_style_copy(&oneline, theme.panel); + lv_style_copy(&oneline, theme.style.panel); oneline.body.radius = LV_RADIUS_CIRCLE; oneline.body.padding.ver = LV_DPI / 10; oneline.body.shadow.width = 0; - theme.ta.area = theme.panel; - theme.ta.oneline = &oneline; - theme.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ - theme.ta.sb = &def; + theme.style.ta.area = theme.style.panel; + theme.style.ta.oneline = &oneline; + theme.style.ta.cursor = NULL; /*Let library to calculate the cursor's style*/ + theme.style.ta.sb = &def; #endif } static void spinbox_init(void) { #if USE_LV_SPINBOX - theme.spinbox.bg= theme.panel; - theme.spinbox.cursor = theme.ta.cursor; - theme.spinbox.sb = theme.ta.sb; + theme.style.spinbox.bg= theme.style.panel; + theme.style.spinbox.cursor = theme.style.ta.cursor; + theme.style.spinbox.sb = theme.style.ta.sb; #endif } @@ -579,7 +579,7 @@ static void list_init(void) #if USE_LV_LIST != 0 static lv_style_t bg, rel, pr, tgl_rel, tgl_pr, ina; - lv_style_copy(&bg, theme.panel); + lv_style_copy(&bg, theme.style.panel); bg.body.padding.hor = 0; bg.body.padding.ver = 0; @@ -592,28 +592,28 @@ static void list_init(void) rel.image.color = LV_COLOR_HEX3(0x666); lv_style_copy(&pr, &rel); - pr.text.color = theme.btn.pr->text.color; - pr.image.color = theme.btn.pr->image.color; + pr.text.color = theme.style.btn.pr->text.color; + pr.image.color = theme.style.btn.pr->image.color; lv_style_copy(&tgl_rel, &rel); tgl_rel.text.color = lv_color_hsv_to_rgb(_hue, 50, 90); lv_style_copy(&tgl_pr, &rel); - tgl_pr.text.color = theme.btn.tgl_pr->text.color; - tgl_pr.image.color = theme.btn.tgl_pr->image.color; + tgl_pr.text.color = theme.style.btn.tgl_pr->text.color; + tgl_pr.image.color = theme.style.btn.tgl_pr->image.color; lv_style_copy(&ina, &rel); - ina.text.color = theme.btn.ina->text.color; - ina.image.color = theme.btn.ina->image.color; + ina.text.color = theme.style.btn.ina->text.color; + ina.image.color = theme.style.btn.ina->image.color; - theme.list.sb = &sb; - theme.list.bg = &bg; - theme.list.scrl = &lv_style_transp_tight; - theme.list.btn.rel = &rel; - theme.list.btn.pr = ≺ - theme.list.btn.tgl_rel = &tgl_rel; - theme.list.btn.tgl_pr = &tgl_pr; - theme.list.btn.ina = &ina; + theme.style.list.sb = &sb; + theme.style.list.bg = &bg; + theme.style.list.scrl = &lv_style_transp_tight; + theme.style.list.btn.rel = &rel; + theme.style.list.btn.pr = ≺ + theme.style.list.btn.tgl_rel = &tgl_rel; + theme.style.list.btn.tgl_pr = &tgl_pr; + theme.style.list.btn.ina = &ina; #endif } @@ -621,7 +621,7 @@ static void ddlist_init(void) { #if USE_LV_DDLIST != 0 static lv_style_t bg, sel; - lv_style_copy(&bg, theme.panel); + lv_style_copy(&bg, theme.style.panel); bg.text.line_space = LV_DPI / 8; bg.body.padding.hor = LV_DPI / 6; bg.body.padding.ver = LV_DPI / 8; @@ -632,9 +632,9 @@ static void ddlist_init(void) sel.body.border.width = 0; sel.text.color = lv_color_hsv_to_rgb(_hue, 50, 80); - theme.ddlist.bg = &bg; - theme.ddlist.sel = &sel; - theme.ddlist.sb = &def; + theme.style.ddlist.bg = &bg; + theme.style.ddlist.sel = &sel; + theme.style.ddlist.sb = &def; #endif } @@ -648,12 +648,12 @@ static void roller_init(void) bg.text.line_space = LV_DPI / 6; bg.text.color = LV_COLOR_HEX3(0x999); - lv_style_copy(&sel, theme.panel); + lv_style_copy(&sel, theme.style.panel); sel.body.radius = LV_RADIUS_CIRCLE; sel.body.empty = 1; - theme.roller.bg = &bg; - theme.roller.sel = &sel; + theme.style.roller.bg = &bg; + theme.style.roller.sel = &sel; #endif } @@ -690,22 +690,22 @@ static void tabview_init(void) lv_style_copy(&tgl_pr, &rel); tgl_pr.text.color = lv_color_hsv_to_rgb(_hue, 50, 70); - theme.tabview.bg = theme.bg; - theme.tabview.indic = &indic; - theme.tabview.btn.bg = &btn_bg; - theme.tabview.btn.rel = &rel; - theme.tabview.btn.pr = ≺ - theme.tabview.btn.tgl_rel = &tgl_rel; - theme.tabview.btn.tgl_pr = &tgl_pr; + theme.style.tabview.bg = theme.style.bg; + theme.style.tabview.indic = &indic; + theme.style.tabview.btn.bg = &btn_bg; + theme.style.tabview.btn.rel = &rel; + theme.style.tabview.btn.pr = ≺ + theme.style.tabview.btn.tgl_rel = &tgl_rel; + theme.style.tabview.btn.tgl_pr = &tgl_pr; #endif } static void tileview_init(void) { #if USE_LV_TILEVIEW != 0 - theme.tileview.bg = &lv_style_transp_tight; - theme.tileview.scrl = &lv_style_transp_tight; - theme.tileview.sb = theme.page.sb; + theme.style.tileview.bg = &lv_style_transp_tight; + theme.style.tileview.scrl = &lv_style_transp_tight; + theme.style.tileview.sb = theme.style.page.sb; #endif } @@ -713,15 +713,15 @@ static void table_init(void) { #if USE_LV_TABLE != 0 static lv_style_t cell; - lv_style_copy(&cell, theme.panel); + lv_style_copy(&cell, theme.style.panel); cell.body.radius = 0; cell.body.border.width = 1; cell.body.shadow.width = 0; cell.body.padding.hor = LV_DPI / 12; cell.body.padding.ver = LV_DPI / 12; - theme.table.bg = &lv_style_transp_tight; - theme.table.cell = &cell; + theme.style.table.bg = &lv_style_transp_tight; + theme.style.table.cell = &cell; #endif } @@ -748,16 +748,58 @@ static void win_init(void) pr.text.color = LV_COLOR_HEX3(0x333); pr.image.color = LV_COLOR_HEX3(0x333); - theme.win.bg = theme.panel; - theme.win.sb = &sb; - theme.win.header = &header; - theme.win.content.bg = &lv_style_transp; - theme.win.content.scrl = &lv_style_transp; - theme.win.btn.rel = &rel; - theme.win.btn.pr = ≺ + theme.style.win.bg = theme.style.panel; + theme.style.win.sb = &sb; + theme.style.win.header = &header; + theme.style.win.content.bg = &lv_style_transp; + theme.style.win.content.scrl = &lv_style_transp; + theme.style.win.btn.rel = &rel; + theme.style.win.btn.pr = ≺ #endif } +#if USE_LV_GROUP + +static void style_mod(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = lv_color_hsv_to_rgb(_hue, 40, 50); + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 2; +#endif +} + +static void style_mod_edit(lv_style_t * style) +{ +#if LV_COLOR_DEPTH != 1 + /*Make the style to be a little bit orange*/ + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_GREEN; + + /*If not empty or has border then emphasis the border*/ + if (style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20; + + style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70); + style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60); + + style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70); +#else + style->body.border.opa = LV_OPA_COVER; + style->body.border.color = LV_COLOR_BLACK; + style->body.border.width = 3; +#endif +} + +#endif /*USE_LV_GROUP*/ + /********************** * GLOBAL FUNCTIONS **********************/ @@ -779,8 +821,8 @@ lv_theme_t * lv_theme_zen_init(uint16_t hue, lv_font_t * font) /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; - lv_style_t ** style_p = (lv_style_t **) &theme; - for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t *); i++) { + lv_style_t ** style_p = (lv_style_t **) &theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { *style_p = &def; style_p++; } @@ -816,6 +858,11 @@ lv_theme_t * lv_theme_zen_init(uint16_t hue, lv_font_t * font) table_init(); win_init(); +#if USE_LV_GROUP + theme.group.style_mod = style_mod; + theme.group.style_mod_edit = style_mod_edit; +#endif + return &theme; }