comparison libcore/core/theme.h @ 121:789b23e01f52

misc: reorganize hierarchy, closes #2490
author David Demelier <markand@malikania.fr>
date Mon, 05 Oct 2020 13:25:06 +0200
parents src/core/theme.h@3bd0d3a39e30
children c46f80820b42
comparison
equal deleted inserted replaced
120:b3429b26d60d 121:789b23e01f52
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_INTERFACE, /*!< Font for interface elements. */
40 THEME_FONT_LAST /*!< Unused. */
41 };
42
43 /**
44 * \brief Theme colors.
45 */
46 enum theme_color {
47 THEME_COLOR_NORMAL, /*!< Normal font color. */
48 THEME_COLOR_SELECTED, /*!< Font color for selected elements. */
49 THEME_COLOR_SHADOW, /*!< Shadow color. */
50 THEME_COLOR_LAST /*!< Unused. */
51 };
52
53 /**
54 * \brief Abstract theme structure.
55 */
56 struct theme {
57 /**
58 * (RW, ref) Fonts catalog.
59 */
60 struct font *fonts[THEME_FONT_LAST];
61
62 /**
63 * (RW) Miscellaneous colors.
64 */
65 unsigned long colors[THEME_COLOR_LAST];
66
67 /**
68 * (RW) Padding between GUI elements.
69 */
70 unsigned int padding;
71
72 /**
73 * Draw a frame.
74 *
75 * This function is used to draw a box usually as a container where UI
76 * elements will be put.
77 *
78 * \see \ref theme_draw_frame
79 */
80 void (*draw_frame)(struct theme *, const struct frame *);
81
82 /**
83 * Draw a label.
84 *
85 * \see \ref theme_draw_label
86 */
87 void (*draw_label)(struct theme *, const struct label *);
88
89 /**
90 * Draw a button.
91 *
92 * \see \ref theme_draw_button
93 */
94 void (*draw_button)(struct theme *, const struct button *);
95
96 /**
97 * Draw a checkbox.
98 *
99 * \see \ref theme_draw_button
100 */
101 void (*draw_checkbox)(struct theme *t, const struct checkbox *);
102 };
103
104 /**
105 * Initialize the theming system.
106 *
107 * \return false on errors
108 * \warning This function must be called before any other theme functions.
109 */
110 bool
111 theme_init(void);
112
113 /**
114 * Get a reference to the default theme.
115 *
116 * \return A non-owning pointer to a static storage for the default theme
117 */
118 struct theme *
119 theme_default(void);
120
121 /**
122 * Get the desired padding between GUI elements.
123 *
124 * \param t the theme to use (may be NULL)
125 * \return the padding in pixels
126 */
127 unsigned int
128 theme_padding(const struct theme *t);
129
130 /**
131 * Draw a frame.
132 *
133 * \pre frame != NULL
134 * \param t the theme to use (may be NULL)
135 * \param frame the frame
136 */
137 void
138 theme_draw_frame(struct theme *t, const struct frame *frame);
139
140 /**
141 * Draw a label.
142 *
143 * \pre label != NULL
144 * \param t the theme to use (may be NULL)
145 * \param label the label
146 */
147 void
148 theme_draw_label(struct theme *t, const struct label *label);
149
150 /**
151 * Draw a button.
152 *
153 * \pre button != NULL
154 * \param t the theme to use (may be NULL)
155 * \param button the button
156 */
157 void
158 theme_draw_button(struct theme *t, const struct button *button);
159
160 /**
161 * Draw a checkbox.
162 *
163 * \param t the theme to use (may be NULL)
164 * \param cb the checkbox
165 */
166 void
167 theme_draw_checkbox(struct theme *t, const struct checkbox *cb);
168
169 /**
170 * Close associated resources.
171 */
172 void
173 theme_finish(void);
174
175 #endif /* !MOLKO_THEME_H */