- 1 if a nested for loop is needed?
From the logic of lv_style_set_prop, each prop in style->values_and_props
is unique. Therefore, I don’t understand why a nested for loop is needed in the following code.
bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
{
LV_ASSERT_STYLE(style);
if(lv_style_is_const(style)) {
LV_LOG_ERROR("Cannot remove prop from const style");
return false;
}
if(style->prop_cnt == 0) return false;
uint8_t * tmp = (lv_style_prop_t *)style->values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint8_t * old_props = (uint8_t *)tmp;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
if(old_props[i] == prop) {
lv_style_value_t * old_values = (lv_style_value_t *)style->values_and_props;
size_t size = (style->prop_cnt - 1) * (sizeof(lv_style_value_t) + sizeof(lv_style_prop_t));
uint8_t * new_values_and_props = lv_malloc(size);
if(new_values_and_props == NULL) return false;
style->values_and_props = new_values_and_props;
style->prop_cnt--;
tmp = new_values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint8_t * new_props = (uint8_t *)tmp;
lv_style_value_t * new_values = (lv_style_value_t *)new_values_and_props;
uint32_t j;
for(i = j = 0; j <= style->prop_cnt;
j++) { /*<=: because prop_cnt already reduced but all the old props. needs to be checked.*/
if(old_props[j] != prop) {
new_values[i] = old_values[j];
new_props[i++] = old_props[j];
}
}
lv_free(old_values);
return true;
}
}
return false;
}
- 2 Comment on
trans_delete
I read function calling and find that , in the comment oftrans_delete
,
/**
* Remove the transition from object's part's property.
* - Remove the transition from `_lv_obj_style_trans_ll` and free it
* - Delete pending transitions
* @param obj pointer to an object which transition(s) should be removed
* @param part a part of object or 0xFF to remove from all parts
* @param prop a property or 0xFF to remove all properties
* @param tr_limit delete transitions only "older" than this. `NULL` if not used
*/
0xFF to remove all properties
The ability to use 0xFF to remove all properties seems not implemented in lv_style_remove_prop.