[test] theme debugging

This commit is contained in:
Milo Turner 2020-02-12 12:40:00 -05:00
parent b918ffca5e
commit 45962af503
3 changed files with 40 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#include "theme.h"
#include "../util.h"
#include "../util/region.h"
#include <inttypes.h>
static const char* default_font_path(struct rgn* rgn)
{
@ -53,12 +54,18 @@ void ax__theme_set_font(
enum ax_font_cat cat,
const char* path, size_t size)
{
const char** out_path;
if (cat == AX_FONT__DEFAULT) {
thmb->dflt_font_path = rstrdup(thmb->rgn, path);
out_path = &thmb->dflt_font_path;
} else {
ASSERT(cat < AX_FONT__COUNT, "invalid font category");
thmb->thm.font_size[cat] = size;
thmb->thm.font_path[cat] = rstrdup(thmb->rgn, path);
out_path = &thmb->thm.font_path[cat];
}
if (path == NULL) {
*out_path = NULL;
} else {
*out_path = rstrdup(thmb->rgn, path);
}
}
@ -110,3 +117,23 @@ int ax__string_to_font_cat(const char* str, enum ax_font_cat* out_cat)
}
return 0;
}
void ax__debug_theme(struct ax_theme* thm)
{
printf("=========\nTHEME INFO:\n");
for (size_t i = 0; i < AX_COLOR__COUNT; i++) {
enum ax_color_cat val = i;
const char* str;
#include "../../_build/color.printer.inc"
printf(" color `%s': #%06" PRIx64 "\n",
str, thm->colors[i]);
}
printf("--------\n");
for (size_t i = 0; i < AX_FONT__COUNT; i++) {
enum ax_font_cat val = i;
const char* str;
#include "../../_build/font.printer.inc"
printf(" font `%s': \"%s\", size %zu\n",
str, thm->font_path[i], thm->font_size[i]);
}
}

View File

@ -81,3 +81,7 @@ static inline const char* ax__theme_font(
}
return thm->font_path[i];
}
void ax__debug_theme(struct ax_theme* thm);

View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include "../src/ax.h"
// #include "../src/ctxt.h"
#include "../src/ctxt/theme.h"
int main(void)
@ -15,10 +15,15 @@ int main(void)
if ((rv = ax_set_theme_font(ax, "default", "/usr/share/fonts/TTF/DejaVuSans.ttf", 0)) != 0) {
goto cleanup;
}
if ((rv = ax_set_theme_font(ax, "h1", NULL, 95)) != 0) {
goto cleanup;
}
struct ax_theme* thm;
ax_end_theme(ax, &thm);
ax_select_theme(ax, thm);
// ax_select_theme(ax, thm);
ax__debug_theme(thm);
cleanup:
if (rv != 0) {