[theme] theme builder stub

This commit is contained in:
Milo Turner 2020-02-08 08:45:53 -05:00
parent b653137a3e
commit 8f6ab23830
6 changed files with 121 additions and 11 deletions

View File

@ -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);
/* -----------------------------------------------------------------------------

View File

@ -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);

View File

@ -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;
}

17
src/ctxt/theme.c Normal file
View File

@ -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();
}

18
src/ctxt/theme.h Normal file
View File

@ -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);

View File

@ -1,13 +1,18 @@
#include <stdio.h>
#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;
}