d89ef83551
Properties can now have values of different types, and they are registered with their name, either to a layout class or globally. Layout classes are also registered with their name.
162 lines
4 KiB
C
162 lines
4 KiB
C
#ifndef CLAY_PROPERTY_H
|
|
#define CLAY_PROPERTY_H
|
|
|
|
#include "clay.h"
|
|
#include "clay-list.h"
|
|
#include "clay-map.h"
|
|
|
|
CLAY_STRING_MAP_TYPE(clay_prop_keyword_map, int)
|
|
|
|
typedef struct clay_prop_val_s clay_prop_val;
|
|
|
|
CLAY_LIST_TYPE(clay_prop_vals, clay_prop_val)
|
|
|
|
typedef struct clay_prop_s clay_prop;
|
|
|
|
typedef struct clay_prop_definition_s clay_prop_definition;
|
|
|
|
typedef struct clay_prop_definition_in_s clay_prop_definition_in;
|
|
|
|
|
|
#include "layout.h"
|
|
|
|
|
|
struct clay_prop_s {
|
|
clay_prop_vals_const values;
|
|
int inheritance_level;
|
|
} ;
|
|
|
|
CLAY_STRING_MAP_TYPE(clay_property_map, clay_prop_vals)
|
|
CLAY_STRING_MAP_TYPE(clay_prop_map, clay_prop)
|
|
|
|
struct clay_t {
|
|
clay_ctx ctx;
|
|
clay_layout_class class;
|
|
clay_property_map properties;
|
|
clay parent;
|
|
clay_layout_list children;
|
|
};
|
|
|
|
|
|
enum clay_prop_val_type {
|
|
CLAY_PROP_TYPE_KEYWORD,
|
|
CLAY_PROP_TYPE_NUMBER,
|
|
CLAY_PROP_TYPE_COLOR,
|
|
CLAY_PROP_TYPE_STRING
|
|
};
|
|
|
|
enum clay_prop_val_number_type {
|
|
CLAY_PROP_NUMBER_INT,
|
|
CLAY_PROP_NUMBER_FLOAT,
|
|
};
|
|
|
|
|
|
typedef enum {
|
|
CLAY_PROP_UNIT_NONE = 1,
|
|
CLAY_PROP_UNIT_PX = 2,
|
|
CLAY_PROP_UNIT_PT = 4,
|
|
CLAY_PROP_UNIT_CM = 8,
|
|
CLAY_PROP_UNIT_MM = 16,
|
|
CLAY_PROP_UNIT_PERCENT = 32,
|
|
} clay_prop_val_unit;
|
|
|
|
#define CLAY_PROP_UNIT_ABSOLUTE (CLAY_PROP_UNIT_PT | CLAY_PROP_UNIT_CM | CLAY_PROP_UNIT_MM)
|
|
#define CLAY_PROP_UNIT_ANY_UNIT (CLAY_PROP_UNIT_PX | CLAY_PROP_UNIT_PT | CLAY_PROP_UNIT_CM | CLAY_PROP_UNIT_MM | CLAY_PROP_UNIT_PERCENT)
|
|
#define CLAY_PROP_UNIT_ANY (CLAY_PROP_UNIT_NONE | CLAY_PROP_UNIT_ANY_UNIT)
|
|
|
|
struct clay_prop_val_number {
|
|
enum clay_prop_val_number_type type;
|
|
clay_prop_val_unit unit;
|
|
union {
|
|
int64_t value_int;
|
|
double value_double;
|
|
};
|
|
};
|
|
|
|
struct clay_prop_val_s {
|
|
enum clay_prop_val_type type;
|
|
union {
|
|
int keyword;
|
|
struct clay_prop_val_number number;
|
|
clay_color color;
|
|
const char *string;
|
|
};
|
|
};
|
|
|
|
struct clay_prop_definition_s {
|
|
bool allow_int;
|
|
bool allow_float;
|
|
bool allow_string;
|
|
clay_prop_val_unit allow_units;
|
|
bool allow_color;
|
|
clay_prop_keyword_map keywords;
|
|
int max_values;
|
|
bool inherits;
|
|
bool global;
|
|
};
|
|
|
|
|
|
struct clay_prop_keyword_map_entry_in {
|
|
const char *keyword;
|
|
int value;
|
|
};
|
|
|
|
struct clay_prop_keyword_map_in {
|
|
struct clay_prop_keyword_map_entry_in *entries;
|
|
size_t num_entries;
|
|
};
|
|
|
|
struct clay_prop_definition_in_s {
|
|
bool allow_int;
|
|
bool allow_string;
|
|
bool allow_float;
|
|
clay_prop_val_unit allow_units;
|
|
bool allow_color;
|
|
struct clay_prop_keyword_map_in keywords;
|
|
int max_values;
|
|
bool inherits;
|
|
} ;
|
|
|
|
|
|
#define CLAY_PP_NARG(...) \
|
|
CLAY_PP_NARG_(__VA_ARGS__,CLAY_PP_RSEQ_N())
|
|
#define CLAY_PP_NARG_(...) \
|
|
CLAY_PP_ARG_N(__VA_ARGS__)
|
|
#define CLAY_PP_ARG_N(\
|
|
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
|
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
|
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
|
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
|
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
|
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
|
|
_61, _62, _63, N, ...) N
|
|
#define CLAY_PP_RSEQ_N() \
|
|
63,62,61,60, \
|
|
59,58,57,56,55,54,53,52,51,50, \
|
|
49,48,47,46,45,44,43,42,41,40, \
|
|
39,38,37,36,35,34,33,32,31,30, \
|
|
29,28,27,26,25,24,23,22,21,20, \
|
|
19,18,17,16,15,14,13,12,11,10, \
|
|
9,8,7,6,5,4,3,2,1,0
|
|
|
|
#define CLAY_PROP_DEF_KEYWORD(k, v) {.keyword = k, .value = v}
|
|
#define CLAY_PROP_DEF_KEYWORDS(...) (struct clay_prop_keyword_map_in) { \
|
|
.entries = (struct clay_prop_keyword_map_entry_in[]) { \
|
|
__VA_ARGS__ \
|
|
}, \
|
|
.num_entries = CLAY_PP_NARG(__VA_ARGS__)/2 \
|
|
}
|
|
|
|
|
|
clay_prop clay_layout_get_property(clay layout, const char *prop_name);
|
|
|
|
|
|
/*
|
|
* this function allocates a clay_property_map, make sure to free it with clay_map_destroy
|
|
* the values in the returned map are pointers to the actual property values and should not be modified
|
|
*/
|
|
clay_prop_map clay_layout_get_properties(clay layout);
|
|
|
|
|
|
#endif //CLAY_PROPERTY_H
|