[theme] progress towards adding colors
This commit is contained in:
parent
9837efa5c0
commit
09415951b3
|
@ -71,12 +71,9 @@ void ax_begin_theme(struct ax_ctxt* ax)
|
|||
|
||||
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;
|
||||
}
|
||||
ASSERT(ax->thmb != NULL, "`ax_end_theme' called while not building a theme");
|
||||
|
||||
ax__theme_builder_finish(ax->thmb, out_thm);
|
||||
ax__theme_builder_finish(ax->thmb, ax->init_rgn, out_thm);
|
||||
ax__theme_builder_cleanup(ax->thmb);
|
||||
ax->thmb = NULL;
|
||||
return 0;
|
||||
|
@ -85,18 +82,21 @@ 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)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
ASSERT(ax->thmb != NULL, "`ax_set_theme_color' called while not building a theme");
|
||||
ax__theme_add_color(ax->thmb, cat, rgb);
|
||||
}
|
||||
|
||||
void ax_set_theme_font(
|
||||
struct ax_ctxt* ax, const char* cat, const char* fnt_path)
|
||||
{
|
||||
ASSERT(ax->thmb != NULL, "`ax_set_theme_font' called while not building a theme");
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
void ax_set_theme_iconset(
|
||||
struct ax_ctxt* ax, const char* iconset_dir)
|
||||
{
|
||||
ASSERT(ax->thmb != NULL, "`ax_set_theme_iconset' called while not building a theme");
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,50 @@
|
|||
#include "theme.h"
|
||||
#include "../util.h"
|
||||
|
||||
#define THMB_RGN_SIZE MEDIUM
|
||||
|
||||
static void theme_init(struct ax_theme* thm)
|
||||
{
|
||||
thm->colors.len = 0;
|
||||
thm->colors.cap = 0;
|
||||
thm->colors.keys = NULL;
|
||||
thm->colors.vals = NULL;
|
||||
}
|
||||
|
||||
void ax__theme_builder_init(struct ax_theme_builder* thmb)
|
||||
{
|
||||
rgn_init(&thmb->rgn, THMB_RGN_SIZE);
|
||||
theme_init(&thmb->thm);
|
||||
}
|
||||
|
||||
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb)
|
||||
{
|
||||
rgn_cleanup(&thmb->rgn);
|
||||
}
|
||||
|
||||
void ax__theme_add_color(
|
||||
struct ax_theme_builder* thmb,
|
||||
const char* key, int64_t val)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
void ax__theme_builder_finish(
|
||||
struct ax_theme_builder* thmb,
|
||||
struct rgn* rgn,
|
||||
struct ax_theme** out_thm)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
ASSERT_NON_NULL(out_thm, "out_thm");
|
||||
|
||||
// TODO: this might be a common pattern, to transfer ownership
|
||||
// of 'thmb->rgn' to 'rgn' by allocating and pinning
|
||||
struct rgn* thm_internal_rgn = ralloc_typed(rgn, struct rgn, 1);
|
||||
*thm_internal_rgn = thmb->rgn;
|
||||
rgn_pin(rgn, thm_internal_rgn, (void*) rgn_cleanup);
|
||||
|
||||
struct ax_theme* thm = ralloc_typed(rgn, struct ax_theme, 1);
|
||||
*thm = thmb->thm;
|
||||
*out_thm = thm;
|
||||
|
||||
ax__theme_builder_init(thmb);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../util/region.h"
|
||||
|
||||
struct ax_theme {
|
||||
struct rgn rgn;
|
||||
struct {
|
||||
size_t len, cap;
|
||||
const char** keys;
|
||||
int64_t* vals;
|
||||
} colors;
|
||||
};
|
||||
|
||||
struct ax_theme_builder {
|
||||
struct rgn rgn;
|
||||
struct ax_theme thm;
|
||||
};
|
||||
|
||||
void ax__theme_builder_init(struct ax_theme_builder* thmb);
|
||||
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb);
|
||||
|
||||
void ax__theme_add_color(
|
||||
struct ax_theme_builder* thmb,
|
||||
const char* key, int64_t val);
|
||||
|
||||
void ax__theme_builder_finish(
|
||||
struct ax_theme_builder* thmb,
|
||||
struct rgn* rgn,
|
||||
struct ax_theme** out_thm);
|
||||
|
|
Loading…
Reference in New Issue