chore(style): add lv_style_is_const() for better readability

This commit is contained in:
Gabor Kiss-Vamosi
2023-08-15 12:48:54 +02:00
parent d1890895a4
commit 3631ad4b78
3 changed files with 18 additions and 7 deletions

View File

@@ -121,7 +121,7 @@ void lv_obj_add_style(lv_obj_t * obj, const lv_style_t * style, lv_style_selecto
#if LV_OBJ_STYLE_CACHE
uint32_t * prop_is_set = part == LV_PART_MAIN ? &obj->style_main_prop_is_set : &obj->style_other_prop_is_set;
if(style->prop_cnt == 255) {
if(lv_style_is_const(style)) {
lv_style_const_prop_t * props = style->values_and_props;
for(i = 0; props[i].prop_ptr; i++) {
(*prop_is_set) |= (uint32_t)1 << ((*props[i].prop_ptr) >> 2);
@@ -1058,7 +1058,7 @@ static void full_cache_refresh(lv_obj_t * obj, lv_part_t part)
if(lv_obj_style_get_selector_part(obj->styles[i].selector) != LV_PART_MAIN) continue;
lv_style_t * style = (lv_style_t *)obj->styles[i].style;
uint32_t j;
if(style->prop_cnt == 255) {
if(lv_style_is_const(style)) {
lv_style_const_prop_t * props = style->values_and_props;
for(j = 0; props[j].prop_ptr; j++) {
obj->style_main_prop_is_set |= (uint32_t)1 << ((*props[j].prop_ptr) >> 2);
@@ -1078,7 +1078,7 @@ static void full_cache_refresh(lv_obj_t * obj, lv_part_t part)
if(lv_obj_style_get_selector_part(obj->styles[i].selector) == LV_PART_MAIN) continue;
lv_style_t * style = (lv_style_t *)obj->styles[i].style;
uint32_t j;
if(style->prop_cnt == 255) {
if(lv_style_is_const(style)) {
lv_style_const_prop_t * props = style->values_and_props;
for(j = 0; props[j].prop_ptr; j++) {
obj->style_other_prop_is_set |= (uint32_t)1 << ((*props[j].prop_ptr) >> 2);
@@ -1110,7 +1110,7 @@ static void fade_in_anim_ready(lv_anim_t * a)
static bool style_has_flag(const lv_style_t * style, uint32_t flag)
{
if(style->prop_cnt == 255) {
if(lv_style_is_const(style)) {
lv_style_const_prop_t * props = style->values_and_props;
uint32_t i;
for(i = 0; props[i].prop_ptr; i++) {

View File

@@ -216,7 +216,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
{
LV_ASSERT_STYLE(style);
if(style->prop_cnt == 255) {
if(lv_style_is_const(style)) {
LV_LOG_ERROR("Cannot remove prop from const style");
return false;
}
@@ -261,7 +261,7 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_
{
LV_ASSERT_STYLE(style);
if(style->prop_cnt == 255) {
if(lv_style_is_const(style)) {
LV_LOG_ERROR("Cannot set property of constant style");
return;
}

View File

@@ -398,6 +398,17 @@ void lv_style_init(lv_style_t * style);
*/
void lv_style_reset(lv_style_t * style);
/**
* Check if a style is constant
* @param style pointer to a style
* @return true: the style is constant
*/
static inline bool lv_style_is_const(const lv_style_t * style)
{
if(style->prop_cnt == 255) return true;
return false;
}
/**
* Register a new style property for custom usage
* @return a new property ID, or LV_STYLE_PROP_INV if there are no more available.
@@ -483,7 +494,7 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop);
static inline lv_style_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop,
lv_style_value_t * value)
{
if(style->prop_cnt == 255) {
if(lv_style_is_const(style)) {
lv_style_const_prop_t * props = (lv_style_const_prop_t *)style->values_and_props;
uint32_t i;
for(i = 0; props[i].prop_ptr; i++) {