Mercurial > molko
comparison libui/ui/debug.h @ 154:2252f9efac9a
ui: remove style from debug_report, closes #2499
While here add an example of usage and rename the function similar to trace.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 16 Oct 2020 13:04:48 +0200 |
parents | c577c15df07f |
children | aab824406d3d |
comparison
equal
deleted
inserted
replaced
153:aa6e70e330a1 | 154:2252f9efac9a |
---|---|
30 * | 30 * |
31 * Predefined core states may print debugging information if | 31 * Predefined core states may print debugging information if |
32 * debug_options.enabled variable is set to true. However, you need to specify | 32 * debug_options.enabled variable is set to true. However, you need to specify |
33 * the font to use in order to work. | 33 * the font to use in order to work. |
34 * | 34 * |
35 * Each call to \ref debug_printf or \ref debug_vprintf automatically adjust | 35 * Each call to \ref debug or \ref vdebug automatically adjust |
36 * next coordinate for rendering the text. As such, user may simply print | 36 * next coordinate for rendering the text. As such, user may simply print |
37 * several lines of text without having to deal with that manually. | 37 * several lines of text without having to deal with that manually. |
38 * | |
39 * Example, activate global debugging. | |
40 * | |
41 * \code | |
42 * struct font *f = font_openf("foo.ttf", 10); | |
43 * | |
44 * if (!f) | |
45 * error_fatal(); | |
46 * | |
47 * debug_options.default_font = f; | |
48 * debug_options.enabled = true; | |
49 * \endcode | |
50 * | |
51 * Example, print debugging information manually. | |
52 * | |
53 * \code | |
54 * struct debug_report report = { | |
55 * .color = 0x00ff00ff, | |
56 * .font = myfont // Optional if debug_options.default_font is set. | |
57 * }; | |
58 * | |
59 * debug_printf("current position: %d, %d\n", x, y); | |
60 * \endcode | |
61 */ | 38 */ |
62 | 39 |
63 #include <stdbool.h> | 40 #include <stdbool.h> |
64 #include <stdarg.h> | 41 #include <stdarg.h> |
65 | 42 |
66 #include <core/font.h> | 43 #include <core/font.h> |
44 #include <core/plat.h> | |
67 | 45 |
68 /** | 46 /** |
69 * Maximum content length per report. | 47 * Maximum content length per report. |
70 */ | 48 */ |
71 #define DEBUG_LINE_MAX 1024 | 49 #define DEBUG_LINE_MAX 1024 |
87 * | 65 * |
88 * Use this structure each time you need to print one or more messages. | 66 * Use this structure each time you need to print one or more messages. |
89 */ | 67 */ |
90 struct debug_report { | 68 struct debug_report { |
91 struct theme *theme; /*!< (+&?) Theme to use. */ | 69 struct theme *theme; /*!< (+&?) Theme to use. */ |
92 unsigned long color; /*!< (+) Font foreground color to use. */ | |
93 unsigned int count; /*!< (-) Number of messages already printed. */ | 70 unsigned int count; /*!< (-) Number of messages already printed. */ |
94 }; | 71 }; |
95 | 72 |
96 /** | 73 /** |
97 * Global debugging options. | 74 * Global debugging options. |
98 */ | 75 */ |
99 extern struct debug_options debug_options; | 76 extern struct debug_options debug_options; |
100 | |
101 /** | |
102 * Convenient macro to initialize \ref debug_report with default values. | |
103 */ | |
104 #define DEBUG_INIT_DEFAULTS { \ | |
105 .font = debug_options.default_font, \ | |
106 .color = debug_options.default_color, \ | |
107 .style = debug_options.default_style \ | |
108 } | |
109 | 77 |
110 /** | 78 /** |
111 * Print debugging information into the screen. | 79 * Print debugging information into the screen. |
112 * | 80 * |
113 * \pre report != NULL | 81 * \pre report != NULL |
116 * \param fmt the printf(3) format string | 84 * \param fmt the printf(3) format string |
117 * \note The message length must not exceed DEBUG_LINE_MAX, otherwise its | 85 * \note The message length must not exceed DEBUG_LINE_MAX, otherwise its |
118 * result is truncated. | 86 * result is truncated. |
119 */ | 87 */ |
120 void | 88 void |
121 debug_printf(struct debug_report *report, const char *fmt, ...); | 89 debug(struct debug_report *report, const char *fmt, ...) PLAT_PRINTF(2, 3); |
122 | 90 |
123 /** | 91 /** |
124 * Similar to \ref debug_printf but with a va_list object. | 92 * Similar to \ref debug with a va_list arguments pointer. |
125 * | 93 * |
126 * \see \ref debug_printf | 94 * \pre fmt != NULL |
95 * \param report the reporting context | |
96 * \param fmt the printf(3) format string | |
97 * \param ap the argument list | |
127 */ | 98 */ |
128 void | 99 void |
129 debug_vprintf(struct debug_report *report, const char *fmt, va_list ap); | 100 vdebug(struct debug_report *report, const char *fmt, va_list ap) PLAT_PRINTF(2, 0); |
130 | 101 |
131 #endif /* !MOLKO_DEBUG_H */ | 102 #endif /* !MOLKO_DEBUG_H */ |