From c3dddda326a9cf6fe0b26469f13bba40579f13d8 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 12 Jan 2020 22:08:34 +0100 Subject: [PATCH] integrate table --- src/lv_core/lv_obj.c | 515 ++++++++++++++++----------------- src/lv_core/lv_obj.h | 6 +- src/lv_core/lv_style.h | 1 + src/lv_objx/lv_btnm.c | 2 + src/lv_objx/lv_table.c | 260 +++++++++-------- src/lv_objx/lv_table.h | 31 +- src/lv_themes/lv_theme.c | 2 +- src/lv_themes/lv_theme.h | 8 + src/lv_themes/lv_theme_alien.c | 36 ++- 9 files changed, 447 insertions(+), 414 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 245570aa8..5befcafea 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -37,7 +37,7 @@ #define LV_OBJX_NAME "lv_obj" #define LV_OBJ_DEF_WIDTH (LV_DPI) #define LV_OBJ_DEF_HEIGHT (2 * LV_DPI / 3) -#define LV_DRAW_RECT_CACHE_SIZE 8 +#define LV_DRAW_RECT_CACHE_SIZE 0 /********************** * TYPEDEFS @@ -63,7 +63,14 @@ static void report_style_mod_core(void * style_p, lv_obj_t * obj); static void refresh_children_style(lv_obj_t * obj); static void delete_children(lv_obj_t * obj); static void base_dir_refr_children(lv_obj_t * obj); +static void obj_state_anim_cb(void * p, lv_anim_value_t value); static void lv_event_mark_deleted(lv_obj_t * obj); + +static lv_style_int_t lv_obj_get_style_int_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); +static lv_color_t lv_obj_get_style_color_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); +static lv_opa_t lv_obj_get_style_opa_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); +static const void * lv_obj_get_style_ptr_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); + static void lv_obj_del_async_cb(void * obj); static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param); @@ -75,8 +82,6 @@ static bool lv_initialized = false; static lv_event_temp_data_t * event_temp_data_head; static const void * event_act_data; -static lv_draw_rect_cache_t lv_draw_rect_cache[LV_DRAW_RECT_CACHE_SIZE]; -static uint16_t lv_draw_rect_cache_last; /********************** * MACROS **********************/ @@ -1429,33 +1434,29 @@ void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot) obj->protect &= prot; } -void lv_obj_state_anim_cb(void * p, lv_anim_value_t value) -{ - lv_obj_t * obj = p; - obj->state_anim = value; - if(value == 255) obj->prev_state = obj->state; - - lv_obj_refresh_style(obj); -} - void lv_obj_set_state(lv_obj_t * obj, lv_obj_state_t state) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); lv_obj_state_t new_state = obj->state | state; if(obj->state != new_state) { - obj->prev_state = obj->state; + lv_obj_state_t prev_state = obj->state; + + /*Set the new state for prev state too to get the TRANSITION_TIME for the new state*/ + obj->prev_state = new_state; obj->state = new_state; obj->state_anim = 0; + /*Get the TRANSITION_TIME and set the real previous state*/ + lv_style_int_t t = lv_obj_get_style_int(obj, LV_OBJ_PART_MAIN, LV_STYLE_TRANSITION_TIME); + obj->prev_state = prev_state; + lv_anim_t a; lv_anim_init(&a); - lv_anim_set_exec_cb(&a, obj, lv_obj_state_anim_cb); + lv_anim_set_exec_cb(&a, obj, obj_state_anim_cb); lv_anim_set_values(&a, 0, 255); - lv_anim_set_time(&a, 1000, 0); + lv_anim_set_time(&a, t, 0); lv_anim_create(&a); - - lv_obj_refresh_style(obj); } } @@ -1466,22 +1467,25 @@ void lv_obj_clear_state(lv_obj_t * obj, lv_obj_state_t state) state = (~state) & 0xFF; lv_obj_state_t new_state = obj->state & state; if(obj->state != new_state) { - obj->prev_state = obj->state; + lv_obj_state_t prev_state = obj->state; + + /*Set the new state for prev state too to get the TRANSITION_TIME for the new state*/ + obj->prev_state = new_state; obj->state = new_state; obj->state_anim = 0; + /*Get the TRANSITION_TIME and set the real previous state*/ + lv_style_int_t t = lv_obj_get_style_int(obj, LV_OBJ_PART_MAIN, LV_STYLE_TRANSITION_TIME); + obj->prev_state = prev_state; lv_anim_t a; lv_anim_init(&a); - lv_anim_set_exec_cb(&a, obj, lv_obj_state_anim_cb); + lv_anim_set_exec_cb(&a, obj, obj_state_anim_cb); lv_anim_set_values(&a, 0, 255); - lv_anim_set_time(&a, 1000, 0); + lv_anim_set_time(&a, t, 0); lv_anim_create(&a); - - lv_obj_refresh_style(obj); } } - /** * Set a an event handler function for an object. * Used by the user to react on event which happens with the object. @@ -1936,8 +1940,8 @@ lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - lv_style_int_t top = lv_obj_get_style_int(obj, LV_OBJ_PART_MAIN, LV_STYLE_PAD_TOP); - lv_style_int_t bottom = lv_obj_get_style_int(obj, LV_OBJ_PART_MAIN, LV_STYLE_PAD_BOTTOM); + lv_style_int_t top = lv_obj_get_style_int((lv_obj_t *)obj, LV_OBJ_PART_MAIN, LV_STYLE_PAD_TOP); + lv_style_int_t bottom = lv_obj_get_style_int((lv_obj_t *)obj, LV_OBJ_PART_MAIN, LV_STYLE_PAD_BOTTOM); return lv_obj_get_height(obj) - top - bottom; } @@ -2068,94 +2072,38 @@ lv_style_dsc_t * lv_obj_get_style(const lv_obj_t * obj, uint8_t part) } -lv_style_int_t lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +lv_style_int_t lv_obj_get_style_int(lv_obj_t * obj, uint8_t part, lv_style_property_t prop) { - lv_style_property_t prop_ori = prop; + if(obj->state == obj->prev_state) { + return lv_obj_get_style_int_core(obj, part, prop); + } else { + lv_style_int_t act_int = lv_obj_get_style_int_core(obj, part, prop); + lv_obj_state_t state_ori = obj->state; + obj->state = obj->prev_state; + lv_style_int_t prev_int = lv_obj_get_style_int_core(obj, part, prop); + obj->state = state_ori; - lv_style_attr_t attr; - attr.full = prop >> 8; + if(prop == LV_STYLE_RADIUS) { + if(act_int == LV_RADIUS_CIRCLE || prev_int == LV_RADIUS_CIRCLE) { + lv_coord_t whalf = lv_obj_get_width(obj) / 2; + lv_coord_t hhalf = lv_obj_get_width(obj) / 2; - lv_style_int_t value; - lv_res_t res = LV_RES_INV; - const lv_obj_t * parent = obj; - while(parent) { - lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); + if(act_int == LV_RADIUS_CIRCLE) { + act_int = LV_MATH_MIN(whalf + 1, hhalf + 1); + } - uint8_t state = lv_obj_get_state(parent, part); - prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); - - res = lv_style_dsc_get_int(dsc, prop, &value); - if(res == LV_RES_OK) return value; - - if(attr.bits.inherit == 0) break; - - /*If not found, check the `MAIN` style first*/ - if(part != LV_OBJ_PART_MAIN) { - part = LV_OBJ_PART_MAIN; - continue; + if(prev_int == LV_RADIUS_CIRCLE) { + prev_int = LV_MATH_MIN(whalf + 1, hhalf + 1); + } + } } - /*Check the parent too.*/ - parent = lv_obj_get_parent(parent); + if(obj->state_anim >= 255) return act_int; + return prev_int + (((act_int - prev_int) * obj->state_anim) >> 8); } - - prop = prop & (~LV_STYLE_STATE_MASK); - switch(prop) { - case LV_STYLE_BORDER_SIDE: - return LV_BORDER_SIDE_FULL; - case LV_STYLE_SIZE: - return LV_DPI / 10; - case LV_STYLE_SCALE_WIDTH: - return LV_DPI / 8; - } - - return 0; } -lv_color_t lv_obj_get_style_color_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) -{ - lv_style_property_t prop_ori = prop; - - lv_style_attr_t attr; - attr.full = prop >> 8; - - lv_color_t value; - lv_res_t res = LV_RES_INV; - const lv_obj_t * parent = obj; - while(parent) { - lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); - - uint8_t state = lv_obj_get_state(parent, part); - prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); - - res = lv_style_dsc_get_color(dsc, prop, &value); - if(res == LV_RES_OK) return value; - - if(attr.bits.inherit == 0) break; - - /*If not found, check the `MAIN` style first*/ - if(part != LV_OBJ_PART_MAIN) { - part = LV_OBJ_PART_MAIN; - continue; - } - - /*Check the parent too.*/ - parent = lv_obj_get_parent(parent); - } - - /*Handle unset values*/ - prop = prop & (~LV_STYLE_STATE_MASK); - switch(prop) { - case LV_STYLE_TEXT_COLOR: - case LV_STYLE_BORDER_COLOR: - case LV_STYLE_SHADOW_COLOR: - return LV_COLOR_BLACK; - } - - return LV_COLOR_WHITE; -} - lv_color_t lv_obj_get_style_color(lv_obj_t * obj, uint8_t part, lv_style_property_t prop) { @@ -2163,100 +2111,46 @@ lv_color_t lv_obj_get_style_color(lv_obj_t * obj, uint8_t part, lv_style_propert return lv_obj_get_style_color_core(obj, part, prop); } else { lv_color_t act_color = lv_obj_get_style_color_core(obj, part, prop); - lv_obj_state_t state_ori = obj->state; obj->state = obj->prev_state; lv_color_t prev_color = lv_obj_get_style_color_core(obj, part, prop); obj->state = state_ori; - return lv_color_mix(prev_color, act_color, obj->state_anim); + return lv_color_mix(act_color, prev_color, obj->state_anim); } } -lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +lv_opa_t lv_obj_get_style_opa(lv_obj_t * obj, uint8_t part, lv_style_property_t prop) { - lv_style_property_t prop_ori = prop; + if(obj->state == obj->prev_state) { + return lv_obj_get_style_opa_core(obj, part, prop); + } else { + lv_opa_t act_opa = lv_obj_get_style_opa_core(obj, part, prop); + lv_obj_state_t state_ori = obj->state; + obj->state = obj->prev_state; + lv_opa_t prev_opa = lv_obj_get_style_opa_core(obj, part, prop); + obj->state = state_ori; - lv_style_attr_t attr; - attr.full = prop >> 8; - - lv_opa_t value; - lv_res_t res = LV_RES_INV; - const lv_obj_t * parent = obj; - while(parent) { - lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); - - uint8_t state = lv_obj_get_state(parent, part); - prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); - - res = lv_style_dsc_get_opa(dsc, prop, &value); - if(res == LV_RES_OK) return value; - - if(attr.bits.inherit == 0) break; - - /*If not found, check the `MAIN` style first*/ - if(part != LV_OBJ_PART_MAIN) { - part = LV_OBJ_PART_MAIN; - continue; - } - - /*Check the parent too.*/ - parent = lv_obj_get_parent(parent); + if(obj->state_anim >= 255) return act_opa; + return prev_opa + (((act_opa - prev_opa) * obj->state_anim) >> 8); } - - prop = prop & (~LV_STYLE_STATE_MASK); - switch(prop) { - case LV_STYLE_OPA_SCALE: - case LV_STYLE_TEXT_OPA: - case LV_STYLE_IMAGE_OPA: - case LV_STYLE_LINE_OPA: - case LV_STYLE_BORDER_OPA: - return LV_OPA_COVER; - } - - return LV_OPA_TRANSP; } -void * lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +const void * lv_obj_get_style_ptr(lv_obj_t * obj, uint8_t part, lv_style_property_t prop) { - lv_style_property_t prop_ori = prop; + if(obj->state == obj->prev_state) { + return lv_obj_get_style_ptr_core(obj, part, prop); + } else { + if(obj->state_anim > 128) return lv_obj_get_style_ptr_core(obj, part, prop); - lv_style_attr_t attr; - attr.full = prop >> 8; - void * value; + lv_obj_state_t state_ori = obj->state; + obj->state = obj->prev_state; + void * prev_ptr = lv_obj_get_style_ptr_core(obj, part, prop); + obj->state = state_ori; - lv_res_t res = LV_RES_INV; - const lv_obj_t * parent = obj; - while(parent) { - lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); - - uint8_t state = lv_obj_get_state(parent, part); - prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); - - res = lv_style_dsc_get_ptr(dsc, prop, &value); - if(res == LV_RES_OK) return value; - - if(attr.bits.inherit == 0) break; - - /*If not found, check the `MAIN` style first*/ - if(part != LV_OBJ_PART_MAIN) { - part = LV_OBJ_PART_MAIN; - continue; - } - - /*Check the parent too.*/ - parent = lv_obj_get_parent(parent); + return prev_ptr; } - - - prop = prop & (~LV_STYLE_STATE_MASK); - switch(prop) { - case LV_STYLE_FONT: - return LV_FONT_DEFAULT; - } - - return NULL; } @@ -2681,79 +2575,10 @@ static void lv_obj_del_async_cb(void * obj) */ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t * draw_dsc) { -#if LV_DRAW_RECT_CACHE_SIZE - lv_draw_rect_cache_t * cached = NULL; - lv_style_dsc_t * s = lv_obj_get_style(obj, part); - lv_obj_state_t state = lv_obj_get_state(obj, part); - if(lv_refr_get_disp_refreshing() && s) { - uint32_t i; - for(i = 0; i < LV_DRAW_RECT_CACHE_SIZE; i++) { - int32_t c; - bool err = false; - if(lv_draw_rect_cache[i].style_dsc == NULL) continue; - if(lv_draw_rect_cache[i].style_dsc->class_cnt != s->class_cnt) continue; - if(lv_draw_rect_cache[i].state != state) continue; - for(c = 0; c < s->class_cnt; c++) { - lv_style_t * class1 = lv_style_dsc_get_class(lv_draw_rect_cache[i].style_dsc, c); - lv_style_t * class2 = lv_style_dsc_get_class(s, c); - if(class1 != class2) { - err = true; - break; - } - } - if(err == false) { - cached = &lv_draw_rect_cache[i]; - break; - } - } - } - static uint32_t hit = 1; - static uint32_t miss = 1; -// printf("hit: %d, miss:%d, pct:%d\n", hit, miss, hit * 100 / (hit+miss)); - - if(cached) { - hit++; - /*Load the cached data*/ - memcpy(draw_dsc, &cached->draw_dsc, sizeof(lv_draw_rect_dsc_t)); - - /*Get inherited properties because they can't be cached*/ - lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); - if(opa_scale <= LV_OPA_MIN) { - draw_dsc->bg_opa = LV_OPA_TRANSP; - draw_dsc->border_opa = LV_OPA_TRANSP; - draw_dsc->shadow_opa = LV_OPA_TRANSP; - } else if(opa_scale < LV_OPA_MAX) { - draw_dsc->bg_opa = (uint16_t)((uint16_t)draw_dsc->bg_opa * opa_scale) >> 8; - draw_dsc->border_opa = (uint16_t)((uint16_t)draw_dsc->border_opa * opa_scale) >> 8; - draw_dsc->shadow_opa = (uint16_t)((uint16_t)draw_dsc->shadow_opa * opa_scale) >> 8; - draw_dsc->pattern_opa = (uint16_t)((uint16_t)draw_dsc->pattern_opa * opa_scale) >> 8; - } - - draw_dsc->overlay_opa = lv_obj_get_style_opa(obj, part, LV_STYLE_OVERLAY_OPA); - if(draw_dsc->overlay_opa > LV_OPA_MIN) { - draw_dsc->overlay_color = lv_obj_get_style_color(obj, part, LV_STYLE_OVERLAY_COLOR); - } - - return; - } - miss++; -#endif - draw_dsc->radius = lv_obj_get_style_int(obj, part, LV_STYLE_RADIUS); lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); if(opa_scale <= LV_OPA_MIN) { - -#if LV_DRAW_RECT_CACHE_SIZE - if(lv_refr_get_disp_refreshing() && s) { - memcpy(&lv_draw_rect_cache[lv_draw_rect_cache_last].draw_dsc, draw_dsc, sizeof(lv_draw_rect_dsc_t)); - lv_draw_rect_cache[lv_draw_rect_cache_last].style_dsc = s; - lv_draw_rect_cache[lv_draw_rect_cache_last].state = state; - lv_draw_rect_cache_last++; - if(lv_draw_rect_cache_last >= LV_DRAW_RECT_CACHE_SIZE) lv_draw_rect_cache_last = 0; - } -#endif - draw_dsc->bg_opa = LV_OPA_TRANSP; draw_dsc->border_opa = LV_OPA_TRANSP; draw_dsc->shadow_opa = LV_OPA_TRANSP; @@ -2810,16 +2635,6 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t } } -#if LV_DRAW_RECT_CACHE_SIZE - if(lv_refr_get_disp_refreshing() && s) { - memcpy(&lv_draw_rect_cache[lv_draw_rect_cache_last].draw_dsc, draw_dsc, sizeof(lv_draw_rect_dsc_t)); - lv_draw_rect_cache[lv_draw_rect_cache_last].style_dsc = s; - lv_draw_rect_cache[lv_draw_rect_cache_last].state = state; - lv_draw_rect_cache_last++; - if(lv_draw_rect_cache_last >= LV_DRAW_RECT_CACHE_SIZE) lv_draw_rect_cache_last = 0; - } -#endif - if(opa_scale < LV_OPA_MAX) { draw_dsc->bg_opa = (uint16_t)((uint16_t)draw_dsc->bg_opa * opa_scale) >> 8; draw_dsc->border_opa = (uint16_t)((uint16_t)draw_dsc->border_opa * opa_scale) >> 8; @@ -3172,6 +2987,15 @@ static void base_dir_refr_children(lv_obj_t * obj) } } +static void obj_state_anim_cb(void * p, lv_anim_value_t value) +{ + lv_obj_t * obj = p; + obj->state_anim = value; + if(value == 255) obj->prev_state = obj->state; + + lv_obj_refresh_style(obj); +} + static void lv_event_mark_deleted(lv_obj_t * obj) { @@ -3182,3 +3006,178 @@ static void lv_event_mark_deleted(lv_obj_t * obj) t = t->prev; } } + +static lv_style_int_t lv_obj_get_style_int_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +{ + lv_style_property_t prop_ori = prop; + + lv_style_attr_t attr; + attr.full = prop >> 8; + + lv_style_int_t value; + lv_res_t res = LV_RES_INV; + const lv_obj_t * parent = obj; + while(parent) { + lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); + + uint8_t state = lv_obj_get_state(parent, part); + prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); + + res = lv_style_dsc_get_int(dsc, prop, &value); + if(res == LV_RES_OK) return value; + + if(attr.bits.inherit == 0) break; + + /*If not found, check the `MAIN` style first*/ + if(part != LV_OBJ_PART_MAIN) { + part = LV_OBJ_PART_MAIN; + continue; + } + + /*Check the parent too.*/ + parent = lv_obj_get_parent(parent); + } + + prop = prop & (~LV_STYLE_STATE_MASK); + switch(prop) { + case LV_STYLE_BORDER_SIDE: + return LV_BORDER_SIDE_FULL; + case LV_STYLE_SIZE: + return LV_DPI / 10; + case LV_STYLE_SCALE_WIDTH: + return LV_DPI / 8; + } + + return 0; +} + + +static lv_color_t lv_obj_get_style_color_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +{ + lv_style_property_t prop_ori = prop; + + lv_style_attr_t attr; + attr.full = prop >> 8; + + lv_color_t value; + lv_res_t res = LV_RES_INV; + const lv_obj_t * parent = obj; + while(parent) { + lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); + + uint8_t state = lv_obj_get_state(parent, part); + prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); + + res = lv_style_dsc_get_color(dsc, prop, &value); + if(res == LV_RES_OK) return value; + + if(attr.bits.inherit == 0) break; + + /*If not found, check the `MAIN` style first*/ + if(part != LV_OBJ_PART_MAIN) { + part = LV_OBJ_PART_MAIN; + continue; + } + + /*Check the parent too.*/ + parent = lv_obj_get_parent(parent); + } + + /*Handle unset values*/ + prop = prop & (~LV_STYLE_STATE_MASK); + switch(prop) { + case LV_STYLE_TEXT_COLOR: + case LV_STYLE_BORDER_COLOR: + case LV_STYLE_SHADOW_COLOR: + return LV_COLOR_BLACK; + } + + return LV_COLOR_WHITE; +} + +static lv_opa_t lv_obj_get_style_opa_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +{ + lv_style_property_t prop_ori = prop; + + lv_style_attr_t attr; + attr.full = prop >> 8; + + lv_opa_t value; + lv_res_t res = LV_RES_INV; + const lv_obj_t * parent = obj; + while(parent) { + lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); + + uint8_t state = lv_obj_get_state(parent, part); + prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); + + res = lv_style_dsc_get_opa(dsc, prop, &value); + if(res == LV_RES_OK) return value; + + if(attr.bits.inherit == 0) break; + + /*If not found, check the `MAIN` style first*/ + if(part != LV_OBJ_PART_MAIN) { + part = LV_OBJ_PART_MAIN; + continue; + } + + /*Check the parent too.*/ + parent = lv_obj_get_parent(parent); + } + + prop = prop & (~LV_STYLE_STATE_MASK); + switch(prop) { + case LV_STYLE_OPA_SCALE: + case LV_STYLE_TEXT_OPA: + case LV_STYLE_IMAGE_OPA: + case LV_STYLE_LINE_OPA: + case LV_STYLE_BORDER_OPA: + case LV_STYLE_PATTERN_OPA: + return LV_OPA_COVER; + } + + return LV_OPA_TRANSP; +} + +static const void * lv_obj_get_style_ptr_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +{ + lv_style_property_t prop_ori = prop; + + lv_style_attr_t attr; + attr.full = prop >> 8; + void * value; + + lv_res_t res = LV_RES_INV; + const lv_obj_t * parent = obj; + while(parent) { + lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); + + uint8_t state = lv_obj_get_state(parent, part); + prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); + + res = lv_style_dsc_get_ptr(dsc, prop, &value); + if(res == LV_RES_OK) return value; + + if(attr.bits.inherit == 0) break; + + /*If not found, check the `MAIN` style first*/ + if(part != LV_OBJ_PART_MAIN) { + part = LV_OBJ_PART_MAIN; + continue; + } + + /*Check the parent too.*/ + parent = lv_obj_get_parent(parent); + } + + + prop = prop & (~LV_STYLE_STATE_MASK); + switch(prop) { + case LV_STYLE_FONT: + return LV_FONT_DEFAULT; + } + + return NULL; +} + diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index f48f1f4bc..b0f4e4567 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -867,13 +867,13 @@ lv_coord_t lv_obj_get_ext_draw_pad(const lv_obj_t * obj); lv_style_dsc_t * lv_obj_get_style(const lv_obj_t * obj, uint8_t type); -lv_style_int_t lv_obj_get_style_int(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop); +lv_style_int_t lv_obj_get_style_int(lv_obj_t * obj, uint8_t type, lv_style_property_t prop); lv_color_t lv_obj_get_style_color(lv_obj_t * obj, uint8_t type, lv_style_property_t prop); -lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop); +lv_opa_t lv_obj_get_style_opa(lv_obj_t * obj, uint8_t type, lv_style_property_t prop); -void * lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop); +const void * lv_obj_get_style_ptr(lv_obj_t * obj, uint8_t type, lv_style_property_t prop); ///** // * Get the style pointer of an object (if NULL get style of the parent) // * @param obj pointer to an object diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index 716136c56..0da1e933d 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -76,6 +76,7 @@ typedef union { enum { LV_STYLE_PROP_INIT(LV_STYLE_RADIUS, 0x0, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_CLIP_CORNER, 0x0, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_TIME, 0x0, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_OPA_SCALE, 0x0, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT), LV_STYLE_PROP_INIT(LV_STYLE_PAD_TOP, 0x1, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), diff --git a/src/lv_objx/lv_btnm.c b/src/lv_objx/lv_btnm.c index 6839cec8e..2ed6ecc56 100644 --- a/src/lv_objx/lv_btnm.c +++ b/src/lv_objx/lv_btnm.c @@ -692,6 +692,7 @@ static lv_design_res_t lv_btnm_design(lv_obj_t * btnm, const lv_area_t * clip_ar if(tgl_state) btnm->state = LV_OBJ_STATE_CHECKED; if(ext->btn_id_pr == btn_i) btnm->state |= LV_OBJ_STATE_PRESSED; if(ext->btn_id_focused == btn_i) btnm->state |= LV_OBJ_STATE_FOCUS; + btnm->prev_state = btnm->state; lv_draw_rect_dsc_init(&draw_rect_tmp_dsc); lv_draw_label_dsc_init(&draw_label_tmp_dsc); lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_tmp_dsc); @@ -699,6 +700,7 @@ static lv_design_res_t lv_btnm_design(lv_obj_t * btnm, const lv_area_t * clip_ar draw_rect_dsc_act = &draw_rect_tmp_dsc; draw_label_dsc_act = &draw_label_tmp_dsc; btnm->state = state_ori; + btnm->state = prev_state_ori; // btnm->style_dsc.cache.enabled = 1; } diff --git a/src/lv_objx/lv_table.c b/src/lv_objx/lv_table.c index 26f8c214c..e9df79789 100644 --- a/src/lv_objx/lv_table.c +++ b/src/lv_objx/lv_table.c @@ -29,6 +29,7 @@ **********************/ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param); +static lv_style_dsc_t * lv_table_get_style(lv_obj_t * table, uint8_t part); static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id); static void refr_size(lv_obj_t * table); @@ -74,14 +75,14 @@ lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy) /*Initialize the allocated 'ext' */ ext->cell_data = NULL; - ext->cell_style[0] = &lv_style_plain; - ext->cell_style[1] = &lv_style_plain; - ext->cell_style[2] = &lv_style_plain; - ext->cell_style[3] = &lv_style_plain; ext->col_cnt = 0; ext->row_cnt = 0; uint16_t i; + for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) { + lv_style_dsc_init(&ext->cell_style[i]); + } + for(i = 0; i < LV_TABLE_COL_MAX; i++) { ext->col_w[i] = LV_DPI; } @@ -92,26 +93,19 @@ lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new table table*/ if(copy == NULL) { - /*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->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); - } - lv_obj_set_click(new_table, false); /*Can be removed if click support is added*/ + lv_obj_add_style_theme(new_table, LV_TABLE_PART_BG, LV_THEME_TABLE_BG); + lv_obj_add_style_theme(new_table, LV_TABLE_PART_CELL1, LV_THEME_TABLE_CELL1); + lv_obj_add_style_theme(new_table, LV_TABLE_PART_CELL2, LV_THEME_TABLE_CELL2); + lv_obj_add_style_theme(new_table, LV_TABLE_PART_CELL3, LV_THEME_TABLE_CELL3); + lv_obj_add_style_theme(new_table, LV_TABLE_PART_CELL4, LV_THEME_TABLE_CELL4); } /*Copy an existing table*/ else { lv_table_ext_t * copy_ext = lv_obj_get_ext_attr(copy); - ext->cell_style[0] = copy_ext->cell_style[0]; - ext->cell_style[1] = copy_ext->cell_style[1]; - ext->cell_style[2] = copy_ext->cell_style[2]; - ext->cell_style[3] = copy_ext->cell_style[3]; +// ext->cell_style[0] = copy_ext->cell_style[0]; +// ext->cell_style[1] = copy_ext->cell_style[1]; +// ext->cell_style[2] = copy_ext->cell_style[2]; +// ext->cell_style[3] = copy_ext->cell_style[3]; lv_table_set_row_cnt(new_table, copy_ext->row_cnt); lv_table_set_col_cnt(new_table, copy_ext->col_cnt); @@ -385,42 +379,6 @@ void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, refr_size(table); } -/** - * Set a style of a table. - * @param table pointer to table object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_table_set_style(lv_obj_t * table, lv_table_style_t type, const lv_style_t * style) -{ - LV_ASSERT_OBJ(table, LV_OBJX_NAME); - - lv_table_ext_t * ext = lv_obj_get_ext_attr(table); - - switch(type) { - case LV_TABLE_STYLE_BG: - lv_obj_set_style(table, style); - refr_size(table); - break; - case LV_TABLE_STYLE_CELL1: - ext->cell_style[0] = style; - refr_size(table); - break; - case LV_TABLE_STYLE_CELL2: - ext->cell_style[1] = style; - refr_size(table); - break; - case LV_TABLE_STYLE_CELL3: - ext->cell_style[2] = style; - refr_size(table); - break; - case LV_TABLE_STYLE_CELL4: - ext->cell_style[3] = style; - refr_size(table); - break; - } -} - /*===================== * Getter functions *====================*/ @@ -603,31 +561,6 @@ bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col) } } -/** - * Get style of a table. - * @param table pointer to table object - * @param type which style should be get - * @return style pointer to the style - */ -const lv_style_t * lv_table_get_style(const lv_obj_t * table, lv_table_style_t type) -{ - LV_ASSERT_OBJ(table, LV_OBJX_NAME); - - lv_table_ext_t * ext = lv_obj_get_ext_attr(table); - const lv_style_t * style = NULL; - - switch(type) { - case LV_TABLE_STYLE_BG: style = lv_obj_get_style(table); break; - case LV_TABLE_STYLE_CELL1: style = ext->cell_style[0]; break; - case LV_TABLE_STYLE_CELL2: style = ext->cell_style[1]; break; - case LV_TABLE_STYLE_CELL3: style = ext->cell_style[2]; break; - case LV_TABLE_STYLE_CELL4: style = ext->cell_style[3]; break; - default: return NULL; - } - - return style; -} - /********************** * STATIC FUNCTIONS **********************/ @@ -653,26 +586,52 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ ancestor_scrl_design(table, clip_area, mode); lv_table_ext_t * ext = lv_obj_get_ext_attr(table); - const lv_style_t * bg_style = lv_obj_get_style(table); lv_coord_t h_row; lv_point_t txt_size; lv_area_t cell_area; lv_area_t txt_area; lv_txt_flag_t txt_flags; - lv_opa_t opa_scale = lv_obj_get_opa_scale(table); + + lv_style_int_t bg_top = lv_obj_get_style_int(table, LV_TABLE_PART_BG, LV_STYLE_PAD_TOP); + lv_style_int_t bg_left= lv_obj_get_style_int(table, LV_TABLE_PART_BG, LV_STYLE_PAD_LEFT); + + lv_draw_rect_dsc_t rect_dsc[LV_TABLE_CELL_STYLE_CNT]; + lv_draw_label_dsc_t label_dsc[LV_TABLE_CELL_STYLE_CNT]; + lv_draw_line_dsc_t line_dsc[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_left[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_right[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_top[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_bottom[LV_TABLE_CELL_STYLE_CNT]; + + uint16_t i; + for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) { + lv_draw_rect_dsc_init(&rect_dsc[i]); + lv_obj_init_draw_rect_dsc(table, LV_TABLE_PART_CELL1 + i, &rect_dsc[i]); + + lv_draw_label_dsc_init(&label_dsc[i]); + lv_obj_init_draw_label_dsc(table, LV_TABLE_PART_CELL1 + i, &label_dsc[i]); + + lv_draw_line_dsc_init(&line_dsc[i]); + lv_obj_init_draw_line_dsc(table, LV_TABLE_PART_CELL1 + i, &line_dsc[i]); + + cell_left[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_LEFT); + cell_right[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_RIGHT); + cell_top[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_TOP); + cell_bottom[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_BOTTOM); + } uint16_t col; uint16_t row; uint16_t cell = 0; - cell_area.y2 = table->coords.y1 + bg_style->body.padding.top; + cell_area.y2 = table->coords.y1 + bg_top; for(row = 0; row < ext->row_cnt; row++) { h_row = get_row_height(table, row); cell_area.y1 = cell_area.y2 + 1; cell_area.y2 = cell_area.y1 + h_row - 1; - cell_area.x2 = table->coords.x1 + bg_style->body.padding.left; + cell_area.x2 = table->coords.x1 + bg_left; for(col = 0; col < ext->col_cnt; col++) { @@ -687,8 +646,6 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ } - lv_style_t cell_style; - lv_style_copy(&cell_style, ext->cell_style[format.s.type]); cell_area.x1 = cell_area.x2 + 1; cell_area.x2 = cell_area.x1 + ext->col_w[col] - 1; @@ -706,14 +663,18 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ } } - lv_draw_rect(&cell_area, clip_area, &cell_style, opa_scale); + + uint8_t cell_type = format.s.type; + + lv_draw_rect(&cell_area, clip_area, &rect_dsc[cell_type]); if(ext->cell_data[cell]) { - txt_area.x1 = cell_area.x1 + cell_style.body.padding.left; - txt_area.x2 = cell_area.x2 - cell_style.body.padding.right; - txt_area.y1 = cell_area.y1 + cell_style.body.padding.top; - txt_area.y2 = cell_area.y2 - cell_style.body.padding.bottom; + txt_area.x1 = cell_area.x1 + cell_left[cell_type]; + txt_area.x2 = cell_area.x2 - cell_right[cell_type]; + txt_area.y1 = cell_area.y1 + cell_top[cell_type]; + txt_area.y2 = cell_area.y2 - cell_bottom[cell_type]; + /*Align the content to the middle if not cropped*/ if(format.s.crop == 0) { txt_flags = LV_TXT_FLAG_NONE; @@ -721,8 +682,8 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ txt_flags = LV_TXT_FLAG_EXPAND; } - lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style.text.font, - cell_style.text.letter_space, cell_style.text.line_space, + lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, label_dsc[cell_type].font, + label_dsc[cell_type].letter_space, label_dsc[cell_type].line_space, lv_area_get_width(&txt_area), txt_flags); /*Align the content to the middle if not cropped*/ @@ -731,19 +692,19 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ txt_area.y2 = cell_area.y1 + h_row / 2 + txt_size.y / 2; } + label_dsc[cell_type].flag = 0; switch(format.s.align) { default: - case LV_LABEL_ALIGN_LEFT: txt_flags |= LV_TXT_FLAG_NONE; break; - case LV_LABEL_ALIGN_RIGHT: txt_flags |= LV_TXT_FLAG_RIGHT; break; - case LV_LABEL_ALIGN_CENTER: txt_flags |= LV_TXT_FLAG_CENTER; break; + case LV_LABEL_ALIGN_LEFT: label_dsc[cell_type].flag |= LV_TXT_FLAG_NONE; break; + case LV_LABEL_ALIGN_RIGHT: label_dsc[cell_type].flag |= LV_TXT_FLAG_RIGHT; break; + case LV_LABEL_ALIGN_CENTER: label_dsc[cell_type].flag |= LV_TXT_FLAG_CENTER; break; } lv_area_t label_mask; bool label_mask_ok; label_mask_ok = lv_area_intersect(&label_mask, clip_area, &cell_area); if(label_mask_ok) { - lv_draw_label(&txt_area, &label_mask, &cell_style, opa_scale, ext->cell_data[cell] + 1, - txt_flags, NULL, NULL, NULL, lv_obj_get_base_dir(table)); + lv_draw_label(&txt_area, &label_mask, &label_dsc[cell_type], ext->cell_data[cell] + 1, NULL); } /*Draw lines after '\n's*/ lv_point_t p1; @@ -754,13 +715,13 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ for(i = 1; ext->cell_data[cell][i] != '\0'; i++) { if(ext->cell_data[cell][i] == '\n') { ext->cell_data[cell][i] = '\0'; - lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style.text.font, - cell_style.text.letter_space, cell_style.text.line_space, + lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, label_dsc[cell_type].font, + label_dsc[cell_type].letter_space, label_dsc[cell_type].line_space, lv_area_get_width(&txt_area), txt_flags); - p1.y = txt_area.y1 + txt_size.y + cell_style.text.line_space / 2; - p2.y = txt_area.y1 + txt_size.y + cell_style.text.line_space / 2; - lv_draw_line(&p1, &p2, clip_area, &cell_style, opa_scale); + p1.y = txt_area.y1 + txt_size.y + label_dsc[cell_type].line_space / 2; + p2.y = txt_area.y1 + txt_size.y + label_dsc[cell_type].line_space / 2; + lv_draw_line(&p1, &p2, clip_area, &line_dsc[cell_type]); ext->cell_data[cell][i] = '\n'; } @@ -789,6 +750,12 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param) { lv_res_t res; + if(sign == LV_SIGNAL_GET_STYLE) { + lv_get_style_info_t * info = param; + info->result = lv_table_get_style(table, info->part); + if(info->result != NULL) return LV_RES_OK; + else return ancestor_signal(table, sign, param); + } /* Include the ancient signal function */ res = ancestor_signal(table, sign, param); @@ -808,10 +775,50 @@ static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param if(ext->cell_data != NULL) lv_mem_free(ext->cell_data); } + else if(sign == LV_SIGNAL_STYLE_CHG) { + refr_size(table); + } return res; } + +/** + * Get the style descriptor of a part of the object + * @param table pointer the object + * @param part the part from. (LV_TABLE_PART_...) + * @return pointer to the style descriptor of the specified part + */ +static lv_style_dsc_t * lv_table_get_style(lv_obj_t * table, uint8_t part) +{ + LV_ASSERT_OBJ(table, LV_OBJX_NAME); + + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + lv_style_dsc_t * style_dsc_p; + + switch(part) { + case LV_TABLE_PART_BG: + style_dsc_p = &table->style_dsc; + break; + case LV_TABLE_PART_CELL1: + style_dsc_p = &ext->cell_style[0]; + break; + case LV_TABLE_PART_CELL2: + style_dsc_p = &ext->cell_style[1]; + break; + case LV_TABLE_PART_CELL3: + style_dsc_p = &ext->cell_style[2]; + break; + case LV_TABLE_PART_CELL4: + style_dsc_p = &ext->cell_style[3]; + break; + default: + style_dsc_p = NULL; + } + + return style_dsc_p; +} + static void refr_size(lv_obj_t * table) { lv_coord_t h = 0; @@ -827,10 +834,12 @@ static void refr_size(lv_obj_t * table) h += get_row_height(table, i); } - const lv_style_t * bg_style = lv_obj_get_style(table); - - w += bg_style->body.padding.left + bg_style->body.padding.right; - h += bg_style->body.padding.top + bg_style->body.padding.bottom; + lv_style_int_t bg_top = lv_obj_get_style_int(table, LV_TABLE_PART_BG, LV_STYLE_PAD_TOP); + lv_style_int_t bg_bottom= lv_obj_get_style_int(table, LV_TABLE_PART_BG, LV_STYLE_PAD_BOTTOM); + lv_style_int_t bg_left = lv_obj_get_style_int(table, LV_TABLE_PART_BG, LV_STYLE_PAD_LEFT); + lv_style_int_t bg_right= lv_obj_get_style_int(table, LV_TABLE_PART_BG, LV_STYLE_PAD_RIGHT); + w += bg_left + bg_right; + h += bg_top + bg_bottom; lv_obj_set_size(table, w + 1, h + 1); lv_obj_invalidate(table); @@ -841,13 +850,29 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id) lv_table_ext_t * ext = lv_obj_get_ext_attr(table); lv_point_t txt_size; lv_coord_t txt_w; - const lv_style_t * cell_style; + + lv_draw_label_dsc_t label_dsc[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_left[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_right[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_top[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_bottom[LV_TABLE_CELL_STYLE_CNT]; + + uint16_t i; + for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) { + lv_draw_label_dsc_init(&label_dsc[i]); + lv_obj_init_draw_label_dsc(table, LV_TABLE_PART_CELL1 + i, &label_dsc[i]); + + cell_left[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_LEFT); + cell_right[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_RIGHT); + cell_top[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_TOP); + cell_bottom[i] = lv_obj_get_style_int(table, LV_TABLE_PART_CELL1 + i, LV_STYLE_PAD_BOTTOM); + } + uint16_t row_start = row_id * ext->col_cnt; uint16_t cell; uint16_t col; - lv_coord_t h_max = lv_font_get_line_height(ext->cell_style[0]->text.font) + ext->cell_style[0]->body.padding.top + - ext->cell_style[0]->body.padding.bottom; + lv_coord_t h_max = lv_font_get_line_height(label_dsc[0].font) + cell_top[0] + cell_bottom[0]; for(cell = row_start, col = 0; cell < row_start + ext->col_cnt; cell++, col++) { if(ext->cell_data[cell] != NULL) { @@ -870,22 +895,21 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id) lv_table_cell_format_t format; format.format_byte = ext->cell_data[cell][0]; - cell_style = ext->cell_style[format.s.type]; + uint8_t cell_type = format.s.type; /*With text crop assume 1 line*/ if(format.s.crop) { - h_max = LV_MATH_MAX(lv_font_get_line_height(cell_style->text.font) + cell_style->body.padding.top + - cell_style->body.padding.bottom, + h_max = LV_MATH_MAX(lv_font_get_line_height(label_dsc[cell_type].font) + cell_top[cell_type] + cell_bottom[cell_type], h_max); } /*Without text crop calculate the height of the text in the cell*/ else { - txt_w -= cell_style->body.padding.left + cell_style->body.padding.right; + txt_w -= cell_left[cell_type] + cell_right[cell_type]; - lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style->text.font, - cell_style->text.letter_space, cell_style->text.line_space, txt_w, LV_TXT_FLAG_NONE); + lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, label_dsc[cell_type].font, + label_dsc[cell_type].letter_space, label_dsc[cell_type].line_space, txt_w, LV_TXT_FLAG_NONE); - h_max = LV_MATH_MAX(txt_size.y + cell_style->body.padding.top + cell_style->body.padding.bottom, h_max); + h_max = LV_MATH_MAX(txt_size.y + cell_top[cell_type] + cell_bottom[cell_type], h_max); cell += col_merge; col += col_merge; } diff --git a/src/lv_objx/lv_table.h b/src/lv_objx/lv_table.h index e6856e08e..7bb747b0e 100644 --- a/src/lv_objx/lv_table.h +++ b/src/lv_objx/lv_table.h @@ -61,19 +61,18 @@ typedef struct uint16_t col_cnt; uint16_t row_cnt; char ** cell_data; - const lv_style_t * cell_style[LV_TABLE_CELL_STYLE_CNT]; + lv_style_dsc_t cell_style[LV_TABLE_CELL_STYLE_CNT]; lv_coord_t col_w[LV_TABLE_COL_MAX]; } lv_table_ext_t; -/*Styles*/ +/*Parts of the table*/ enum { - LV_TABLE_STYLE_BG, - LV_TABLE_STYLE_CELL1, - LV_TABLE_STYLE_CELL2, - LV_TABLE_STYLE_CELL3, - LV_TABLE_STYLE_CELL4, + LV_TABLE_PART_BG, + LV_TABLE_PART_CELL1, + LV_TABLE_PART_CELL2, + LV_TABLE_PART_CELL3, + LV_TABLE_PART_CELL4, }; -typedef uint8_t lv_table_style_t; /********************** * GLOBAL PROTOTYPES @@ -159,14 +158,6 @@ void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool c */ void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, bool en); -/** - * Set a style of a table. - * @param table pointer to table object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_table_set_style(lv_obj_t * table, lv_table_style_t type, const lv_style_t * style); - /*===================== * Getter functions *====================*/ @@ -239,14 +230,6 @@ lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t */ bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col); -/** - * Get style of a table. - * @param table pointer to table object - * @param type which style should be get - * @return style pointer to the style - */ -const lv_style_t * lv_table_get_style(const lv_obj_t * table, lv_table_style_t type); - /*===================== * Other functions *====================*/ diff --git a/src/lv_themes/lv_theme.c b/src/lv_themes/lv_theme.c index a2d57ca57..de9629700 100644 --- a/src/lv_themes/lv_theme.c +++ b/src/lv_themes/lv_theme.c @@ -59,7 +59,7 @@ lv_style_t * lv_theme_get_style(lv_theme_style_t name) } -void lv_obj_add_style_theme(lv_obj_t * obj, uint8_t part, lv_theme_style_t name) +void lv_obj_add_style_theme(void * obj, uint8_t part, lv_theme_style_t name) { lv_obj_add_style_class(obj, part, lv_theme_get_style(name)); } diff --git a/src/lv_themes/lv_theme.h b/src/lv_themes/lv_theme.h index 4d4de7716..ab4165f2d 100644 --- a/src/lv_themes/lv_theme.h +++ b/src/lv_themes/lv_theme.h @@ -118,6 +118,12 @@ typedef enum { LV_THEME_MBOX_BG, LV_THEME_MBOX_BTN_BG, LV_THEME_MBOX_BTN, + + LV_THEME_TABLE_BG, + LV_THEME_TABLE_CELL1, + LV_THEME_TABLE_CELL2, + LV_THEME_TABLE_CELL3, + LV_THEME_TABLE_CELL4, }lv_theme_style_t; typedef struct { @@ -143,6 +149,8 @@ lv_theme_t * lv_theme_get_act(void); lv_style_t * lv_theme_get_style(lv_theme_style_t name); +void lv_obj_add_style_theme(void * obj, uint8_t part, lv_theme_style_t name); + /********************** * MACROS **********************/ diff --git a/src/lv_themes/lv_theme_alien.c b/src/lv_themes/lv_theme_alien.c index c25e21e8b..9944660af 100644 --- a/src/lv_themes/lv_theme_alien.c +++ b/src/lv_themes/lv_theme_alien.c @@ -70,6 +70,10 @@ static lv_style_t arc_bg; static lv_style_t calendar_date_nums; #endif +#if LV_USE_TABLE +static lv_style_t table_cell; +#endif + /********************** * MACROS **********************/ @@ -122,6 +126,7 @@ static void basic_init(void) lv_style_set_color(&btn, LV_STYLE_BG_COLOR | LV_STYLE_STATE_CHECKED, LV_COLOR_BLUE); lv_style_set_color(&btn, LV_STYLE_TEXT_COLOR, LV_COLOR_LIME); lv_style_set_color(&btn, LV_STYLE_IMAGE_RECOLOR, LV_COLOR_LIME); + lv_style_set_int(&btn, LV_STYLE_RADIUS | LV_STYLE_STATE_PRESSED, LV_RADIUS_CIRCLE); lv_style_set_color(&btn, LV_STYLE_TEXT_COLOR | LV_STYLE_STATE_PRESSED, LV_COLOR_BLUE); lv_style_set_color(&btn, LV_STYLE_IMAGE_RECOLOR | LV_STYLE_STATE_PRESSED, LV_COLOR_BLUE); lv_style_set_ptr(&btn, LV_STYLE_FONT | LV_STYLE_STATE_PRESSED, &lv_font_roboto_28); @@ -133,6 +138,7 @@ static void basic_init(void) lv_style_set_int(&btn, LV_STYLE_PATTERN_REPEATE | LV_STYLE_STATE_CHECKED, 1); lv_style_set_int(&btn, LV_STYLE_SHADOW_WIDTH, 5); lv_style_set_int(&btn, LV_STYLE_SHADOW_OFFSET_Y, 3); + lv_style_set_int(&btn, LV_STYLE_TRANSITION_TIME, 200); lv_style_set_ptr(&btn, LV_STYLE_FONT | LV_STYLE_STATE_CHECKED, &lv_font_roboto_12); lv_style_init(&transp_tight); @@ -501,17 +507,16 @@ static void tileview_init(void) static void table_init(void) { #if LV_USE_TABLE != 0 - static lv_style_t cell; - lv_style_copy(&cell, &panel); - cell.body.radius = 0; - cell.body.border.width = 1; - cell.body.padding.left = LV_DPI / 12; - cell.body.padding.right = LV_DPI / 12; - cell.body.padding.top = LV_DPI / 12; - cell.body.padding.bottom = LV_DPI / 12; + lv_style_init(&table_cell); + lv_style_set_opa(&table_cell, LV_STYLE_BG_OPA, LV_OPA_COVER); + lv_style_set_color(&table_cell, LV_STYLE_BG_COLOR, LV_COLOR_WHITE); + lv_style_set_color(&table_cell, LV_STYLE_BORDER_COLOR, LV_COLOR_BLACK); + lv_style_set_int(&table_cell, LV_STYLE_BORDER_WIDTH, 1); + lv_style_set_int(&table_cell, LV_STYLE_PAD_LEFT, LV_DPI/20); + lv_style_set_int(&table_cell, LV_STYLE_PAD_RIGHT, LV_DPI/20); + lv_style_set_int(&table_cell, LV_STYLE_PAD_TOP, LV_DPI/20); + lv_style_set_int(&table_cell, LV_STYLE_PAD_BOTTOM, LV_DPI/20); - theme.style.table.bg = &lv_style_transp_tight; - theme.style.table.cell = &cell; #endif } @@ -699,6 +704,17 @@ lv_style_t * lv_theme_alien_get_style(lv_theme_style_t name) case LV_THEME_MBOX_BTN: return &btn; #endif + +#if LV_USE_TABLE + case LV_THEME_TABLE_BG: + return &panel; + case LV_THEME_TABLE_CELL1: + case LV_THEME_TABLE_CELL2: + case LV_THEME_TABLE_CELL3: + case LV_THEME_TABLE_CELL4: + return &table_cell; +#endif + } return NULL;