diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index bf17082fb..2a6973d88 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -34,7 +34,8 @@ static void lv_lists_init(void); * STATIC VARIABLES **********************/ static lv_lists_t lv_lists_def; -static lv_lists_t lv_lists_tight; +static lv_lists_t lv_lists_scrl; +static lv_lists_t lv_lists_transp; /********************** * MACROS @@ -65,10 +66,10 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new list object*/ if(copy == NULL) { - ext ->fit = LV_LIST_FIT_HOLDER; + ext ->fit = LV_LIST_FIT_WIDTH; lv_obj_set_size_us(new_list, 120, 150); lv_obj_set_style(new_list, lv_lists_get(LV_LISTS_DEF, NULL)); - lv_rect_set_layout(LV_EA(new_list, lv_list_ext_t)->page_ext.scrolling, LV_LIST_LAYOUT_DEF); + lv_rect_set_layout(LV_EA(new_list, lv_list_ext_t)->page_ext.scrl, LV_LIST_LAYOUT_DEF); } else { lv_list_ext_t * copy_ext = lv_obj_get_ext(copy); ext ->fit = copy_ext->fit; @@ -139,12 +140,17 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l } /*Make the size adjustment*/ - if(ext->fit == LV_LIST_FIT_HOLDER) { + if(ext->fit == LV_LIST_FIT_WIDTH || ext->fit == LV_LIST_FIT_WIDTH_SB) { /*Now the width will be adjusted (so disable hor. auto fit)*/ lv_rect_set_fit(liste, false, true); cord_t w = lv_obj_get_width(list); - w -= lists->bg_pages.bg_rects.hpad * 2; - w -= lists->bg_pages.scrable_rects.hpad * 2; + cord_t hpad_tot = lists->bg_pages.bg_rects.hpad + lists->bg_pages.scrl_rects.hpad; + w -= hpad_tot * 2; + + /*Make place for the scrollbar if hpad_tot is too small*/ + if(ext->fit == LV_LIST_FIT_WIDTH_SB) { + if(hpad_tot < lists->bg_pages.sb_width) w -= lists->bg_pages.sb_width - hpad_tot; + } lv_obj_set_width(liste, w); } else if(ext->fit == LV_LIST_FIT_LONGEST) { /*In this case the width will be adjusted*/ @@ -281,11 +287,13 @@ lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * list) switch(style) { case LV_LISTS_DEF: - case LV_LISTS_GAP: - style_p = &lv_lists_def; - break; - case LV_LISTS_TIGHT: - style_p = &lv_lists_tight; + style_p = &lv_lists_def; + break; + case LV_LISTS_SCRL: + style_p = &lv_lists_scrl; + break; + case LV_LISTS_TRANSP: + style_p = &lv_lists_transp; break; default: style_p = &lv_lists_def; @@ -334,14 +342,14 @@ static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_ static void lv_lists_init(void) { /*Default style*/ - lv_pages_get(LV_PAGES_TRANSP, &lv_lists_def.bg_pages); + lv_pages_get(LV_PAGES_DEF, &lv_lists_def.bg_pages); lv_lists_def.bg_pages.bg_rects.vpad = 0 * LV_DOWNSCALE; lv_lists_def.bg_pages.bg_rects.hpad = 0 * LV_DOWNSCALE; lv_lists_def.bg_pages.bg_rects.opad = 0 * LV_DOWNSCALE; - lv_lists_def.bg_pages.scrable_rects.vpad = 10 * LV_DOWNSCALE; - lv_lists_def.bg_pages.scrable_rects.hpad = 10 * LV_DOWNSCALE; - lv_lists_def.bg_pages.scrable_rects.opad = 5 * LV_DOWNSCALE; + lv_lists_def.bg_pages.scrl_rects.vpad = 0 * LV_DOWNSCALE; + lv_lists_def.bg_pages.scrl_rects.hpad = 0 * LV_DOWNSCALE; + lv_lists_def.bg_pages.scrl_rects.opad = 5 * LV_DOWNSCALE; lv_btns_get(LV_BTNS_DEF, &lv_lists_def.liste_btns); /*List element button style*/ @@ -352,14 +360,30 @@ static void lv_lists_init(void) lv_lists_def.liste_layout = LV_RECT_LAYOUT_ROW_M; - memcpy(&lv_lists_tight, &lv_lists_def, sizeof(lv_lists_t)); - lv_lists_tight.bg_pages.bg_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_tight.bg_pages.bg_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_tight.bg_pages.bg_rects.opad = 0 * LV_DOWNSCALE; + /*Only the scrollable part is visible style*/ + memcpy(&lv_lists_scrl, &lv_lists_def, sizeof(lv_lists_t)); + lv_pages_get(LV_PAGES_TRANSP, &lv_lists_scrl.bg_pages); + lv_lists_scrl.bg_pages.bg_rects.vpad = 0 * LV_DOWNSCALE; + lv_lists_scrl.bg_pages.bg_rects.hpad = 0 * LV_DOWNSCALE; + lv_lists_scrl.bg_pages.bg_rects.opad = 0 * LV_DOWNSCALE; - lv_lists_tight.bg_pages.scrable_rects.vpad = 0 * LV_DOWNSCALE; - lv_lists_tight.bg_pages.scrable_rects.hpad = 0 * LV_DOWNSCALE; - lv_lists_tight.bg_pages.scrable_rects.opad = 0 * LV_DOWNSCALE; + lv_lists_scrl.bg_pages.scrl_rects.objs.transp = 0; + lv_lists_scrl.bg_pages.scrl_rects.empty = 0; + lv_lists_scrl.bg_pages.scrl_rects.bwidth = 1 * LV_DOWNSCALE; + lv_lists_scrl.bg_pages.scrl_rects.vpad = 0 * LV_DOWNSCALE; + lv_lists_scrl.bg_pages.scrl_rects.hpad = 0 * LV_DOWNSCALE; + lv_lists_scrl.bg_pages.scrl_rects.opad = 0 * LV_DOWNSCALE; + + /*Transparent list background*/ + memcpy(&lv_lists_transp, &lv_lists_def, sizeof(lv_lists_t)); + lv_pages_get(LV_PAGES_TRANSP, &lv_lists_transp.bg_pages); + lv_lists_transp.bg_pages.bg_rects.vpad = 0 * LV_DOWNSCALE; + lv_lists_transp.bg_pages.bg_rects.hpad = 0 * LV_DOWNSCALE; + lv_lists_transp.bg_pages.bg_rects.opad = 0 * LV_DOWNSCALE; + + lv_lists_transp.bg_pages.scrl_rects.vpad = 0 * LV_DOWNSCALE; + lv_lists_transp.bg_pages.scrl_rects.hpad = 0 * LV_DOWNSCALE; + lv_lists_transp.bg_pages.scrl_rects.opad = 5 * LV_DOWNSCALE; } #endif diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index b2b32cc3b..5089400ab 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -41,14 +41,15 @@ typedef struct typedef enum { LV_LISTS_DEF, - LV_LISTS_GAP, - LV_LISTS_TIGHT, + LV_LISTS_SCRL, + LV_LISTS_TRANSP, }lv_lists_builtin_t; typedef enum { + LV_LIST_FIT_WIDTH, + LV_LIST_FIT_WIDTH_SB, /*Let space for the scrollbar*/ LV_LIST_FIT_CONTENT, - LV_LIST_FIT_HOLDER, LV_LIST_FIT_LONGEST, }lv_list_fit_t; diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 853aa5b27..b3be272f6 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -29,13 +29,14 @@ **********************/ static void lv_page_sb_refresh(lv_obj_t * main); static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode); -static bool lv_scrolling_signal(lv_obj_t * page, lv_signal_t sign, void* param); +static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param); static void lv_pages_init(void); /********************** * STATIC VARIABLES **********************/ static lv_pages_t lv_pages_def; +static lv_pages_t lv_pages_simple; static lv_pages_t lv_pages_transp; static lv_design_f_t ancestor_design_f; @@ -74,12 +75,12 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new page object*/ if(copy == NULL) { lv_pages_t * pages = lv_pages_get(LV_PAGES_DEF, NULL); - ext->scrolling = lv_rect_create(new_page, NULL); - lv_obj_set_signal_f(ext->scrolling, lv_scrolling_signal); - lv_obj_set_drag(ext->scrolling, true); - lv_obj_set_drag_throw(ext->scrolling, true); - lv_rect_set_fit(ext->scrolling, true, true); - lv_obj_set_style(ext->scrolling, &pages->scrable_rects); + ext->scrl = lv_rect_create(new_page, NULL); + lv_obj_set_signal_f(ext->scrl, lv_scrl_signal); + lv_obj_set_drag(ext->scrl, true); + lv_obj_set_drag_throw(ext->scrl, true); + lv_rect_set_fit(ext->scrl, true, true); + lv_obj_set_style(ext->scrl, &pages->scrl_rects); /* Add the signal function only if 'scrolling' is created * because everything has to be ready before any signal is received*/ @@ -88,8 +89,8 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_set_style(new_page, pages); } else { lv_page_ext_t * copy_ext = lv_obj_get_ext(copy); - ext->scrolling = lv_rect_create(new_page, copy_ext->scrolling); - lv_obj_set_signal_f(ext->scrolling, lv_scrolling_signal); + ext->scrl = lv_rect_create(new_page, copy_ext->scrl); + lv_obj_set_signal_f(ext->scrl, lv_scrl_signal); /* Add the signal function only if 'scrolling' is created * because everything has to be ready before any signal is received*/ @@ -127,10 +128,10 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) case LV_SIGNAL_CHILD_CHG: /*Be sure, only scrollable object is on the page*/ child = lv_obj_get_child(page, NULL); while(child != NULL) { - if(child != ext->scrolling) { + if(child != ext->scrl) { lv_obj_t * tmp = child; child = lv_obj_get_child(page, child); /*Get the next child before move this*/ - lv_obj_set_parent(tmp, ext->scrolling); + lv_obj_set_parent(tmp, ext->scrl); } else { child = lv_obj_get_child(page, child); } @@ -140,7 +141,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) case LV_SIGNAL_STYLE_CHG: area_set_height(&ext->sbh, pages->sb_width); area_set_width(&ext->sbv, pages->sb_width); - lv_obj_set_style(ext->scrolling, &pages->scrable_rects); + lv_obj_set_style(ext->scrl, &pages->scrl_rects); if(pages->sb_mode == LV_PAGE_SB_MODE_ON) { ext->sbh_draw = 1; @@ -154,8 +155,8 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) break; case LV_SIGNAL_CORD_CHG: - if(ext->scrolling != NULL) { - ext->scrolling->signal_f(ext->scrolling, LV_SIGNAL_CORD_CHG, &ext->scrolling->cords); + if(ext->scrl != NULL) { + ext->scrl->signal_f(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->cords); lv_page_sb_refresh(page); } break; @@ -182,16 +183,16 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) /** * Signal function of the scrollable part of a page - * @param scrolling pointer to the scrollable object + * @param scrl pointer to the scrollable object * @param sign a signal type from lv_signal_t enum * @param param pointer to a signal specific variable */ -static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* param) +static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param) { bool obj_valid = true; /* Include the ancient signal function */ - obj_valid = lv_rect_signal(scrolling, sign, param); + obj_valid = lv_rect_signal(scrl, sign, param); /* The object can be deleted so check its validity and then * make the object specific signal handling */ @@ -203,7 +204,7 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa bool refr_y = false; area_t page_cords; area_t obj_cords; - lv_obj_t * page = lv_obj_get_parent(scrolling); + lv_obj_t * page = lv_obj_get_parent(scrl); lv_pages_t * pages = lv_obj_get_style(page); lv_page_ext_t * page_ext = lv_obj_get_ext(page); cord_t hpad = pages->bg_rects.hpad; @@ -211,9 +212,9 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa switch(sign) { case LV_SIGNAL_CORD_CHG: - new_x = lv_obj_get_x(scrolling); - new_y = lv_obj_get_y(scrolling); - lv_obj_get_cords(scrolling, &obj_cords); + new_x = lv_obj_get_x(scrl); + new_y = lv_obj_get_y(scrl); + lv_obj_get_cords(scrl, &obj_cords); lv_obj_get_cords(page, &page_cords); /*scrollable width smaller then page width? -> align to left*/ @@ -252,7 +253,7 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa } } if(refr_x != false || refr_y != false) { - lv_obj_set_pos(scrolling, new_x, new_y); + lv_obj_set_pos(scrl, new_x, new_y); } lv_page_sb_refresh(page); @@ -260,11 +261,11 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa case LV_SIGNAL_DRAG_BEGIN: if(pages->sb_mode == LV_PAGE_SB_MODE_AUTO ) { - if(area_get_height(&page_ext->sbv) < lv_obj_get_height(scrolling) - pages->sb_width) { + if(area_get_height(&page_ext->sbv) < lv_obj_get_height(scrl) - pages->sb_width) { page_ext->sbv_draw = 1; lv_inv_area(&page_ext->sbv); } - if(area_get_width(&page_ext->sbh) < lv_obj_get_width(scrolling) - pages->sb_width) { + if(area_get_width(&page_ext->sbh) < lv_obj_get_width(scrl) - pages->sb_width) { page_ext->sbh_draw = 1; lv_inv_area(&page_ext->sbh); } @@ -351,7 +352,7 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en) cord_t obj_y = lv_obj_get_y(obj); cord_t obj_h = lv_obj_get_height(obj); - cord_t scrlable_y = lv_obj_get_y(ext->scrolling); + cord_t scrlable_y = lv_obj_get_y(ext->scrl); cord_t page_h = lv_obj_get_height(page); bool refr = false; @@ -364,8 +365,8 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en) if((obj_h <= page_h && top_err > 0) || (obj_h > page_h && top_err < bot_err)) { /*Calculate a new position and to let scrable_rects.vpad space above*/ - scrlable_y = -(obj_y - style->scrable_rects.vpad - style->bg_rects.vpad); - scrlable_y += style->scrable_rects.vpad; + scrlable_y = -(obj_y - style->scrl_rects.vpad - style->bg_rects.vpad); + scrlable_y += style->scrl_rects.vpad; refr = true; } /*Out of the page on the bottom*/ @@ -374,26 +375,26 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en) /*Calculate a new position and to let scrable_rects.vpad space below*/ scrlable_y = -obj_y; scrlable_y += page_h - obj_h; - scrlable_y -= style->scrable_rects.vpad; + scrlable_y -= style->scrl_rects.vpad; refr = true; } if(refr != false) { #if LV_PAGE_ANIM_FOCUS_TIME == 0 - lv_obj_set_y(ext->scrolling, scrlable_y); + lv_obj_set_y(ext->scrl, scrlable_y); #else if(anim_en == false) { - lv_obj_set_y(ext->scrolling, scrlable_y); + lv_obj_set_y(ext->scrl, scrlable_y); } else { anim_t a; a.act_time = 0; - a.start = lv_obj_get_y(ext->scrolling); + a.start = lv_obj_get_y(ext->scrl); a.end = scrlable_y; a.time = LV_PAGE_ANIM_FOCUS_TIME;//anim_speed_to_time(LV_PAGE_ANIM_SPEED, a.start, a.end); a.end_cb = NULL; a.playback = 0; a.repeat = 0; - a.var = ext->scrolling; + a.var = ext->scrl; a.path = anim_get_path(ANIM_PATH_LIN); a.fp = (anim_fp_t) lv_obj_set_y; @@ -412,11 +413,11 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en) * @param page pointer to page object * @return pointer to rectangle which is the scrollable part of the page */ -lv_obj_t * lv_page_get_scrable(lv_obj_t * page) +lv_obj_t * lv_page_get_scrl(lv_obj_t * page) { lv_page_ext_t * ext = lv_obj_get_ext(page); - return ext->scrolling; + return ext->scrl; } /** @@ -441,6 +442,9 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy) case LV_PAGES_DEF: style_p = &lv_pages_def; break; + case LV_PAGES_SIMPLE: + style_p = &lv_pages_simple; + break; case LV_PAGES_TRANSP: style_p = &lv_pages_transp; break; @@ -502,58 +506,64 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_ */ static void lv_page_sb_refresh(lv_obj_t * page) { + /*Always let sb_width padding above,under, left and right to the scrollbars + * else: + * - horizontal and vertical scrollbars can overlap on the corners + * - if the page has radius the scrollbar can be out of the radius */ + lv_page_ext_t * page_ext = lv_obj_get_ext(page); - lv_pages_t * pages = lv_obj_get_style(page); - lv_obj_t * scrolling = page_ext->scrolling; + lv_pages_t * style = lv_obj_get_style(page); + lv_obj_t * scrl = page_ext->scrl; cord_t size_tmp; - cord_t scrolling_w = lv_obj_get_width(scrolling); - cord_t scrolling_h = lv_obj_get_height(scrolling); - cord_t hpad = pages->bg_rects.hpad; - cord_t vpad = pages->bg_rects.vpad; + cord_t scrl_w = lv_obj_get_width(scrl); + cord_t scrl_h = lv_obj_get_height(scrl); + cord_t hpad = style->bg_rects.hpad; + cord_t vpad = style->bg_rects.vpad; cord_t obj_w = lv_obj_get_width(page); cord_t obj_h = lv_obj_get_height(page); cord_t page_x0 = page->cords.x1; cord_t page_y0 = page->cords.y1; - - if(pages->sb_mode == LV_PAGE_SB_MODE_OFF) return; + if(style->sb_mode == LV_PAGE_SB_MODE_OFF) return; /*Invalidate the current (old) scrollbar areas*/ if(page_ext->sbh_draw != 0) lv_inv_area(&page_ext->sbh); if(page_ext->sbv_draw != 0) lv_inv_area(&page_ext->sbv); /*Horizontal scrollbar*/ - if(scrolling_w <= obj_w - 2 * hpad) { /*Full sized scroll bar*/ - area_set_width(&page_ext->sbh, obj_w - pages->sb_width); - area_set_pos(&page_ext->sbh, page_x0, page_y0 + obj_h - pages->sb_width); + if(scrl_w <= obj_w - 2 * hpad) { /*Full sized scroll bar*/ + area_set_width(&page_ext->sbh, obj_w - style->sb_width); + area_set_pos(&page_ext->sbh, page_x0, page_y0 + obj_h - style->sb_width); + page_ext->sbh_draw = 0; } else { - if(pages->sb_mode == LV_PAGE_SB_MODE_ON) { + if(style->sb_mode == LV_PAGE_SB_MODE_ON) { page_ext->sbh_draw = 1; } - size_tmp = (((obj_w - hpad) * (obj_w - pages->sb_width)) / scrolling_w); + size_tmp = (obj_w * (obj_w - (2 * style->sb_width))) / (scrl_w + 2 * hpad); area_set_width(&page_ext->sbh, size_tmp); - area_set_pos(&page_ext->sbh, page_x0 + - ( -(lv_obj_get_x(scrolling) - hpad) * (obj_w - size_tmp - pages->sb_width)) / - (scrolling_w - obj_w + 2 * hpad), - page_y0 + obj_h - pages->sb_width); + area_set_pos(&page_ext->sbh, page_x0 + style->sb_width + + (-(lv_obj_get_x(scrl) - hpad) * (obj_w - size_tmp - 2 * style->sb_width)) / + (scrl_w + 2 * hpad - obj_w ), + page_y0 + obj_h - style->sb_width); } /*Vertical scrollbar*/ - if(scrolling_h <= obj_h - 2 * vpad) { /*Full sized scroll bar*/ - area_set_height(&page_ext->sbv, obj_h - pages->sb_width); - area_set_pos(&page_ext->sbv, page_x0 + obj_w - pages->sb_width, 0); + if(scrl_h <= obj_h - 2 * vpad) { /*Full sized scroll bar*/ + area_set_height(&page_ext->sbv, obj_h - style->sb_width); + area_set_pos(&page_ext->sbv, page_x0 + obj_w - style->sb_width, 0); + page_ext->sbv_draw = 0; } else { - if(pages->sb_mode == LV_PAGE_SB_MODE_ON) { + if(style->sb_mode == LV_PAGE_SB_MODE_ON) { page_ext->sbv_draw = 1; } - size_tmp = (((obj_h - vpad) * (obj_h - pages->sb_width)) / scrolling_h); + size_tmp = (obj_h * (obj_h - (2 * style->sb_width))) / (scrl_h + 2 * vpad); area_set_height(&page_ext->sbv, size_tmp); - area_set_pos(&page_ext->sbv, page_x0 + obj_w - pages->sb_width, - page_y0 + - (-(lv_obj_get_y(scrolling) - vpad) * (obj_h - size_tmp - pages->sb_width)) / - (scrolling_h - obj_h + 2 * vpad)); + area_set_pos(&page_ext->sbv, page_x0 + obj_w - style->sb_width, + page_y0 + style->sb_width + + (-(lv_obj_get_y(scrl) - vpad) * (obj_h - size_tmp - 2 * style->sb_width)) / + (scrl_h + 2 * vpad - obj_h )); } /*Invalidate the new scrollbar areas*/ @@ -569,10 +579,10 @@ static void lv_pages_init(void) /*Default style*/ lv_rects_get(LV_RECTS_DEF, &lv_pages_def.bg_rects); - lv_rects_get(LV_RECTS_DEF, &lv_pages_def.scrable_rects); - lv_pages_def.scrable_rects.objs.color = COLOR_WHITE; - lv_pages_def.scrable_rects.gcolor = COLOR_SILVER; - lv_pages_def.scrable_rects.bcolor = COLOR_GRAY; + lv_rects_get(LV_RECTS_DEF, &lv_pages_def.scrl_rects); + lv_pages_def.scrl_rects.objs.color = COLOR_WHITE; + lv_pages_def.scrl_rects.gcolor = COLOR_SILVER; + lv_pages_def.scrl_rects.bcolor = COLOR_GRAY; lv_rects_get(LV_RECTS_DEF, &lv_pages_def.sb_rects); lv_pages_def.sb_rects.objs.color = COLOR_BLACK; @@ -585,11 +595,21 @@ static void lv_pages_init(void) lv_pages_def.sb_opa=50; lv_pages_def.sb_mode = LV_PAGE_SB_MODE_AUTO; - /*Transparent style*/ - memcpy(&lv_pages_transp, &lv_pages_def, sizeof(lv_pages_t)); - lv_pages_transp.scrable_rects.objs.transp = 1; - lv_pages_transp.scrable_rects.empty = 1; - lv_pages_transp.scrable_rects.bwidth = 0; + /*No (transparent) scrollable style*/ + memcpy(&lv_pages_simple, &lv_pages_def, sizeof(lv_pages_t)); + lv_rects_get(LV_RECTS_TRANSP, &lv_pages_simple.scrl_rects); + lv_pages_simple.scrl_rects.vpad = 0 * LV_DOWNSCALE; + lv_pages_simple.scrl_rects.hpad = 0 * LV_DOWNSCALE; + /*Transparent style*/ + memcpy(&lv_pages_transp, &lv_pages_simple, sizeof(lv_pages_t)); + lv_rects_get(LV_RECTS_TRANSP, &lv_pages_transp.bg_rects); + lv_pages_transp.bg_rects.vpad = 10 * LV_DOWNSCALE; + lv_pages_transp.bg_rects.hpad = 10 * LV_DOWNSCALE; + lv_pages_transp.bg_rects.opad = 10 * LV_DOWNSCALE; + /* Make transparent bg. only witth bwidth = 0 nad empty = 1 + * because with transp = 1 the design function will not be called + * to draw the scrollbars*/ + lv_pages_transp.bg_rects.objs.transp = 0; } #endif diff --git a/lv_objx/lv_page.h b/lv_objx/lv_page.h index 28351e476..50ff3e538 100644 --- a/lv_objx/lv_page.h +++ b/lv_objx/lv_page.h @@ -35,7 +35,7 @@ typedef struct { lv_rects_t bg_rects; /*Style of ancestor*/ /*New style element for this type */ - lv_rects_t scrable_rects; + lv_rects_t scrl_rects; lv_rects_t sb_rects; cord_t sb_width; lv_page_sb_mode_t sb_mode; @@ -46,6 +46,7 @@ typedef struct typedef enum { LV_PAGES_DEF, + LV_PAGES_SIMPLE, LV_PAGES_TRANSP, }lv_pages_builtin_t; @@ -54,7 +55,7 @@ typedef struct { lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ /*New data for this type */ - lv_obj_t * scrolling; /*The scrollable object on the background*/ + lv_obj_t * scrl; /*The scrollable object on the background*/ lv_action_t rel_action; lv_action_t pr_action; area_t sbh; /*Horizontal scrollbar*/ @@ -76,7 +77,7 @@ void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action); void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action); void lv_page_glue_obj(lv_obj_t * page, bool glue); void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en); -lv_obj_t * lv_page_get_scrable(lv_obj_t * page); +lv_obj_t * lv_page_get_scrl(lv_obj_t * page); /********************** * MACROS diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index ec26c2354..55b39fbd3 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -35,9 +35,11 @@ static void lv_tas_init(void); * STATIC VARIABLES **********************/ static lv_tas_t lv_tas_def; +static lv_tas_t lv_tas_simple; +static lv_tas_t lv_tas_transp; lv_design_f_t ancestor_design_f; -lv_design_f_t scrling_design_f; +lv_design_f_t scrl_design_f; /********************** * MACROS @@ -81,11 +83,11 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new text area object*/ if(copy == NULL) { ext->label = lv_label_create(new_ta, NULL); - if(scrling_design_f == NULL) { - scrling_design_f = lv_obj_get_design_f(ext->page.scrolling); + if(scrl_design_f == NULL) { + scrl_design_f = lv_obj_get_design_f(ext->page.scrl); } - lv_obj_set_design_f(ext->page.scrolling, lv_ta_scrling_design); + lv_obj_set_design_f(ext->page.scrl, lv_ta_scrling_design); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); lv_label_set_text(ext->label, "Text area"); lv_page_glue_obj(ext->label, true); @@ -95,7 +97,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) } /*Copy an existing object*/ else { - lv_obj_set_design_f(ext->page.scrolling, lv_ta_scrling_design); + lv_obj_set_design_f(ext->page.scrl, lv_ta_scrling_design); lv_ta_ext_t * copy_ext = lv_obj_get_ext(copy); ext->label = lv_label_create(new_ta, copy_ext->label); lv_page_glue_obj(ext->label, true); @@ -150,13 +152,13 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) case LV_SIGNAL_STYLE_CHG: lv_obj_set_style(ext->label, &style->labels); lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 * - (style->pages.bg_rects.hpad + style->pages.scrable_rects.hpad)); + (style->pages.bg_rects.hpad + style->pages.scrl_rects.hpad)); lv_label_set_text(ext->label, NULL); break; /*Set the label width according to the text area width*/ case LV_SIGNAL_CORD_CHG: lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 * - (style->pages.bg_rects.hpad + style->pages.scrable_rects.hpad)); + (style->pages.bg_rects.hpad + style->pages.scrl_rects.hpad)); lv_label_set_text(ext->label, NULL); break; default: @@ -306,9 +308,9 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) } /*Check the bottom*/ - if(label_cords.y1 + cur_pos.y + font_get_height(font_p) + style->pages.scrable_rects.vpad > ta_cords.y2) { + if(label_cords.y1 + cur_pos.y + font_get_height(font_p) + style->pages.scrl_rects.vpad > ta_cords.y2) { lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) + - font_get_height(font_p) + 2 * style->pages.scrable_rects.vpad)); + font_get_height(font_p) + 2 * style->pages.scrl_rects.vpad)); } lv_obj_inv(ta); @@ -441,6 +443,12 @@ lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy) case LV_TAS_DEF: style_p = &lv_tas_def; break; + case LV_TAS_SIMPLE: + style_p = &lv_tas_simple; + break; + case LV_TAS_TRANSP: + style_p = &lv_tas_transp; + break; default: style_p = &lv_tas_def; } @@ -495,12 +503,12 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des { if(mode == LV_DESIGN_COVER_CHK) { /*Return false if the object is not covers the mask_p area*/ - return scrling_design_f(scrling, mask, mode); + return scrl_design_f(scrling, mask, mode); } else if(mode == LV_DESIGN_DRAW_MAIN) { /*Draw the object*/ - scrling_design_f(scrling, mask, mode); + scrl_design_f(scrling, mask, mode); } else if(mode == LV_DESIGN_DRAW_POST) { - scrling_design_f(scrling, mask, mode); + scrl_design_f(scrling, mask, mode); /*Draw the cursor too*/ lv_obj_t * ta = lv_obj_get_parent(scrling); @@ -566,6 +574,7 @@ static void lv_tas_init(void) { /*Default style*/ lv_pages_get(LV_PAGES_DEF, &lv_tas_def.pages); + lv_tas_def.pages.sb_mode = LV_PAGE_SB_MODE_ON; lv_labels_get(LV_LABELS_TXT, &lv_tas_def.labels); lv_tas_def.labels.objs.color = COLOR_MAKE(0x20, 0x20, 0x20); @@ -573,5 +582,18 @@ static void lv_tas_init(void) lv_tas_def.cursor_color = COLOR_MAKE(0x10, 0x10, 0x10); lv_tas_def.cursor_width = 1 * LV_DOWNSCALE; /*>=1 px for visible cursor*/ lv_tas_def.cursor_show = 1; + + memcpy(&lv_tas_simple, &lv_tas_def, sizeof(lv_tas_t)); + lv_pages_get(LV_PAGES_SIMPLE, &lv_tas_simple.pages); + lv_tas_simple.pages.sb_mode = LV_PAGE_SB_MODE_ON; + lv_tas_simple.pages.scrl_rects.objs.transp = 0; /*if transp == 1 the cursor will not be drawn*/ + lv_tas_simple.pages.bg_rects.objs.color = COLOR_WHITE; + lv_tas_simple.pages.bg_rects.gcolor = COLOR_SILVER; + lv_tas_simple.pages.bg_rects.bcolor = COLOR_GRAY; + + memcpy(&lv_tas_transp, &lv_tas_def, sizeof(lv_tas_t)); + lv_pages_get(LV_PAGES_TRANSP, &lv_tas_transp.pages); + lv_tas_transp.pages.scrl_rects.objs.transp = 0; /*if transp == 1 the cursor will not be drawn*/ + } #endif diff --git a/lv_objx/lv_ta.h b/lv_objx/lv_ta.h index a4f7f3d70..557e0288c 100644 --- a/lv_objx/lv_ta.h +++ b/lv_objx/lv_ta.h @@ -40,6 +40,8 @@ typedef struct typedef enum { LV_TAS_DEF, + LV_TAS_SIMPLE, + LV_TAS_TRANSP, }lv_tas_builtin_t; /*Data of text area*/