fix(layer): update the cached layer type on state change (#5801)

This commit is contained in:
Gabor Kiss-Vamosi
2024-03-10 07:48:19 +01:00
committed by GitHub
parent 7a59cd15ec
commit ed38275db5
5 changed files with 36 additions and 7 deletions

View File

@@ -740,7 +740,7 @@ static void update_obj_state(lv_obj_t * obj, lv_state_t new_state)
lv_obj_invalidate(obj);
obj->state = new_state;
_lv_obj_update_layer_type(obj);
_lv_obj_style_transition_dsc_t * ts = lv_malloc_zeroed(sizeof(_lv_obj_style_transition_dsc_t) * STYLE_TRANSITION_MAX);
uint32_t tsi = 0;
uint32_t i;

View File

@@ -300,12 +300,7 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_selector_t selector, lv_style
/*Cache the layer type*/
if((part == LV_PART_ANY || part == LV_PART_MAIN) && is_layer_refr) {
lv_layer_type_t layer_type = calculate_layer_type(obj);
if(obj->spec_attr) obj->spec_attr->layer_type = layer_type;
else if(layer_type != LV_LAYER_TYPE_NONE) {
lv_obj_allocate_spec_attr(obj);
obj->spec_attr->layer_type = layer_type;
}
_lv_obj_update_layer_type(obj);
}
if(prop == LV_STYLE_PROP_ANY || is_ext_draw) {
@@ -670,6 +665,16 @@ lv_opa_t lv_obj_get_style_opa_recursive(const lv_obj_t * obj, lv_part_t part)
return opa_final;
}
void _lv_obj_update_layer_type(lv_obj_t * obj)
{
lv_layer_type_t layer_type = calculate_layer_type(obj);
if(obj->spec_attr) obj->spec_attr->layer_type = layer_type;
else if(layer_type != LV_LAYER_TYPE_NONE) {
lv_obj_allocate_spec_attr(obj);
obj->spec_attr->layer_type = layer_type;
}
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -352,6 +352,13 @@ static inline int32_t lv_obj_get_style_transform_scale_y_safe(const lv_obj_t * o
*/
lv_opa_t lv_obj_get_style_opa_recursive(const lv_obj_t * obj, lv_part_t part);
/**
* Update the layer type of a widget bayed on its current styles.
* The result will be stored in `obj->spec_attr->layer_type`
* @param obj the object whose layer should be updated
*/
void _lv_obj_update_layer_type(lv_obj_t * obj);
/**********************
* MACROS
**********************/

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@@ -41,4 +41,21 @@ void test_no_residual_border_on_scale_down(void)
}
void test_update_layer_type_on_state_change(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_transform_rotation(&style, 90);
lv_style_set_transform_scale_x(&style, 100);
lv_obj_t * obj = lv_obj_create(lv_screen_active());
lv_obj_center(obj);
lv_obj_add_style(obj, &style, LV_STATE_CHECKED);
lv_refr_now(NULL);
lv_obj_add_state(obj, LV_STATE_CHECKED);
TEST_ASSERT_EQUAL_SCREENSHOT("draw/layer_transform_2.png");
}
#endif