feat(style) add support for declaring styles in ROM (#2220)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
@@ -388,6 +388,17 @@ def local_style_set(p):
|
||||
print("}")
|
||||
print("")
|
||||
|
||||
def style_const_set(p):
|
||||
cast = style_set_cast(p['style_type'])
|
||||
print("#define LV_STYLE_CONST_" + p['name'] + "(val) \\")
|
||||
print(" { \\")
|
||||
print(" .prop = LV_STYLE_" + p['name'] + ", \\")
|
||||
print(" .value = { \\")
|
||||
print(" ." + p['style_type'] +" = " + cast + "val \\")
|
||||
print(" } \\")
|
||||
print(" }")
|
||||
print("")
|
||||
|
||||
|
||||
|
||||
def docs(p):
|
||||
@@ -430,6 +441,7 @@ sys.stdout = open(base_dir + '/../src/misc/lv_style_gen.h', 'w')
|
||||
|
||||
for p in props:
|
||||
style_set(p)
|
||||
style_const_set(p)
|
||||
|
||||
sys.stdout = open(base_dir + '/style_props.md', 'w')
|
||||
|
||||
|
||||
@@ -55,6 +55,11 @@ void lv_style_reset(lv_style_t * style)
|
||||
{
|
||||
LV_ASSERT_STYLE(style);
|
||||
|
||||
if(style->is_const) {
|
||||
LV_LOG_ERROR("Cannot reset const style");
|
||||
return;
|
||||
}
|
||||
|
||||
if(style->prop_cnt > 1) lv_mem_free(style->v_p.values_and_props);
|
||||
lv_memset_00(style, sizeof(lv_style_t));
|
||||
#if LV_USE_ASSERT_STYLE
|
||||
@@ -74,6 +79,11 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
|
||||
{
|
||||
LV_ASSERT_STYLE(style);
|
||||
|
||||
if(style->is_const) {
|
||||
LV_LOG_ERROR("Cannot remove prop from const style");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(style->prop_cnt == 0) return false;
|
||||
|
||||
if(style->prop_cnt == 1) {
|
||||
@@ -92,10 +102,11 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
|
||||
if(old_props[i] == prop) {
|
||||
lv_style_value_t * old_values = (lv_style_value_t *)style->v_p.values_and_props;
|
||||
|
||||
uint16_t * new_props = &style->prop1;
|
||||
lv_style_value_t * new_values = &style->v_p.value1;
|
||||
|
||||
if(style->prop_cnt > 2) {
|
||||
if(style->prop_cnt == 2) {
|
||||
style->prop_cnt = 1;
|
||||
style->prop1 = i == 0 ? old_props[1] : old_props[0];
|
||||
style->v_p.value1 = i == 0 ? old_values[1] : old_values[0];
|
||||
} else {
|
||||
size_t size = (style->prop_cnt - 1) * (sizeof(lv_style_value_t) + sizeof(uint16_t));
|
||||
uint8_t * new_values_and_props = lv_mem_alloc(size);
|
||||
if(new_values_and_props == NULL) return false;
|
||||
@@ -103,13 +114,8 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
|
||||
style->prop_cnt--;
|
||||
|
||||
tmp = new_values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
|
||||
new_props = (uint16_t *)tmp;
|
||||
new_values = (lv_style_value_t *)new_values_and_props;
|
||||
} else {
|
||||
style->prop_cnt = 1;
|
||||
style->prop1 = i == 0 ? old_props[1] : old_props[0];
|
||||
style->v_p.value1 = i == 0 ? old_values[1] : old_values[0];
|
||||
}
|
||||
uint16_t * new_props = (uint16_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.*/
|
||||
@@ -118,6 +124,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
|
||||
new_props[i++] = old_props[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lv_mem_free(old_values);
|
||||
return true;
|
||||
@@ -131,6 +138,11 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_
|
||||
{
|
||||
LV_ASSERT_STYLE(style);
|
||||
|
||||
if(style->is_const) {
|
||||
LV_LOG_ERROR("Cannot set property of constant style");
|
||||
return;
|
||||
}
|
||||
|
||||
if(style->prop_cnt > 1) {
|
||||
uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
|
||||
uint16_t * props = (uint16_t *)tmp;
|
||||
|
||||
@@ -43,6 +43,12 @@ extern "C" {
|
||||
#define LV_IMG_ZOOM_NONE 256 /*Value for not zooming the image*/
|
||||
LV_EXPORT_CONST_INT(LV_IMG_ZOOM_NONE);
|
||||
|
||||
#if LV_USE_ASSERT_STYLE
|
||||
#define LV_STYLE_CONST_INIT(var_name, prop_array) const lv_style_t var_name = { .sentinel = LV_STYLE_SENTINEL_VALUE, .v_p = { .const_props = prop_array }, .has_group = 0xFF, .is_const = 1 }
|
||||
#else
|
||||
#define LV_STYLE_CONST_INIT(var_name, prop_array) const lv_style_t var_name = { .v_p = { .const_props = prop_array }, .has_group = 0xFF, .is_const = 1 }
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@@ -236,6 +242,14 @@ typedef struct _lv_style_transiton_t {
|
||||
uint32_t delay; /**< Delay before the transition in [ms]*/
|
||||
}lv_style_transition_dsc_t;
|
||||
|
||||
|
||||
/**
|
||||
* Descriptor of a constant style property.
|
||||
*/
|
||||
typedef struct {
|
||||
lv_style_prop_t prop;
|
||||
lv_style_value_t value;
|
||||
} lv_style_const_prop_t;
|
||||
/**
|
||||
* Descriptor of a style (a collection of properties and values).
|
||||
*/
|
||||
@@ -250,9 +264,11 @@ typedef struct {
|
||||
union {
|
||||
lv_style_value_t value1;
|
||||
uint8_t * values_and_props;
|
||||
const lv_style_const_prop_t * const_props;
|
||||
} v_p;
|
||||
|
||||
uint16_t prop1;
|
||||
uint16_t prop1 :15;
|
||||
uint16_t is_const :1;
|
||||
uint8_t has_group;
|
||||
uint8_t prop_cnt;
|
||||
} lv_style_t;
|
||||
@@ -334,6 +350,17 @@ lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_va
|
||||
*/
|
||||
static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value)
|
||||
{
|
||||
if(style->is_const) {
|
||||
const lv_style_const_prop_t *const_prop;
|
||||
for(const_prop = style->v_p.const_props; const_prop->prop != LV_STYLE_PROP_INV; const_prop++) {
|
||||
if(const_prop->prop == prop) {
|
||||
*value = const_prop->value;
|
||||
return LV_RES_OK;
|
||||
}
|
||||
}
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
if(style->prop_cnt == 0) return LV_RES_INV;
|
||||
|
||||
if(style->prop_cnt > 1) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user