theme.h (2400B)
1 /* 2 * Copyright (c) 2022-2024 lumidify <nobody@lumidify.org> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef LTK_THEME_H 18 #define LTK_THEME_H 19 20 #include <stddef.h> 21 #include "color.h" 22 #include "graphics.h" 23 24 typedef enum { 25 THEME_STRING, 26 THEME_COLOR, 27 THEME_INT, 28 THEME_BOOL, 29 THEME_BORDERSIDES, 30 THEME_SIZE, 31 } ltk_theme_datatype; 32 33 typedef struct { 34 char *key; 35 ltk_theme_datatype type; 36 /* Note: Bool and int are both integers, but they are 37 separate just to make it a bit clearer */ 38 union { 39 char **str; 40 ltk_color **color; 41 int *i; 42 int *b; 43 ltk_border_sides *border; 44 ltk_size *size; 45 } ptr; 46 /* Note: The default color is also given as a string 47 because it has to be allocated first (it is only a 48 different entry in the union in order to make it 49 a bit clearer) */ 50 union { 51 char *str; 52 char *color; 53 int i; 54 int b; 55 ltk_border_sides border; 56 ltk_size size; 57 } defaultval; 58 /* FIXME: min/max doesn't make too much sense for sizes since they 59 can use different units, but that shouldn't matter for now because 60 min/max is only used as a sanity check to avoid extreme sizes or 61 negative sizes where that isn't allowed */ 62 int min, max; /* only for integers or sizes */ 63 int initialized; 64 } ltk_theme_parseinfo; 65 66 /* Both return 1 on error, 0 on success */ 67 int ltk_theme_handle_value(ltk_renderdata *renderdata, char *debug_name, const char *prop, const char *value, ltk_theme_parseinfo *parseinfo, size_t len, int *sorted); 68 int ltk_theme_fill_defaults(ltk_renderdata *renderdata, char *debug_name, ltk_theme_parseinfo *parseinfo, size_t len); 69 void ltk_theme_uninitialize(ltk_renderdata *renderdata, ltk_theme_parseinfo *parseinfo, size_t len); 70 71 #endif /* LTK_THEME_H */