Mercurial > molko
comparison libmlk-ui/ui/label.h @ 243:71b3b7036de7
misc: lot of cleanups,
- prefix libraries with libmlk,
- move assets from source directories closes #2520,
- prefix header guards closes #2519
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 28 Nov 2020 22:37:30 +0100 |
parents | libui/ui/label.h@49639211d63b |
children | 08ab73b32832 |
comparison
equal
deleted
inserted
replaced
242:4c24604efcab | 243:71b3b7036de7 |
---|---|
1 /* | |
2 * label.h -- GUI label | |
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_UI_LABEL_H | |
20 #define MOLKO_UI_LABEL_H | |
21 | |
22 /** | |
23 * \file label.h | |
24 * \brief GUI label. | |
25 * \ingroup ui | |
26 */ | |
27 | |
28 #include <stdbool.h> | |
29 | |
30 struct action; | |
31 struct theme; | |
32 | |
33 /** | |
34 * \brief Label flags. | |
35 */ | |
36 enum label_flags { | |
37 LABEL_FLAGS_NONE, /*!< No flags. */ | |
38 LABEL_FLAGS_SHADOW = (1 << 0), /*!< Enable shadow. */ | |
39 }; | |
40 | |
41 /** | |
42 * \brief GUI label. | |
43 */ | |
44 struct label { | |
45 int x; /*!< (+) Position in x. */ | |
46 int y; /*!< (+) Position in y. */ | |
47 const char *text; /*!< (+&) Text to show. */ | |
48 enum label_flags flags; /*!< (+) Optional flags. */ | |
49 const struct theme *theme; /*!< (+&?) Theme to use. */ | |
50 }; | |
51 | |
52 /** | |
53 * Default drawing function. | |
54 * | |
55 * \pre t != NULL | |
56 * \pre label != NULL | |
57 * \param t the theme | |
58 * \param label the label | |
59 */ | |
60 void | |
61 label_draw_default(const struct theme *t, const struct label *label); | |
62 | |
63 /** | |
64 * Tells if the label is usable. | |
65 * | |
66 * \param label the label to check (may be NULL) | |
67 * \return False if label is null or as empty text. | |
68 */ | |
69 bool | |
70 label_ok(const struct label *label); | |
71 | |
72 /** | |
73 * Update the `w` and `h` fields with the dimensions the text would needs with | |
74 * the current theme. | |
75 * | |
76 * \pre label != NULL | |
77 * \param label the label | |
78 * \param w the pointer to width (may be NULL) | |
79 * \param h the pointer to height (may be NULL) | |
80 */ | |
81 void | |
82 label_query(const struct label *label, unsigned int *w, unsigned int *h); | |
83 | |
84 /** | |
85 * Draw the label. | |
86 * | |
87 * \pre label != NULL | |
88 * \param label the label to draw | |
89 */ | |
90 void | |
91 label_draw(const struct label *label); | |
92 | |
93 /** | |
94 * Convert the label into an action. | |
95 * | |
96 * The following field will be set into the action: | |
97 * | |
98 * - act->data: points to label (reference), | |
99 * - act->draw: a wrapper to label_draw. | |
100 * | |
101 * The label being an UI element is considered to never completes, as such | |
102 * you will need to handle this case or to use a custom update function. | |
103 * | |
104 * \pre frame != NULL | |
105 * \pre act != NULL | |
106 * \param label the label to reference | |
107 * \param act the action to fill | |
108 */ | |
109 void | |
110 label_action(struct label *label, struct action *act); | |
111 | |
112 #endif /* !MOLKO_UI_LABEL_H */ |