2017-04-13 10:20:35 +02:00
|
|
|
/**
|
|
|
|
* @file lv_style.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2017-07-28 13:57:56 +02:00
|
|
|
#include "lv_obj.h"
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_mem.h"
|
2019-05-20 18:38:24 -07:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
2017-04-13 10:20:35 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-04-04 07:15:40 +02:00
|
|
|
#define STYLE_MIX_MAX 256
|
|
|
|
#define STYLE_MIX_SHIFT 8 /*log2(STYLE_MIX_MAX)*/
|
|
|
|
|
|
|
|
#define VAL_PROP(v1, v2, r) v1 + (((v2 - v1) * r) >> STYLE_MIX_SHIFT)
|
2019-06-06 06:05:40 +02:00
|
|
|
#define STYLE_ATTR_MIX(attr, r) \
|
|
|
|
if(start->attr != end->attr) { \
|
|
|
|
res->attr = VAL_PROP(start->attr, end->attr, r); \
|
|
|
|
} else { \
|
|
|
|
res->attr = start->attr; \
|
2019-04-04 07:15:40 +02:00
|
|
|
}
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2019-12-14 23:39:26 +01:00
|
|
|
#define LV_STYLE_PROP_TO_ID(prop) (prop & 0xFF);
|
|
|
|
#define LV_STYLE_PROP_GET_TYPE(prop) ((prop >> 8) & 0xFF);
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2019-12-14 23:39:26 +01:00
|
|
|
static inline int32_t get_property_index(const lv_style_t * style, lv_style_property_t prop);
|
2020-01-16 14:26:36 +01:00
|
|
|
static lv_style_t * get_local_style(lv_style_list_t * list);
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2019-12-22 22:40:02 +01:00
|
|
|
/**********************
|
|
|
|
* GLOABAL VARIABLES
|
|
|
|
**********************/
|
2020-01-10 18:16:20 +01:00
|
|
|
//lv_style_t lv_style_transp_tight;
|
2019-12-22 22:40:02 +01:00
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
2020-01-01 18:46:22 +01:00
|
|
|
void lv_style_built_in_init(void)
|
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
|
2020-01-01 18:46:22 +01:00
|
|
|
}
|
|
|
|
|
2019-12-14 23:39:26 +01:00
|
|
|
void lv_style_init(lv_style_t * style)
|
|
|
|
{
|
|
|
|
style->map = NULL;
|
2019-12-31 22:13:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_style_copy(lv_style_t * style_dest, const lv_style_t * style_src)
|
|
|
|
{
|
|
|
|
lv_style_init(style_dest);
|
2020-01-16 21:25:11 +01:00
|
|
|
|
|
|
|
if(style_src->map == NULL) return;
|
|
|
|
|
2020-02-04 02:09:15 +01:00
|
|
|
uint16_t size = lv_style_get_mem_size(style_src);
|
2020-01-24 14:55:56 +01:00
|
|
|
|
|
|
|
style_dest->map = lv_mem_alloc(size);
|
|
|
|
memcpy(style_dest->map, style_src->map, size);
|
2017-04-13 10:20:35 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
void lv_style_list_init(lv_style_list_t * list)
|
2019-12-17 09:20:40 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
list->style_list = NULL;
|
|
|
|
list->style_cnt = 0;
|
|
|
|
list->has_local = 0;
|
2019-12-22 22:40:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 21:25:11 +01:00
|
|
|
void lv_style_list_copy(lv_style_list_t * list_dest, const lv_style_list_t * list_src)
|
|
|
|
{
|
2020-01-20 16:11:38 +01:00
|
|
|
lv_style_list_reset(list_dest);
|
2020-01-16 21:25:11 +01:00
|
|
|
|
|
|
|
if(list_src->style_list == NULL) return;
|
|
|
|
|
|
|
|
if(list_src->has_local == 0) {
|
|
|
|
list_dest->style_list = lv_mem_alloc(list_src->style_cnt * sizeof(lv_style_t *));
|
|
|
|
memcpy(list_dest->style_list, list_src->style_list, list_src->style_cnt * sizeof(lv_style_t *));
|
|
|
|
|
|
|
|
list_dest->style_cnt = list_src->style_cnt;
|
|
|
|
} else {
|
|
|
|
list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *));
|
|
|
|
memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *));
|
|
|
|
list_dest->style_cnt = list_src->style_cnt - 1;
|
|
|
|
|
|
|
|
lv_style_t * local_style = get_local_style(list_dest);
|
|
|
|
lv_style_copy(local_style, get_local_style(list_src));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 22:40:02 +01:00
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
void lv_style_list_add_style(lv_style_list_t * list, lv_style_t * style)
|
2019-12-22 22:40:02 +01:00
|
|
|
{
|
2020-01-21 06:26:37 +01:00
|
|
|
if(list == NULL) return;
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
/*Remove the style first if already exists*/
|
|
|
|
lv_style_list_remove_style(list, style);
|
|
|
|
|
|
|
|
lv_style_t ** new_classes;
|
|
|
|
if(list->style_cnt == 0) new_classes = lv_mem_alloc(sizeof(lv_style_t *));
|
|
|
|
else new_classes = lv_mem_realloc(list->style_list, sizeof(lv_style_t *) * (list->style_cnt + 1));
|
|
|
|
LV_ASSERT_MEM(new_classes);
|
|
|
|
if(new_classes == NULL) {
|
|
|
|
LV_LOG_WARN("lv_style_list_add_style: couldn't add the class");
|
|
|
|
return;
|
|
|
|
}
|
2019-12-22 23:19:51 +01:00
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
/*Make space for the new style at the beginning. Leave local style if exists*/
|
|
|
|
uint8_t i;
|
|
|
|
uint8_t first_style = list->has_local ? 1 : 0;
|
|
|
|
for(i = list->style_cnt; i > first_style; i--) {
|
|
|
|
new_classes[i] = new_classes[i - 1];
|
2019-12-22 22:40:02 +01:00
|
|
|
}
|
2020-01-16 14:26:36 +01:00
|
|
|
|
|
|
|
new_classes[first_style] = style;
|
|
|
|
list->style_cnt++;
|
|
|
|
list->style_list = new_classes;
|
2019-12-22 22:40:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
void lv_style_list_remove_style(lv_style_list_t * list, lv_style_t * style)
|
2019-12-22 22:40:02 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
if(list->style_cnt == 0) return;
|
|
|
|
|
|
|
|
/*Check if the style really exists here*/
|
|
|
|
uint8_t i;
|
|
|
|
bool found = false;
|
|
|
|
for(i = 0; i < list->style_cnt; i++) {
|
|
|
|
if(list->style_list[i] == style) {
|
|
|
|
found = true;
|
|
|
|
break;
|
2019-12-22 23:19:51 +01:00
|
|
|
}
|
2020-01-16 14:26:36 +01:00
|
|
|
}
|
|
|
|
if(found == false) return;
|
|
|
|
|
|
|
|
if(list->style_cnt == 1) {
|
|
|
|
lv_mem_free(list->style_list);
|
|
|
|
list->style_list = NULL;
|
|
|
|
list->style_cnt = 0;
|
|
|
|
list->has_local = 0;
|
|
|
|
return;
|
|
|
|
}
|
2019-12-22 23:19:51 +01:00
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_t ** new_classes = lv_mem_realloc(list->style_list, sizeof(lv_style_t *) * (list->style_cnt - 1));
|
|
|
|
LV_ASSERT_MEM(new_classes);
|
|
|
|
if(new_classes == NULL) {
|
|
|
|
LV_LOG_WARN("lv_style_list_remove_style: couldn't reallocate class list");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t j;
|
|
|
|
for(i = 0, j = 0; i < list->style_cnt; i++) {
|
|
|
|
if(list->style_list[i] == style) continue;
|
|
|
|
new_classes[j] = list->style_list[i];
|
|
|
|
j++;
|
2019-12-22 23:19:51 +01:00
|
|
|
|
2019-12-22 22:40:02 +01:00
|
|
|
}
|
2020-01-16 14:26:36 +01:00
|
|
|
|
|
|
|
list->style_cnt--;
|
|
|
|
list->style_list = new_classes;
|
2019-12-22 22:40:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
void lv_style_list_reset(lv_style_list_t * list)
|
2019-12-22 22:40:02 +01:00
|
|
|
{
|
2020-01-21 06:26:37 +01:00
|
|
|
if(list == NULL) return;
|
2020-01-16 14:26:36 +01:00
|
|
|
if(list->has_local) {
|
|
|
|
lv_style_t * local = lv_style_list_get_style(list, 0);
|
|
|
|
lv_style_reset(local);
|
|
|
|
lv_mem_free(local);
|
|
|
|
}
|
|
|
|
if(list->style_cnt > 0) lv_mem_free(list->style_list);
|
|
|
|
list->style_list = NULL;
|
|
|
|
list->style_cnt = 0;
|
|
|
|
list->has_local = 0;
|
2019-12-22 23:19:51 +01:00
|
|
|
}
|
|
|
|
|
2019-12-26 01:30:20 +01:00
|
|
|
|
2019-12-22 22:40:02 +01:00
|
|
|
void lv_style_reset(lv_style_t * style)
|
|
|
|
{
|
|
|
|
lv_mem_free(style->map);
|
|
|
|
style->map = NULL;
|
2020-01-24 14:55:56 +01:00
|
|
|
}
|
|
|
|
|
2020-02-04 02:09:15 +01:00
|
|
|
uint16_t lv_style_get_mem_size(lv_style_t * style)
|
2020-01-24 14:55:56 +01:00
|
|
|
{
|
|
|
|
if(style->map == NULL) return 0;
|
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
while(style->map[i] != _LV_STYLE_CLOSEING_PROP) {
|
|
|
|
/*Go to the next property*/
|
|
|
|
if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t);
|
|
|
|
else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t);
|
|
|
|
else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t);
|
|
|
|
else i+= sizeof(void*);
|
|
|
|
|
|
|
|
i += sizeof(lv_style_property_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
return i + sizeof(lv_style_property_t);
|
2017-05-08 10:09:41 +02:00
|
|
|
}
|
|
|
|
|
2020-01-07 00:49:47 +01:00
|
|
|
void lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_int_t value)
|
2019-12-14 23:39:26 +01:00
|
|
|
{
|
|
|
|
int32_t id = get_property_index(style, prop);
|
2019-12-19 11:05:04 +01:00
|
|
|
/*The property already exists but not sure it's state is the same*/
|
2019-12-14 23:39:26 +01:00
|
|
|
if(id >= 0) {
|
2019-12-19 11:05:04 +01:00
|
|
|
lv_style_attr_t attr_found;
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
|
|
|
|
attr_found.full = *(style->map + id + 1);
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFFU;
|
|
|
|
|
|
|
|
if(attr_found.bits.state == attr_goal.bits.state) {
|
2020-01-06 22:14:04 +01:00
|
|
|
memcpy(style->map + id + sizeof(lv_style_property_t), &value, sizeof(lv_style_int_t));
|
2019-12-19 11:05:04 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
2019-12-19 11:05:04 +01:00
|
|
|
|
2019-12-14 23:39:26 +01:00
|
|
|
/*Add new property if not exists yet*/
|
2020-01-24 14:55:56 +01:00
|
|
|
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(lv_style_int_t));
|
|
|
|
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
|
|
|
uint8_t end_mark_size = sizeof(end_mark);
|
|
|
|
|
2020-02-04 02:09:15 +01:00
|
|
|
uint16_t size = lv_style_get_mem_size(style);
|
2020-01-24 14:55:56 +01:00
|
|
|
if(size == 0) size += end_mark_size;
|
|
|
|
size += sizeof(lv_style_property_t) + sizeof(lv_style_int_t);
|
|
|
|
style->map = lv_mem_realloc(style->map, size);
|
2019-12-19 11:05:04 +01:00
|
|
|
LV_ASSERT_MEM(style->map);
|
|
|
|
if(style == NULL) return;
|
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t));
|
|
|
|
memcpy(style->map + size - sizeof(lv_style_int_t) - end_mark_size, &value, sizeof(lv_style_int_t));
|
|
|
|
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_style_set_color(lv_style_t * style, lv_style_property_t prop, lv_color_t color)
|
|
|
|
{
|
|
|
|
int32_t id = get_property_index(style, prop);
|
2019-12-19 11:05:04 +01:00
|
|
|
/*The property already exists but not sure it's state is the same*/
|
2019-12-14 23:39:26 +01:00
|
|
|
if(id >= 0) {
|
2019-12-19 11:05:04 +01:00
|
|
|
lv_style_attr_t attr_found;
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
|
|
|
|
attr_found.full = *(style->map + id + 1);
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFFU;
|
|
|
|
|
|
|
|
if(attr_found.bits.state == attr_goal.bits.state) {
|
|
|
|
memcpy(style->map + id + sizeof(lv_style_property_t), &color, sizeof(lv_color_t));
|
|
|
|
return;
|
|
|
|
}
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
2019-12-19 11:05:04 +01:00
|
|
|
|
2019-12-14 23:39:26 +01:00
|
|
|
/*Add new property if not exists yet*/
|
2020-01-24 14:55:56 +01:00
|
|
|
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(lv_color_t));
|
|
|
|
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
|
|
|
uint8_t end_mark_size = sizeof(end_mark);
|
|
|
|
|
2020-02-04 02:09:15 +01:00
|
|
|
uint16_t size = lv_style_get_mem_size(style);
|
2020-01-24 14:55:56 +01:00
|
|
|
if(size == 0) size += end_mark_size;
|
|
|
|
|
|
|
|
size += sizeof(lv_style_property_t) + sizeof(lv_color_t);
|
|
|
|
style->map = lv_mem_realloc(style->map, size);
|
2019-12-19 11:05:04 +01:00
|
|
|
LV_ASSERT_MEM(style->map);
|
|
|
|
if(style == NULL) return;
|
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t));
|
|
|
|
memcpy(style->map + size - sizeof(lv_color_t) - end_mark_size, &color, sizeof(lv_color_t));
|
|
|
|
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t opa)
|
|
|
|
{
|
|
|
|
int32_t id = get_property_index(style, prop);
|
2019-12-19 11:05:04 +01:00
|
|
|
/*The property already exists but not sure it's state is the same*/
|
2019-12-14 23:39:26 +01:00
|
|
|
if(id >= 0) {
|
2019-12-19 11:05:04 +01:00
|
|
|
lv_style_attr_t attr_found;
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
|
|
|
|
attr_found.full = *(style->map + id + 1);
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFFU;
|
|
|
|
|
|
|
|
if(attr_found.bits.state == attr_goal.bits.state) {
|
|
|
|
memcpy(style->map + id + sizeof(lv_style_property_t), &opa, sizeof(lv_opa_t));
|
|
|
|
return;
|
|
|
|
}
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
2019-12-19 11:05:04 +01:00
|
|
|
|
2019-12-14 23:39:26 +01:00
|
|
|
/*Add new property if not exists yet*/
|
2020-01-24 14:55:56 +01:00
|
|
|
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(lv_opa_t));
|
|
|
|
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
|
|
|
uint8_t end_mark_size = sizeof(end_mark);
|
|
|
|
|
2020-02-04 02:09:15 +01:00
|
|
|
uint16_t size = lv_style_get_mem_size(style);
|
2020-01-24 14:55:56 +01:00
|
|
|
if(size == 0) size += end_mark_size;
|
|
|
|
|
|
|
|
size += sizeof(lv_style_property_t) + sizeof(lv_opa_t);
|
|
|
|
style->map = lv_mem_realloc(style->map, size);
|
2019-12-19 11:05:04 +01:00
|
|
|
LV_ASSERT_MEM(style->map);
|
|
|
|
if(style == NULL) return;
|
2019-12-14 23:39:26 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t));
|
|
|
|
memcpy(style->map + size - sizeof(lv_opa_t) - end_mark_size, &opa, sizeof(lv_opa_t));
|
|
|
|
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
2019-12-19 11:05:04 +01:00
|
|
|
}
|
2019-12-14 23:39:26 +01:00
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
void lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void * p)
|
2019-12-19 22:44:18 +01:00
|
|
|
{
|
|
|
|
int32_t id = get_property_index(style, prop);
|
|
|
|
/*The property already exists but not sure it's state is the same*/
|
|
|
|
if(id >= 0) {
|
|
|
|
lv_style_attr_t attr_found;
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
|
|
|
|
attr_found.full = *(style->map + id + 1);
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFFU;
|
|
|
|
|
|
|
|
if(attr_found.bits.state == attr_goal.bits.state) {
|
|
|
|
memcpy(style->map + id + sizeof(lv_style_property_t), &p, sizeof(void *));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Add new property if not exists yet*/
|
2020-01-24 14:55:56 +01:00
|
|
|
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(void *));
|
|
|
|
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
|
|
|
uint8_t end_mark_size = sizeof(end_mark);
|
|
|
|
|
2020-02-04 02:09:15 +01:00
|
|
|
uint16_t size = lv_style_get_mem_size(style);
|
2020-01-24 14:55:56 +01:00
|
|
|
if(size == 0) size += end_mark_size;
|
|
|
|
|
|
|
|
size += sizeof(lv_style_property_t) + sizeof(void *);
|
|
|
|
style->map = lv_mem_realloc(style->map, size);
|
2019-12-19 22:44:18 +01:00
|
|
|
LV_ASSERT_MEM(style->map);
|
|
|
|
if(style == NULL) return;
|
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t));
|
|
|
|
memcpy(style->map + size - sizeof(void *) - end_mark_size , &p, sizeof(void *));
|
|
|
|
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
2019-12-19 22:44:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-19 11:05:04 +01:00
|
|
|
/**
|
|
|
|
* Get the a property from a style.
|
|
|
|
* Take into account the style state and return the property which matches the best.
|
|
|
|
* @param style pointer to a style where to search
|
|
|
|
* @param prop the property, might contain ORed style states too
|
|
|
|
* @param res buffer to store the result
|
|
|
|
* @return the weight of the found property (how well it fits to the style state).
|
|
|
|
* Higher number is means better fit
|
|
|
|
* -1 if the not found (`res` will be undefined)
|
|
|
|
*/
|
2020-01-07 00:49:47 +01:00
|
|
|
int16_t lv_style_get_int(const lv_style_t * style, lv_style_property_t prop, lv_style_int_t * res)
|
2019-12-14 23:39:26 +01:00
|
|
|
{
|
2020-01-06 22:14:04 +01:00
|
|
|
if(style == NULL) return -1;
|
2020-01-08 23:13:08 +01:00
|
|
|
if(style->map == NULL) return -1;
|
2019-12-14 23:39:26 +01:00
|
|
|
int32_t id = get_property_index(style, prop);
|
|
|
|
if(id < 0) {
|
2019-12-19 11:05:04 +01:00
|
|
|
return -1;
|
2019-12-14 23:39:26 +01:00
|
|
|
} else {
|
2020-01-06 22:14:04 +01:00
|
|
|
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_style_int_t));
|
2019-12-19 11:05:04 +01:00
|
|
|
lv_style_attr_t attr_act;
|
|
|
|
attr_act.full = style->map[id + 1];
|
|
|
|
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFF;
|
|
|
|
|
|
|
|
return attr_act.bits.state & attr_goal.bits.state;
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-19 11:05:04 +01:00
|
|
|
int16_t lv_style_get_opa(const lv_style_t * style, lv_style_property_t prop, lv_opa_t * res)
|
2019-12-14 23:39:26 +01:00
|
|
|
{
|
2020-01-06 22:14:04 +01:00
|
|
|
if(style == NULL) return -1;
|
2020-01-08 23:13:08 +01:00
|
|
|
if(style->map == NULL) return -1;
|
2019-12-14 23:39:26 +01:00
|
|
|
int32_t id = get_property_index(style, prop);
|
|
|
|
if(id < 0) {
|
2019-12-19 11:05:04 +01:00
|
|
|
return -1;
|
2019-12-14 23:39:26 +01:00
|
|
|
} else {
|
|
|
|
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_opa_t));
|
2019-12-19 11:05:04 +01:00
|
|
|
lv_style_attr_t attr_act;
|
|
|
|
attr_act.full = style->map[id + 1];
|
|
|
|
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFF;
|
|
|
|
|
|
|
|
return attr_act.bits.state & attr_goal.bits.state;
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 11:05:04 +01:00
|
|
|
int16_t lv_style_get_color(const lv_style_t * style, lv_style_property_t prop, lv_color_t * res)
|
2019-12-14 23:39:26 +01:00
|
|
|
{
|
2020-01-06 22:14:04 +01:00
|
|
|
if(style == NULL) return -1;
|
2020-01-08 23:13:08 +01:00
|
|
|
if(style->map == NULL) return -1;
|
2019-12-14 23:39:26 +01:00
|
|
|
int32_t id = get_property_index(style, prop);
|
|
|
|
if(id < 0) {
|
2019-12-19 11:05:04 +01:00
|
|
|
return -1;
|
2019-12-14 23:39:26 +01:00
|
|
|
} else {
|
|
|
|
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_color_t));
|
2019-12-19 11:05:04 +01:00
|
|
|
lv_style_attr_t attr_act;
|
|
|
|
attr_act.full = style->map[id + 1];
|
|
|
|
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFF;
|
|
|
|
|
2019-12-19 22:44:18 +01:00
|
|
|
return attr_act.bits.state & attr_goal.bits.state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, void ** res)
|
|
|
|
{
|
2020-01-06 22:14:04 +01:00
|
|
|
if(style == NULL) return -1;
|
2020-01-08 23:13:08 +01:00
|
|
|
if(style->map == NULL) return -1;
|
2019-12-19 22:44:18 +01:00
|
|
|
int32_t id = get_property_index(style, prop);
|
|
|
|
if(id < 0) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(void*));
|
|
|
|
lv_style_attr_t attr_act;
|
|
|
|
attr_act.full = style->map[id + 1];
|
|
|
|
|
|
|
|
lv_style_attr_t attr_goal;
|
|
|
|
attr_goal.full = (prop >> 8) & 0xFF;
|
|
|
|
|
2019-12-19 11:05:04 +01:00
|
|
|
return attr_act.bits.state & attr_goal.bits.state;
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-08 21:31:05 +01:00
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
|
|
|
|
void lv_style_list_set_local_int(lv_style_list_t * list, lv_style_property_t prop, lv_style_int_t value)
|
|
|
|
{
|
|
|
|
lv_style_t * local = get_local_style(list);
|
|
|
|
lv_style_set_int(local, prop, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_style_list_set_local_opa(lv_style_list_t * list, lv_style_property_t prop, lv_opa_t value)
|
|
|
|
{
|
|
|
|
lv_style_t * local = get_local_style(list);
|
|
|
|
lv_style_set_opa(local, prop, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_style_list_set_local_color(lv_style_list_t * list, lv_style_property_t prop, lv_color_t value)
|
2020-01-08 21:31:05 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_t * local = get_local_style(list);
|
|
|
|
lv_style_set_color(local, prop, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_style_list_set_local_ptr(lv_style_list_t * list, lv_style_property_t prop, const void * value)
|
|
|
|
{
|
|
|
|
lv_style_t * local = get_local_style(list);
|
|
|
|
lv_style_set_ptr(local, prop, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lv_res_t lv_style_list_get_int(lv_style_list_t * list, lv_style_property_t prop, lv_style_int_t * value)
|
|
|
|
{
|
|
|
|
if(list == NULL) return LV_RES_INV;
|
|
|
|
if(list->style_list == NULL) return LV_RES_INV;
|
2020-01-08 21:31:05 +01:00
|
|
|
|
|
|
|
lv_style_attr_t attr;
|
|
|
|
attr.full = prop >> 8;
|
|
|
|
int16_t weight_goal = attr.full;
|
|
|
|
|
|
|
|
int16_t weight_act;
|
|
|
|
int16_t weight = -1;
|
|
|
|
|
|
|
|
lv_style_int_t value_act;
|
|
|
|
|
|
|
|
int16_t ci;
|
2020-01-16 14:26:36 +01:00
|
|
|
for(ci = 0; ci < list->style_cnt; ci++) {
|
|
|
|
lv_style_t * class = lv_style_list_get_style(list, ci);
|
2020-01-08 21:31:05 +01:00
|
|
|
weight_act = lv_style_get_int(class, prop, &value_act);
|
|
|
|
/*On perfect match return the value immediately*/
|
|
|
|
if(weight_act == weight_goal) {
|
|
|
|
*value = value_act;
|
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
/*If the found ID is better the current candidate then use it*/
|
|
|
|
else if(weight_act > weight) {
|
|
|
|
weight = weight_act;
|
|
|
|
*value = value_act;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
if(weight >= 0) return LV_RES_OK;
|
2020-01-08 21:31:05 +01:00
|
|
|
else return LV_RES_INV;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_res_t lv_style_list_get_color(lv_style_list_t * list, lv_style_property_t prop, lv_color_t * value)
|
2020-01-08 21:31:05 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
if(list == NULL) return LV_RES_INV;
|
|
|
|
if(list->style_list == NULL) return LV_RES_INV;
|
2020-01-08 21:31:05 +01:00
|
|
|
|
|
|
|
lv_style_attr_t attr;
|
|
|
|
attr.full = prop >> 8;
|
|
|
|
int16_t weight_goal = attr.full;
|
|
|
|
|
|
|
|
int16_t weight_act;
|
|
|
|
int16_t weight = -1;
|
|
|
|
|
|
|
|
lv_color_t value_act;
|
|
|
|
|
|
|
|
int16_t ci;
|
2020-01-16 14:26:36 +01:00
|
|
|
for(ci = 0; ci < list->style_cnt; ci++) {
|
|
|
|
lv_style_t * class = lv_style_list_get_style(list, ci);
|
2020-01-08 21:31:05 +01:00
|
|
|
weight_act = lv_style_get_color(class, prop, &value_act);
|
|
|
|
/*On perfect match return the value immediately*/
|
|
|
|
if(weight_act == weight_goal) {
|
|
|
|
*value = value_act;
|
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
/*If the found ID is better the current candidate then use it*/
|
|
|
|
else if(weight_act > weight) {
|
|
|
|
weight = weight_act;
|
|
|
|
*value = value_act;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
if(weight >= 0) return LV_RES_OK;
|
2020-01-08 21:31:05 +01:00
|
|
|
else return LV_RES_INV;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_res_t lv_style_list_get_opa(lv_style_list_t * list, lv_style_property_t prop, lv_opa_t * value)
|
2020-01-08 21:31:05 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
if(list == NULL) return LV_RES_INV;
|
|
|
|
if(list->style_list == NULL) return LV_RES_INV;
|
2020-01-08 21:31:05 +01:00
|
|
|
|
|
|
|
lv_style_attr_t attr;
|
|
|
|
attr.full = prop >> 8;
|
|
|
|
int16_t weight_goal = attr.full;
|
|
|
|
|
|
|
|
int16_t weight_act;
|
|
|
|
int16_t weight = -1;
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_opa_t value_act = LV_OPA_TRANSP;
|
2020-01-08 21:31:05 +01:00
|
|
|
|
|
|
|
int16_t ci;
|
2020-01-16 14:26:36 +01:00
|
|
|
for(ci = 0; ci < list->style_cnt; ci++) {
|
|
|
|
lv_style_t * class = lv_style_list_get_style(list, ci);
|
2020-01-08 21:31:05 +01:00
|
|
|
weight_act = lv_style_get_opa(class, prop, &value_act);
|
|
|
|
/*On perfect match return the value immediately*/
|
|
|
|
if(weight_act == weight_goal) {
|
|
|
|
*value = value_act;
|
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
/*If the found ID is better the current candidate then use it*/
|
|
|
|
else if(weight_act > weight) {
|
|
|
|
weight = weight_act;
|
|
|
|
*value = value_act;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
if(weight >= 0) return LV_RES_OK;
|
2020-01-08 21:31:05 +01:00
|
|
|
else return LV_RES_INV;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, void ** value)
|
2020-01-08 21:31:05 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
if(list == NULL) return LV_RES_INV;
|
|
|
|
if(list->style_list == NULL) return LV_RES_INV;
|
2020-01-08 21:31:05 +01:00
|
|
|
|
|
|
|
lv_style_attr_t attr;
|
|
|
|
attr.full = prop >> 8;
|
|
|
|
int16_t weight_goal = attr.full;
|
|
|
|
|
|
|
|
int16_t weight_act;
|
|
|
|
int16_t weight = -1;
|
|
|
|
|
2020-01-09 01:37:14 +01:00
|
|
|
void * value_act = NULL;
|
2020-01-08 21:31:05 +01:00
|
|
|
|
|
|
|
int16_t ci;
|
2020-01-16 14:26:36 +01:00
|
|
|
for(ci = 0; ci < list->style_cnt; ci++) {
|
|
|
|
lv_style_t * class = lv_style_list_get_style(list, ci);
|
2020-01-08 21:31:05 +01:00
|
|
|
weight_act = lv_style_get_ptr(class, prop, &value_act);
|
|
|
|
/*On perfect match return the value immediately*/
|
|
|
|
if(weight_act == weight_goal) {
|
|
|
|
*value = value_act;
|
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
/*If the found ID is better the current candidate then use it*/
|
|
|
|
else if(weight_act > weight) {
|
|
|
|
weight = weight_act;
|
|
|
|
*value = value_act;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
if(weight >= 0) return LV_RES_OK;
|
2020-01-08 21:31:05 +01:00
|
|
|
else return LV_RES_INV;
|
|
|
|
}
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
2019-12-14 23:39:26 +01:00
|
|
|
|
|
|
|
static inline int32_t get_property_index(const lv_style_t * style, lv_style_property_t prop)
|
|
|
|
{
|
2020-01-24 14:55:56 +01:00
|
|
|
if(style->map == NULL) return -1;
|
|
|
|
|
2019-12-14 23:39:26 +01:00
|
|
|
uint8_t id_to_find = prop & 0xFF;
|
2019-12-19 11:05:04 +01:00
|
|
|
lv_style_attr_t attr;
|
|
|
|
attr.full = (prop >> 8) & 0xFF;
|
|
|
|
|
|
|
|
int16_t weight = -1;
|
|
|
|
int16_t id_guess = -1;
|
2020-01-09 14:16:32 +01:00
|
|
|
|
2019-12-14 23:39:26 +01:00
|
|
|
size_t i = 0;
|
2020-01-24 14:55:56 +01:00
|
|
|
while(style->map[i] != _LV_STYLE_CLOSEING_PROP) {
|
2019-12-14 23:39:26 +01:00
|
|
|
if(style->map[i] == id_to_find) {
|
2020-01-08 23:56:51 +01:00
|
|
|
lv_style_attr_t attr_act;
|
|
|
|
attr_act.full = style->map[i + 1];
|
|
|
|
|
2019-12-28 01:27:20 +01:00
|
|
|
/*If the state perfectly matches return this property*/
|
2019-12-19 11:05:04 +01:00
|
|
|
if(attr_act.bits.state == attr.bits.state) {
|
|
|
|
return i;
|
|
|
|
}
|
2019-12-28 01:27:20 +01:00
|
|
|
/* Be sure the property not specifies other state than the requested.
|
2019-12-19 11:05:04 +01:00
|
|
|
* E.g. For HOVER+PRESS, HOVER only is OK, but HOVER+FOCUS not*/
|
|
|
|
else if((attr_act.bits.state & (~attr.bits.state)) == 0) {
|
|
|
|
/* Use this property if it describes better the requested state than the current candidate.
|
|
|
|
* E.g. for HOVER+FOCUS+PRESS prefer HOVER+FOCUS over FOCUS*/
|
|
|
|
if(attr_act.bits.state > weight) {
|
|
|
|
weight = attr_act.bits.state;
|
|
|
|
id_guess = i;
|
|
|
|
}
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-19 11:05:04 +01:00
|
|
|
|
|
|
|
/*Go to the next property*/
|
2020-01-24 14:55:56 +01:00
|
|
|
if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t);
|
|
|
|
else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t);
|
|
|
|
else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t);
|
|
|
|
else i+= sizeof(void*);
|
|
|
|
|
|
|
|
i += sizeof(lv_style_property_t);
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 11:05:04 +01:00
|
|
|
return id_guess;
|
2019-12-14 23:39:26 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
|
|
|
|
static lv_style_t * get_local_style(lv_style_list_t * list)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(list->has_local) return lv_style_list_get_style(list, 0);
|
|
|
|
|
|
|
|
|
|
|
|
lv_style_t * local_style = lv_mem_alloc(sizeof(lv_style_t));
|
|
|
|
LV_ASSERT_MEM(local_style);
|
|
|
|
if(local_style == NULL) {
|
|
|
|
LV_LOG_WARN("get_local_style: couldn't create local style");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
lv_style_init(local_style);
|
|
|
|
|
|
|
|
lv_style_list_add_style(list, local_style);
|
|
|
|
list->has_local = 1;
|
|
|
|
|
|
|
|
return local_style;
|
|
|
|
}
|
|
|
|
|