1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

start to separate virtual and real object parts

This commit is contained in:
Gabor Kiss-Vamosi 2020-01-05 20:05:11 +01:00
parent eea40f41bb
commit 73614e6b22
7 changed files with 48 additions and 28 deletions

View File

@ -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; lv_style_attr_t attr;
attr.full = prop >> 8; 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; int16_t weight = -1;
lv_style_value_t value; 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); lv_style_dsc_t * dsc = lv_obj_get_style(parent, part);
if(dsc == NULL) continue; 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); prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS);
int16_t weight_act; 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); lv_style_dsc_t * dsc = lv_obj_get_style(parent, part);
if(dsc == NULL) continue; if(dsc == NULL) continue;
state = lv_obj_get_state(parent); state = lv_obj_get_state(parent, part);
int16_t weight_goal = state; int16_t weight_goal = state;
prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); 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; lv_style_attr_t attr;
attr.full = prop >> 8; 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; int16_t weight = -1;
lv_opa_t value; 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); lv_style_dsc_t * dsc = lv_obj_get_style(parent, part);
if(dsc == NULL) continue; 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); prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS);
int16_t weight_act; 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); lv_style_dsc_t * dsc = lv_obj_get_style(parent, part);
if(dsc == NULL) continue; if(dsc == NULL) continue;
state = lv_obj_get_state(parent); state = lv_obj_get_state(parent, part);
int16_t weight_goal = state; int16_t weight_goal = state;
prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS); 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; 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); 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; if(res != LV_RES_OK) return 0;
while(parent) {
state |= parent->state;
parent = lv_obj_get_parent(parent);
}
return info.result;
return state;
} }
/** /**

View File

@ -46,6 +46,10 @@ extern "C" {
#define LV_EXT_CLICK_AREA_TINY 1 #define LV_EXT_CLICK_AREA_TINY 1
#define LV_EXT_CLICK_AREA_FULL 2 #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 * TYPEDEFS
**********************/ **********************/
@ -280,12 +284,18 @@ typedef struct
... [x]: "lv_obj" */ ... [x]: "lv_obj" */
} lv_obj_type_t; } lv_obj_type_t;
typedef struct _lv_hit_test_info_t typedef struct
{ {
lv_point_t *point; lv_point_t *point;
bool result; bool result;
} lv_hit_test_info_t; } lv_hit_test_info_t;
typedef struct
{
uint8_t part;
lv_obj_state_t result;
} lv_get_state_info_t;
/********************** /**********************
* GLOBAL PROTOTYPES * 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); 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 * Get the signal function of an object

View File

@ -189,7 +189,7 @@ void lv_btn_toggle(lv_obj_t * btn)
{ {
LV_ASSERT_OBJ(btn, LV_OBJX_NAME); 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); lv_obj_clear_state(btn, LV_OBJ_STATE_CHECKED);
} else { } else {
lv_obj_set_state(btn, LV_OBJ_STATE_CHECKED); 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_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_CHECKED) {
if(state & LV_OBJ_STATE_PRESSED) return LV_BTN_STATE_TGL_PR; if(state & LV_OBJ_STATE_PRESSED) return LV_BTN_STATE_TGL_PR;

View File

@ -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; style_dsc_p = &ext->page.sb.style;
break; break;
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
case LV_PAGE_PART_EDGE_FLASH: case LV_LIST_PART_EDGE_FLASH:
style_dsc_p = &ext->page.edge_flash.style; style_dsc_p = &ext->page.edge_flash.style;
break; break;
#endif #endif

View File

@ -63,10 +63,11 @@ typedef struct
/** List styles. */ /** List styles. */
enum { enum {
LV_LIST_PART_BG, /**< List background style */ LV_LIST_PART_BG = _LV_OBJ_PART_MAIN_VALUE, /**< List background style */
LV_LIST_PART_SCRL, /**< List scrollable area style. */ LV_LIST_PART_SCRLBAR = _LV_OBJ_PART_VIRTUAL_START, /**< List scrollbar style. */
LV_LIST_PART_SCRLBAR, /**< List scrollbar style. */
LV_LIST_PART_EDGE_FLASH, /**< List edge flash 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; typedef uint8_t lv_list_style_t;

View File

@ -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; lv_res_t res;
if(sign == LV_SIGNAL_GET_STYLE) { if(sign == LV_SIGNAL_GET_STYLE) {
uint8_t ** type_p = param; uint8_t ** part_p = param;
lv_style_dsc_t ** style_dsc_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; return LV_RES_OK;
} }

View File

@ -87,10 +87,11 @@ typedef struct
} lv_page_ext_t; } lv_page_ext_t;
enum { enum {
LV_PAGE_PART_BG, LV_PAGE_PART_BG = _LV_OBJ_PART_MAIN_VALUE,
LV_PAGE_PART_SCRL, LV_PAGE_PART_SCRLBAR = _LV_OBJ_PART_VIRTUAL_START,
LV_PAGE_PART_SCRLBAR,
LV_PAGE_PART_EDGE_FLASH, LV_PAGE_PART_EDGE_FLASH,
LV_PAGE_PART_SCRL = _LV_OBJ_PART_REAL_START,
}; };
typedef uint8_t lv_part_style_t; typedef uint8_t lv_part_style_t;