Mercurial > molko
diff libmlk-ui/mlk/ui/debug.c @ 626:2c5514927166
ui: improve documentation (debug.h)
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 26 Aug 2023 10:35:53 +0200 |
parents | ed1d3244ed57 |
children |
line wrap: on
line diff
--- a/libmlk-ui/mlk/ui/debug.c Sat Aug 26 09:34:27 2023 +0200 +++ b/libmlk-ui/mlk/ui/debug.c Sat Aug 26 10:35:53 2023 +0200 @@ -24,6 +24,26 @@ #include "debug.h" #include "ui.h" +#include "ui_p.h" + +static void +draw(const char *line, unsigned int n) +{ + struct mlk_font *font; + struct mlk_texture tex; + int x, y; + + font = MLK__STYLE_FONT(mlk_debug_style.font, MLK_UI_FONT_INTERFACE); + + if (mlk_font_render(font, &tex, line, MLK_UI_COLOR_DEBUG) < 0) + return; + + x = mlk_debug_style.padding; + y = (mlk_debug_style.padding * (n + 1)) + (tex.h * n); + + mlk_texture_draw(&tex, x, y); + mlk_texture_finish(&tex); +} struct mlk_debug_options mlk_debug_options = { #if !defined(NDEBUG) @@ -33,15 +53,18 @@ #endif }; +struct mlk_debug_style mlk_debug_style = { + .color = MLK_UI_COLOR_DEBUG, + .padding = 10, + .draw = draw +}; + void mlk_debugf(struct mlk_debug_report *report, const char *fmt, ...) { assert(report); assert(fmt); - if (!mlk_debug_options.enable) - return; - va_list ap; va_start(ap, fmt); @@ -55,27 +78,15 @@ assert(report); assert(fmt); - char line[MLK_DEBUG_LINE_MAX]; - struct mlk_font *font; - struct mlk_texture tex; - int x, y; + char line[MLK_DEBUG_LINE_MAX] = {}; if (!mlk_debug_options.enable) return; vsnprintf(line, sizeof (line), fmt, ap); - // TODO: add style support. - font = &mlk_ui_fonts[MLK_UI_FONT_INTERFACE]; - - if (mlk_font_render(font, &tex, line, MLK_UI_COLOR_DEBUG) < 0) - return; + if (mlk_debug_style.draw) + mlk_debug_style.draw(line, report->count); - // TODO: same here. - x = 10; - y = (10 * (report->count + 1)) + (tex.h * (report->count)); report->count++; - - mlk_texture_draw(&tex, x, y); - mlk_texture_finish(&tex); }