diff --git a/src/ax.h b/src/ax.h index fc04ccd..642c769 100644 --- a/src/ax.h +++ b/src/ax.h @@ -24,16 +24,15 @@ void ax_log(struct ax_ctxt* ax, const char* string); * -------------------------------------------------------------------------- */ void ax_begin_theme(struct ax_ctxt* ax); -void ax_set_theme_color(struct ax_ctxt* ax, const char* name, - uint64_t rgb); -void ax_set_theme_font(struct ax_ctxt* ax, - const char* fnt_cat, - const char* fnt_path, - size_t fnt_size); -void ax_set_theme_iconset(struct ax_ctxt* ax, - const char* iconset_dir); int ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm); +void ax_set_theme_color( + struct ax_ctxt* ax, const char* cat, int64_t rgb); +void ax_set_theme_font( + struct ax_ctxt* ax, const char* cat, const char* fnt_path); +void ax_set_theme_iconset( + struct ax_ctxt* ax, const char* iconset_dir); + void ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm); /* ----------------------------------------------------------------------------- diff --git a/src/ctxt.h b/src/ctxt.h index d25ddb5..3b586b9 100644 --- a/src/ctxt.h +++ b/src/ctxt.h @@ -2,10 +2,20 @@ #include "util/region.h" +struct ax_theme; +struct ax_theme_builder; + struct ax_ctxt { struct rgn* init_rgn; + + // errors struct rgn err_rgn; char* err; + + // theme + struct ax_theme* sel_theme; + struct ax_theme_builder* thmb0; + struct ax_theme_builder* thmb; }; void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* self_rgn); diff --git a/src/ctxt/ctxt.c b/src/ctxt/ctxt.c index ec104a6..e1c8bdc 100644 --- a/src/ctxt/ctxt.c +++ b/src/ctxt/ctxt.c @@ -1,5 +1,7 @@ #include "../ctxt.h" +#include "../util.h" #include "../ax.h" +#include "theme.h" /* ----------------------------------------------------------------------------- * API functions :: init / cleanup @@ -38,9 +40,68 @@ void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* init_rgn) rgn_init(&ax->err_rgn, SMALL); ax->err = ""; + + ax->sel_theme = NULL; + ax->thmb0 = ralloc_typed(init_rgn, struct ax_theme_builder, 1); + ax->thmb = NULL; } void ax__ctxt_cleanup(struct ax_ctxt* ax) { + if (ax->thmb != NULL) { + ax__theme_builder_cleanup(ax->thmb); + } + rgn_cleanup(&ax->err_rgn); } + +/* ----------------------------------------------------------------------------- + * API functions :: themes + * -------------------------------------------------------------------------- */ + +void ax_begin_theme(struct ax_ctxt* ax) +{ + if (ax->thmb != NULL) { + ax__theme_builder_cleanup(ax->thmb); + } + + ax->thmb = ax->thmb0; + ax__theme_builder_init(ax->thmb); +} + +int ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm) +{ + if (ax->thmb == NULL) { + ax->err = "not building a theme"; + return 1; + } + + ax__theme_builder_finish(ax->thmb, out_thm); + ax__theme_builder_cleanup(ax->thmb); + ax->thmb = NULL; + return 0; +} + +void ax_set_theme_color( + struct ax_ctxt* ax, const char* cat, int64_t rgb) +{ + UNIMPLEMENTED(); +} + +void ax_set_theme_font( + struct ax_ctxt* ax, const char* cat, const char* fnt_path) +{ + UNIMPLEMENTED(); +} + +void ax_set_theme_iconset( + struct ax_ctxt* ax, const char* iconset_dir) +{ + UNIMPLEMENTED(); +} + +void ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm) +{ + ASSERT_NON_NULL(thm, "theme"); + ax->sel_theme = thm; +} diff --git a/src/ctxt/theme.c b/src/ctxt/theme.c new file mode 100644 index 0000000..ef4010d --- /dev/null +++ b/src/ctxt/theme.c @@ -0,0 +1,17 @@ +#include "theme.h" +#include "../util.h" + +void ax__theme_builder_init(struct ax_theme_builder* thmb) +{ +} + +void ax__theme_builder_cleanup(struct ax_theme_builder* thmb) +{ +} + +void ax__theme_builder_finish( + struct ax_theme_builder* thmb, + struct ax_theme** out_thm) +{ + UNIMPLEMENTED(); +} diff --git a/src/ctxt/theme.h b/src/ctxt/theme.h new file mode 100644 index 0000000..ab46420 --- /dev/null +++ b/src/ctxt/theme.h @@ -0,0 +1,18 @@ +#pragma once + +#include "../util/region.h" + +struct ax_theme { + struct rgn rgn; +}; + +struct ax_theme_builder { + struct rgn rgn; +}; + +void ax__theme_builder_init(struct ax_theme_builder* thmb); +void ax__theme_builder_cleanup(struct ax_theme_builder* thmb); + +void ax__theme_builder_finish( + struct ax_theme_builder* thmb, + struct ax_theme** out_thm); diff --git a/test/main.c b/test/main.c index 53daea7..52a4cf3 100644 --- a/test/main.c +++ b/test/main.c @@ -1,13 +1,18 @@ #include #include "../src/ax.h" -#include "../src/ctxt.h" +// #include "../src/ctxt.h" int main(void) { struct ax_ctxt* ax = ax_new(); - ax__set_error(ax, "hello world"); - printf("--> %s\n", ax_get_error(ax)); + + ax_begin_theme(ax); + ax_set_theme_color(ax, "default", 0x112233); + struct ax_theme* thm; + ax_end_theme(ax, &thm); + ax_select_theme(ax, thm); + ax_free(ax); return 0; }