diff --git a/src/ctxt/theme.c b/src/ctxt/theme.c index f449fb4..77c2387 100644 --- a/src/ctxt/theme.c +++ b/src/ctxt/theme.c @@ -1,6 +1,7 @@ #include "theme.h" #include "../util.h" #include "../util/region.h" +#include 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]); + } +} diff --git a/src/ctxt/theme.h b/src/ctxt/theme.h index 4dc237d..0a7fbc6 100644 --- a/src/ctxt/theme.h +++ b/src/ctxt/theme.h @@ -81,3 +81,7 @@ static inline const char* ax__theme_font( } return thm->font_path[i]; } + + + +void ax__debug_theme(struct ax_theme* thm); diff --git a/test/main.c b/test/main.c index b348c61..07dffb8 100644 --- a/test/main.c +++ b/test/main.c @@ -1,6 +1,6 @@ #include #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) {