From 73614e6b22002511c86f8e1a7e02f5d8641bcf94 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 5 Jan 2020 20:05:11 +0100 Subject: [PATCH] start to separate virtual and real object parts --- src/lv_core/lv_obj.c | 33 ++++++++++++++++++--------------- src/lv_core/lv_obj.h | 14 ++++++++++++-- src/lv_objx/lv_btn.c | 4 ++-- src/lv_objx/lv_list.c | 2 +- src/lv_objx/lv_list.h | 7 ++++--- src/lv_objx/lv_page.c | 9 +++++++-- src/lv_objx/lv_page.h | 7 ++++--- 7 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index cfa6fb1e8..906812c72 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -2138,7 +2138,7 @@ lv_style_value_t lv_obj_get_style_value(const lv_obj_t * obj, uint8_t part, lv_s lv_style_attr_t attr; attr.full = prop >> 8; - int16_t weight_goal = lv_obj_get_state(obj); + int16_t weight_goal = lv_obj_get_state(obj, part); int16_t weight = -1; lv_style_value_t value; @@ -2147,7 +2147,7 @@ lv_style_value_t lv_obj_get_style_value(const lv_obj_t * obj, uint8_t part, lv_s lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); if(dsc == NULL) continue; - state = lv_obj_get_state(parent); + state = lv_obj_get_state(parent, part); prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); int16_t weight_act; @@ -2223,7 +2223,7 @@ lv_color_t lv_obj_get_style_color(const lv_obj_t * obj, uint8_t part, lv_style_p lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); if(dsc == NULL) continue; - state = lv_obj_get_state(parent); + state = lv_obj_get_state(parent, part); int16_t weight_goal = state; prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); @@ -2331,7 +2331,7 @@ lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_prope lv_style_attr_t attr; attr.full = prop >> 8; - int16_t weight_goal = lv_obj_get_state(obj); + int16_t weight_goal = lv_obj_get_state(obj, part); int16_t weight = -1; lv_opa_t value; @@ -2340,7 +2340,7 @@ lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_prope lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); if(dsc == NULL) continue; - state = lv_obj_get_state(parent); + state = lv_obj_get_state(parent, part); prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); int16_t weight_act; @@ -2423,7 +2423,7 @@ void * lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_propert lv_style_dsc_t * dsc = lv_obj_get_style(parent, part); if(dsc == NULL) continue; - state = lv_obj_get_state(parent); + state = lv_obj_get_state(parent, part); int16_t weight_goal = state; prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); @@ -2648,22 +2648,25 @@ bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot) return (obj->protect & prot) == 0 ? false : true; } -lv_obj_state_t lv_obj_get_state(const lv_obj_t * obj) +lv_obj_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - return obj->state; + if(part < _LV_OBJ_PART_REAL_START) return obj->state; - uint8_t state = 0; + /*If a real part is asked, then use the object's signal to get its state. + * A real object can be in different state then the main part + * and only the object itseld knows who to get it's state. */ + lv_get_state_info_t info; + info.part = part; + info.result = 0; + lv_res_t res; + res = lv_signal_send((lv_obj_t*)obj, LV_SIGNAL_GET_STATE, &info); - const lv_obj_t * parent = obj; - while(parent) { - state |= parent->state; - parent = lv_obj_get_parent(parent); - } + if(res != LV_RES_OK) return 0; + return info.result; - return state; } /** diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 8183f8d76..469cb37ce 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -46,6 +46,10 @@ extern "C" { #define LV_EXT_CLICK_AREA_TINY 1 #define LV_EXT_CLICK_AREA_FULL 2 +#define _LV_OBJ_PART_MAIN_VALUE 0x00 +#define _LV_OBJ_PART_VIRTUAL_START 0x01 +#define _LV_OBJ_PART_REAL_START 0x40 + /********************** * TYPEDEFS **********************/ @@ -280,12 +284,18 @@ typedef struct ... [x]: "lv_obj" */ } lv_obj_type_t; -typedef struct _lv_hit_test_info_t +typedef struct { lv_point_t *point; bool result; } lv_hit_test_info_t; +typedef struct +{ + uint8_t part; + lv_obj_state_t result; +} lv_get_state_info_t; + /********************** * GLOBAL PROTOTYPES **********************/ @@ -966,7 +976,7 @@ uint8_t lv_obj_get_protect(const lv_obj_t * obj); */ bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot); -lv_obj_state_t lv_obj_get_state(const lv_obj_t * obj); +lv_obj_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part); /** * Get the signal function of an object diff --git a/src/lv_objx/lv_btn.c b/src/lv_objx/lv_btn.c index 1ae8e3f94..6047efc98 100644 --- a/src/lv_objx/lv_btn.c +++ b/src/lv_objx/lv_btn.c @@ -189,7 +189,7 @@ void lv_btn_toggle(lv_obj_t * btn) { LV_ASSERT_OBJ(btn, LV_OBJX_NAME); - if(lv_obj_get_state(btn) & LV_OBJ_STATE_CHECKED) { + if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_OBJ_STATE_CHECKED) { lv_obj_clear_state(btn, LV_OBJ_STATE_CHECKED); } else { lv_obj_set_state(btn, LV_OBJ_STATE_CHECKED); @@ -270,7 +270,7 @@ lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn) { LV_ASSERT_OBJ(btn, LV_OBJX_NAME); - lv_obj_state_t state = lv_obj_get_state(btn); + lv_obj_state_t state = lv_obj_get_state(btn, LV_BTN_PART_MAIN); if(state & LV_OBJ_STATE_CHECKED) { if(state & LV_OBJ_STATE_PRESSED) return LV_BTN_STATE_TGL_PR; diff --git a/src/lv_objx/lv_list.c b/src/lv_objx/lv_list.c index 5c550c9e7..0d90574f7 100644 --- a/src/lv_objx/lv_list.c +++ b/src/lv_objx/lv_list.c @@ -929,7 +929,7 @@ static lv_style_dsc_t * lv_list_get_style(lv_obj_t * list, uint8_t part) style_dsc_p = &ext->page.sb.style; break; #if LV_USE_ANIMATION - case LV_PAGE_PART_EDGE_FLASH: + case LV_LIST_PART_EDGE_FLASH: style_dsc_p = &ext->page.edge_flash.style; break; #endif diff --git a/src/lv_objx/lv_list.h b/src/lv_objx/lv_list.h index f183268db..546d3b703 100644 --- a/src/lv_objx/lv_list.h +++ b/src/lv_objx/lv_list.h @@ -63,10 +63,11 @@ typedef struct /** List styles. */ enum { - LV_LIST_PART_BG, /**< List background style */ - LV_LIST_PART_SCRL, /**< List scrollable area style. */ - LV_LIST_PART_SCRLBAR, /**< List scrollbar style. */ + LV_LIST_PART_BG = _LV_OBJ_PART_MAIN_VALUE, /**< List background style */ + LV_LIST_PART_SCRLBAR = _LV_OBJ_PART_VIRTUAL_START, /**< List scrollbar style. */ LV_LIST_PART_EDGE_FLASH, /**< List edge flash style. */ + + LV_LIST_PART_SCRL = _LV_OBJ_PART_REAL_START, /**< List scrollable area style. */ }; typedef uint8_t lv_list_style_t; diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index 89cd1ba8b..abeb16219 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -758,9 +758,14 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) { lv_res_t res; if(sign == LV_SIGNAL_GET_STYLE) { - uint8_t ** type_p = param; + uint8_t ** part_p = param; lv_style_dsc_t ** style_dsc_p = param; - *style_dsc_p = lv_page_get_style(page, **type_p); + *style_dsc_p = lv_page_get_style(page, **part_p); + return LV_RES_OK; + } else if(sign == LV_SIGNAL_GET_STATE) { + lv_get_state_info_t * info = param; + if(info->part == LV_PAGE_PART_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(page), LV_CONT_PART_MAIN); + else info->result = lv_obj_get_state(page, info->part); return LV_RES_OK; } diff --git a/src/lv_objx/lv_page.h b/src/lv_objx/lv_page.h index 84186d77d..0c75572fe 100644 --- a/src/lv_objx/lv_page.h +++ b/src/lv_objx/lv_page.h @@ -87,10 +87,11 @@ typedef struct } lv_page_ext_t; enum { - LV_PAGE_PART_BG, - LV_PAGE_PART_SCRL, - LV_PAGE_PART_SCRLBAR, + LV_PAGE_PART_BG = _LV_OBJ_PART_MAIN_VALUE, + LV_PAGE_PART_SCRLBAR = _LV_OBJ_PART_VIRTUAL_START, LV_PAGE_PART_EDGE_FLASH, + + LV_PAGE_PART_SCRL = _LV_OBJ_PART_REAL_START, }; typedef uint8_t lv_part_style_t;