[theme] lots of progress on fonts
This commit is contained in:
parent
2e0ce61829
commit
04e282eeba
2
src/ax.h
2
src/ax.h
|
@ -29,7 +29,7 @@ int ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm);
|
|||
int ax_set_theme_color(
|
||||
struct ax_ctxt* ax, const char* cat, int64_t rgb);
|
||||
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, size_t fnt_size);
|
||||
int ax_set_theme_iconset(
|
||||
struct ax_ctxt* ax, const char* iconset_dir);
|
||||
|
||||
|
|
|
@ -84,7 +84,6 @@ int ax_set_theme_color(
|
|||
{
|
||||
ASSERT(ax->thmb != NULL, "`ax_set_theme_color' called while not building a theme");
|
||||
int rv;
|
||||
|
||||
enum ax_color_cat cat;
|
||||
if ((rv = ax__string_to_color_cat(cat_name, &cat)) != 0) {
|
||||
#define FMT "invalid color category `%s'"
|
||||
|
@ -93,16 +92,25 @@ int ax_set_theme_color(
|
|||
return rv;
|
||||
#undef FMT
|
||||
}
|
||||
|
||||
ax__theme_set_color(ax->thmb, cat, rgb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ax_set_theme_font(
|
||||
struct ax_ctxt* ax, const char* cat, const char* fnt_path)
|
||||
struct ax_ctxt* ax, const char* cat_name, const char* fnt_path, size_t fnt_size)
|
||||
{
|
||||
ASSERT(ax->thmb != NULL, "`ax_set_theme_font' called while not building a theme");
|
||||
UNIMPLEMENTED();
|
||||
int rv;
|
||||
enum ax_font_cat cat;
|
||||
if ((rv = ax__string_to_font_cat(cat_name, &cat)) != 0) {
|
||||
#define FMT "invalid font category `%s'"
|
||||
sprintf(ax__make_error_buf(ax, strlen(FMT) + strlen(cat_name)),
|
||||
FMT, cat_name);
|
||||
return rv;
|
||||
#undef FMT
|
||||
}
|
||||
ax__theme_set_font(ax->thmb, cat, fnt_path, fnt_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ax_set_theme_iconset(
|
||||
|
|
|
@ -15,11 +15,23 @@ static void theme_init(struct ax_theme* thm)
|
|||
thm->colors[AX_COLOR_ON_SURFACE] =
|
||||
thm->colors[AX_COLOR_ON_PRIMARY] =
|
||||
thm->colors[AX_COLOR_ON_SECONDARY] = 0x000000;
|
||||
|
||||
for (size_t i = 0; i < AX_FONT__COUNT; i++) {
|
||||
thm->font_path[i] = NULL;
|
||||
}
|
||||
|
||||
thm->font_size[AX_FONT_H1] = 96;
|
||||
thm->font_size[AX_FONT_H2] = 60;
|
||||
thm->font_size[AX_FONT_H3] = 34;
|
||||
thm->font_size[AX_FONT_H4] = 24;
|
||||
thm->font_size[AX_FONT_BODY] = 16;
|
||||
thm->font_size[AX_FONT_BUTTON] = 14;
|
||||
}
|
||||
|
||||
void ax__theme_builder_init(struct ax_theme_builder* thmb)
|
||||
{
|
||||
theme_init(&thmb->thm);
|
||||
thmb->dflt_font_path = NULL;
|
||||
}
|
||||
|
||||
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb)
|
||||
|
@ -28,9 +40,30 @@ void ax__theme_builder_cleanup(struct ax_theme_builder* thmb)
|
|||
|
||||
void ax__theme_set_color(
|
||||
struct ax_theme_builder* thmb,
|
||||
enum ax_color_cat cat, int64_t val)
|
||||
enum ax_color_cat cat,
|
||||
int64_t val)
|
||||
{
|
||||
thmb->thm.colors[cat] = val;
|
||||
}
|
||||
|
||||
void ax__theme_set_font(
|
||||
struct ax_theme_builder* thmb,
|
||||
enum ax_font_cat cat,
|
||||
const char* path, size_t size)
|
||||
{
|
||||
const char** dst_path;
|
||||
|
||||
if (cat == AX_FONT__DEFAULT) {
|
||||
dst_path = &thmb->dflt_font_path;
|
||||
} else {
|
||||
ASSERT(cat < AX_FONT__COUNT, "invalid font category");
|
||||
dst_path = &thmb->thm.font_path[cat];
|
||||
thmb->thm.font_size[cat] = size;
|
||||
}
|
||||
|
||||
char* new_path;
|
||||
UNIMPLEMENTED();
|
||||
*dst_path = new_path;
|
||||
}
|
||||
|
||||
void ax__theme_builder_finish(
|
||||
|
@ -55,7 +88,12 @@ int ax__string_to_color_cat(const char* str, enum ax_color_cat* out_cat)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void ax__color_cat_to_string(enum ax_color_cat cat, const char** out_str)
|
||||
int ax__string_to_font_cat(const char* str, enum ax_font_cat* out_cat)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
enum ax_font_cat val;
|
||||
#include "../../_build/font.parser.inc"
|
||||
if (out_cat != NULL) {
|
||||
*out_cat = val;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,3 +8,11 @@
|
|||
(AX_COLOR_ON_SURFACE "on surface")
|
||||
(AX_COLOR_ON_PRIMARY "on primary")
|
||||
(AX_COLOR_ON_SECONDARY "on secondary")]
|
||||
|
||||
[font (AX_FONT_H1 "h1")
|
||||
(AX_FONT_H2 "h2")
|
||||
(AX_FONT_H3 "h3")
|
||||
(AX_FONT_H4 "h4")
|
||||
(AX_FONT_BODY "body")
|
||||
(AX_FONT_BUTTON "button")
|
||||
(AX_FONT__DEFAULT "default")]
|
||||
|
|
|
@ -17,16 +17,31 @@ enum ax_color_cat {
|
|||
AX_COLOR__COUNT,
|
||||
};
|
||||
|
||||
enum ax_font_cat {
|
||||
AX_FONT_H1 = 0,
|
||||
AX_FONT_H2,
|
||||
AX_FONT_H3,
|
||||
AX_FONT_H4,
|
||||
AX_FONT_BODY,
|
||||
AX_FONT_BUTTON,
|
||||
AX_FONT__COUNT,
|
||||
AX_FONT__DEFAULT,
|
||||
};
|
||||
|
||||
struct ax_theme {
|
||||
int64_t colors[AX_COLOR__COUNT];
|
||||
const char* font_path[AX_FONT__COUNT];
|
||||
size_t font_size[AX_FONT__COUNT];
|
||||
};
|
||||
|
||||
struct ax_theme_builder {
|
||||
struct ax_theme thm;
|
||||
const char* dflt_font_path;
|
||||
};
|
||||
|
||||
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);
|
||||
int ax__string_to_font_cat(const char* str, enum ax_font_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_cleanup(struct ax_theme_builder* thmb);
|
||||
|
@ -35,7 +50,30 @@ void ax__theme_set_color(
|
|||
struct ax_theme_builder* thmb,
|
||||
enum ax_color_cat cat, int64_t val);
|
||||
|
||||
void ax__theme_set_font(
|
||||
struct ax_theme_builder* thmb,
|
||||
enum ax_font_cat cat,
|
||||
const char* path, size_t size);
|
||||
|
||||
void ax__theme_builder_finish(
|
||||
struct ax_theme_builder* thmb,
|
||||
struct rgn* rgn,
|
||||
struct ax_theme** out_thm);
|
||||
|
||||
static inline int64_t ax__theme_color(
|
||||
struct ax_theme* thm,
|
||||
enum ax_color_cat i)
|
||||
{
|
||||
return thm->colors[i];
|
||||
}
|
||||
|
||||
static inline const char* ax__theme_font(
|
||||
struct ax_theme* thm,
|
||||
enum ax_font_cat i,
|
||||
size_t* out_size)
|
||||
{
|
||||
if (out_size != NULL) {
|
||||
*out_size = thm->font_size[i];
|
||||
}
|
||||
return thm->font_path[i];
|
||||
}
|
||||
|
|
|
@ -17,3 +17,6 @@
|
|||
|
||||
#define UNIMPLEMENTED() \
|
||||
ASSERT(0, "not implemented")
|
||||
|
||||
#define IMPOSSIBLE(what) \
|
||||
ASSERT(0, "unreachable: " what)
|
||||
|
|
|
@ -9,7 +9,10 @@ int main(void)
|
|||
int rv;
|
||||
|
||||
ax_begin_theme(ax);
|
||||
if ((rv = ax_set_theme_color(ax, "default", 0x112233)) != 0) {
|
||||
if ((rv = ax_set_theme_color(ax, "primary", 0x00ff00)) != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
if ((rv = ax_set_theme_font(ax, "default", "/usr/share/fonts/TTF/DejaVuSans.ttf", 0)) != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue