[theme] actually doing colors differently
This commit is contained in:
parent
09415951b3
commit
ad6a7bec26
6
src/ax.h
6
src/ax.h
|
@ -26,11 +26,11 @@ void ax_log(struct ax_ctxt* ax, const char* string);
|
||||||
void ax_begin_theme(struct ax_ctxt* ax);
|
void ax_begin_theme(struct ax_ctxt* ax);
|
||||||
int ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm);
|
int ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm);
|
||||||
|
|
||||||
void ax_set_theme_color(
|
int ax_set_theme_color(
|
||||||
struct ax_ctxt* ax, const char* cat, int64_t rgb);
|
struct ax_ctxt* ax, const char* cat, int64_t rgb);
|
||||||
void ax_set_theme_font(
|
int ax_set_theme_font(
|
||||||
struct ax_ctxt* ax, const char* cat, const char* fnt_path);
|
struct ax_ctxt* ax, const char* cat, const char* fnt_path);
|
||||||
void ax_set_theme_iconset(
|
int ax_set_theme_iconset(
|
||||||
struct ax_ctxt* ax, const char* iconset_dir);
|
struct ax_ctxt* ax, const char* iconset_dir);
|
||||||
|
|
||||||
void ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm);
|
void ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm);
|
||||||
|
|
|
@ -79,21 +79,33 @@ int ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax_set_theme_color(
|
int ax_set_theme_color(
|
||||||
struct ax_ctxt* ax, const char* cat, int64_t rgb)
|
struct ax_ctxt* ax, const char* cat_name, int64_t rgb)
|
||||||
{
|
{
|
||||||
ASSERT(ax->thmb != NULL, "`ax_set_theme_color' called while not building a theme");
|
ASSERT(ax->thmb != NULL, "`ax_set_theme_color' called while not building a theme");
|
||||||
ax__theme_add_color(ax->thmb, cat, rgb);
|
int rv;
|
||||||
|
|
||||||
|
enum ax_color_cat cat;
|
||||||
|
if ((rv = ax__string_to_color_cat(cat_name, &cat)) != 0) {
|
||||||
|
#define FMT "invalid color category `%s'"
|
||||||
|
sprintf(ax__make_error_buf(ax, strlen(FMT) + strlen(cat_name)),
|
||||||
|
FMT, cat_name);
|
||||||
|
return rv;
|
||||||
|
#undef FMT
|
||||||
|
}
|
||||||
|
|
||||||
|
ax__theme_set_color(ax->thmb, cat, rgb);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax_set_theme_font(
|
int ax_set_theme_font(
|
||||||
struct ax_ctxt* ax, const char* cat, const char* fnt_path)
|
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");
|
ASSERT(ax->thmb != NULL, "`ax_set_theme_font' called while not building a theme");
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax_set_theme_iconset(
|
int ax_set_theme_iconset(
|
||||||
struct ax_ctxt* ax, const char* iconset_dir)
|
struct ax_ctxt* ax, const char* iconset_dir)
|
||||||
{
|
{
|
||||||
ASSERT(ax->thmb != NULL, "`ax_set_theme_iconset' called while not building a theme");
|
ASSERT(ax->thmb != NULL, "`ax_set_theme_iconset' called while not building a theme");
|
||||||
|
|
|
@ -5,26 +5,30 @@
|
||||||
|
|
||||||
static void theme_init(struct ax_theme* thm)
|
static void theme_init(struct ax_theme* thm)
|
||||||
{
|
{
|
||||||
thm->colors.len = 0;
|
thm->colors[AX_COLOR_BACKGROUND] = 0xffffff;
|
||||||
thm->colors.cap = 0;
|
thm->colors[AX_COLOR_SURFACE] = 0xffffff;
|
||||||
thm->colors.keys = NULL;
|
thm->colors[AX_COLOR_PRIMARY] = 0xff0000;
|
||||||
thm->colors.vals = NULL;
|
thm->colors[AX_COLOR_PRIMARY_ALT] = 0xff4444;
|
||||||
|
thm->colors[AX_COLOR_SECONDARY] = 0x0000ff;
|
||||||
|
thm->colors[AX_COLOR_SECONDARY_ALT] = 0x4444ff;
|
||||||
|
thm->colors[AX_COLOR_ON_BACKGROUND] =
|
||||||
|
thm->colors[AX_COLOR_ON_SURFACE] =
|
||||||
|
thm->colors[AX_COLOR_ON_PRIMARY] =
|
||||||
|
thm->colors[AX_COLOR_ON_SECONDARY] = 0x000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax__theme_builder_init(struct ax_theme_builder* thmb)
|
void ax__theme_builder_init(struct ax_theme_builder* thmb)
|
||||||
{
|
{
|
||||||
rgn_init(&thmb->rgn, THMB_RGN_SIZE);
|
|
||||||
theme_init(&thmb->thm);
|
theme_init(&thmb->thm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb)
|
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb)
|
||||||
{
|
{
|
||||||
rgn_cleanup(&thmb->rgn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax__theme_add_color(
|
void ax__theme_set_color(
|
||||||
struct ax_theme_builder* thmb,
|
struct ax_theme_builder* thmb,
|
||||||
const char* key, int64_t val)
|
enum ax_color_cat cat, int64_t val)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
@ -34,17 +38,20 @@ void ax__theme_builder_finish(
|
||||||
struct rgn* rgn,
|
struct rgn* rgn,
|
||||||
struct ax_theme** out_thm)
|
struct ax_theme** out_thm)
|
||||||
{
|
{
|
||||||
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);
|
struct ax_theme* thm = ralloc_typed(rgn, struct ax_theme, 1);
|
||||||
*thm = thmb->thm;
|
*thm = thmb->thm;
|
||||||
*out_thm = thm;
|
if (out_thm != NULL) {
|
||||||
|
*out_thm = thm;
|
||||||
ax__theme_builder_init(thmb);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ax__string_to_color_cat(const char* str, enum ax_color_cat* out_cat)
|
||||||
|
{
|
||||||
|
// TODO: this
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ax__color_cat_to_string(enum ax_color_cat cat, const char** out_str)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,25 +3,38 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../util/region.h"
|
#include "../util/region.h"
|
||||||
|
|
||||||
|
enum ax_color_cat {
|
||||||
|
AX_COLOR_BACKGROUND = 0,
|
||||||
|
AX_COLOR_SURFACE,
|
||||||
|
AX_COLOR_PRIMARY,
|
||||||
|
AX_COLOR_PRIMARY_ALT,
|
||||||
|
AX_COLOR_SECONDARY,
|
||||||
|
AX_COLOR_SECONDARY_ALT,
|
||||||
|
AX_COLOR_ON_BACKGROUND,
|
||||||
|
AX_COLOR_ON_SURFACE,
|
||||||
|
AX_COLOR_ON_PRIMARY,
|
||||||
|
AX_COLOR_ON_SECONDARY,
|
||||||
|
AX_COLOR__COUNT,
|
||||||
|
AX_COLOR__DEFAULT,
|
||||||
|
};
|
||||||
|
|
||||||
struct ax_theme {
|
struct ax_theme {
|
||||||
struct {
|
int64_t colors[AX_COLOR__COUNT];
|
||||||
size_t len, cap;
|
|
||||||
const char** keys;
|
|
||||||
int64_t* vals;
|
|
||||||
} colors;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ax_theme_builder {
|
struct ax_theme_builder {
|
||||||
struct rgn rgn;
|
|
||||||
struct ax_theme thm;
|
struct ax_theme thm;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int ax__string_to_color_cat(const char* str, enum ax_color_cat* out_cat);
|
||||||
|
void ax__color_cat_to_string(enum ax_color_cat cat, const char** out_str);
|
||||||
|
|
||||||
void ax__theme_builder_init(struct ax_theme_builder* thmb);
|
void ax__theme_builder_init(struct ax_theme_builder* thmb);
|
||||||
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb);
|
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb);
|
||||||
|
|
||||||
void ax__theme_add_color(
|
void ax__theme_set_color(
|
||||||
struct ax_theme_builder* thmb,
|
struct ax_theme_builder* thmb,
|
||||||
const char* key, int64_t val);
|
enum ax_color_cat cat, int64_t val);
|
||||||
|
|
||||||
void ax__theme_builder_finish(
|
void ax__theme_builder_finish(
|
||||||
struct ax_theme_builder* thmb,
|
struct ax_theme_builder* thmb,
|
||||||
|
|
12
test/main.c
12
test/main.c
|
@ -6,13 +6,21 @@
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
struct ax_ctxt* ax = ax_new();
|
struct ax_ctxt* ax = ax_new();
|
||||||
|
int rv;
|
||||||
|
|
||||||
ax_begin_theme(ax);
|
ax_begin_theme(ax);
|
||||||
ax_set_theme_color(ax, "default", 0x112233);
|
if ((rv = ax_set_theme_color(ax, "default", 0x112233)) != 0) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
struct ax_theme* thm;
|
struct ax_theme* thm;
|
||||||
ax_end_theme(ax, &thm);
|
ax_end_theme(ax, &thm);
|
||||||
ax_select_theme(ax, thm);
|
ax_select_theme(ax, thm);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (rv != 0) {
|
||||||
|
printf("error: %s\n", ax_get_error(ax));
|
||||||
|
}
|
||||||
ax_free(ax);
|
ax_free(ax);
|
||||||
return 0;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue