Mercurial > molko
comparison libui/ui/theme.h @ 148:c577c15df07f
misc: split libraries, closes #2496
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 15 Oct 2020 10:32:18 +0200 |
parents | libcore/core/theme.h@b386d25832c8 |
children | b19d076856d2 |
comparison
equal
deleted
inserted
replaced
147:b386d25832c8 | 148:c577c15df07f |
---|---|
1 /* | |
2 * theme.h -- abstract theming | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef MOLKO_THEME_H | |
20 #define MOLKO_THEME_H | |
21 | |
22 /** | |
23 * \file theme.h | |
24 * \brief Abstract theming. | |
25 */ | |
26 | |
27 #include <stdbool.h> | |
28 | |
29 struct checkbox; | |
30 struct button; | |
31 struct font; | |
32 struct frame; | |
33 struct label; | |
34 | |
35 /** | |
36 * \brief Font component. | |
37 */ | |
38 enum theme_font { | |
39 THEME_FONT_DEBUG, /*!< Font for debug messages. */ | |
40 THEME_FONT_INTERFACE, /*!< Font for interface elements. */ | |
41 THEME_FONT_LAST /*!< Unused. */ | |
42 }; | |
43 | |
44 /** | |
45 * \brief Theme colors. | |
46 */ | |
47 enum theme_color { | |
48 THEME_COLOR_DEBUG, /*!< Debug color font. */ | |
49 THEME_COLOR_NORMAL, /*!< Normal font color. */ | |
50 THEME_COLOR_SELECTED, /*!< Font color for selected elements. */ | |
51 THEME_COLOR_SHADOW, /*!< Shadow color. */ | |
52 THEME_COLOR_LAST /*!< Unused. */ | |
53 }; | |
54 | |
55 /** | |
56 * \brief Abstract theme structure. | |
57 */ | |
58 struct theme { | |
59 /** | |
60 * (+&) Fonts catalog. | |
61 */ | |
62 struct font *fonts[THEME_FONT_LAST]; | |
63 | |
64 /** | |
65 * (+) Miscellaneous colors. | |
66 */ | |
67 unsigned long colors[THEME_COLOR_LAST]; | |
68 | |
69 /** | |
70 * (+) Padding between GUI elements. | |
71 */ | |
72 unsigned int padding; | |
73 | |
74 /** | |
75 * (+) Draw a frame. | |
76 * | |
77 * This function is used to draw a box usually as a container where UI | |
78 * elements will be put. | |
79 * | |
80 * \see \ref theme_draw_frame | |
81 */ | |
82 void (*draw_frame)(struct theme *, const struct frame *); | |
83 | |
84 /** | |
85 * (+) Draw a label. | |
86 * | |
87 * \see \ref theme_draw_label | |
88 */ | |
89 void (*draw_label)(struct theme *, const struct label *); | |
90 | |
91 /** | |
92 * (+) Draw a button. | |
93 * | |
94 * \see \ref theme_draw_button | |
95 */ | |
96 void (*draw_button)(struct theme *, const struct button *); | |
97 | |
98 /** | |
99 * (+) Draw a checkbox. | |
100 * | |
101 * \see \ref theme_draw_button | |
102 */ | |
103 void (*draw_checkbox)(struct theme *t, const struct checkbox *); | |
104 }; | |
105 | |
106 /** | |
107 * Initialize the theming system. | |
108 * | |
109 * \return false on errors | |
110 * \warning This function must be called before any other theme functions. | |
111 */ | |
112 bool | |
113 theme_init(void); | |
114 | |
115 /** | |
116 * Get a reference to the default theme. | |
117 * | |
118 * \return A non-owning pointer to a static storage for the default theme | |
119 */ | |
120 struct theme * | |
121 theme_default(void); | |
122 | |
123 /** | |
124 * Convenient shortcut to shallow copy src into dst. | |
125 * | |
126 * Use this function when you want your own local copy of a theme because you | |
127 * want to modify some attributes. | |
128 * | |
129 * This is a shortcut to `memcpy(dst, src, sizeof (*src))`. | |
130 * | |
131 * \pre dst != NULL | |
132 * \param dst the destination theme | |
133 * \param src the source theme (may be NULL) | |
134 * \note Resources are not cloned, internal pointers will adress the same | |
135 * regions. | |
136 */ | |
137 void | |
138 theme_shallow(struct theme *dst, const struct theme *src); | |
139 | |
140 /** | |
141 * Get the desired padding between GUI elements. | |
142 * | |
143 * \param t the theme to use (may be NULL) | |
144 * \return the padding in pixels | |
145 */ | |
146 unsigned int | |
147 theme_padding(const struct theme *t); | |
148 | |
149 /** | |
150 * Draw a frame. | |
151 * | |
152 * \pre frame != NULL | |
153 * \param t the theme to use (may be NULL) | |
154 * \param frame the frame | |
155 */ | |
156 void | |
157 theme_draw_frame(struct theme *t, const struct frame *frame); | |
158 | |
159 /** | |
160 * Draw a label. | |
161 * | |
162 * \pre label != NULL | |
163 * \param t the theme to use (may be NULL) | |
164 * \param label the label | |
165 */ | |
166 void | |
167 theme_draw_label(struct theme *t, const struct label *label); | |
168 | |
169 /** | |
170 * Draw a button. | |
171 * | |
172 * \pre button != NULL | |
173 * \param t the theme to use (may be NULL) | |
174 * \param button the button | |
175 */ | |
176 void | |
177 theme_draw_button(struct theme *t, const struct button *button); | |
178 | |
179 /** | |
180 * Draw a checkbox. | |
181 * | |
182 * \param t the theme to use (may be NULL) | |
183 * \param cb the checkbox | |
184 */ | |
185 void | |
186 theme_draw_checkbox(struct theme *t, const struct checkbox *cb); | |
187 | |
188 /** | |
189 * Close associated resources. | |
190 */ | |
191 void | |
192 theme_finish(void); | |
193 | |
194 #endif /* !MOLKO_THEME_H */ |