[theme] theme builder region management

This commit is contained in:
Milo Turner 2020-02-12 12:18:24 -05:00
parent 04e282eeba
commit e5dbad88d3
4 changed files with 20 additions and 29 deletions

View File

@ -13,9 +13,9 @@ struct ax_ctxt {
char* err; char* err;
// theme // theme
struct ax_theme* sel_theme; struct rgn thmb_rgn;
struct ax_theme_builder* thmb0;
struct ax_theme_builder* thmb; struct ax_theme_builder* thmb;
struct ax_theme* sel_theme;
}; };
void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* self_rgn); void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* self_rgn);

View File

@ -41,17 +41,14 @@ void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* init_rgn)
rgn_init(&ax->err_rgn, SMALL); rgn_init(&ax->err_rgn, SMALL);
ax->err = ""; ax->err = "";
ax->sel_theme = NULL; rgn_init(&ax->thmb_rgn, THEME_BUILDER_DESIRED_REGION_SIZE);
ax->thmb0 = ralloc_typed(init_rgn, struct ax_theme_builder, 1);
ax->thmb = NULL; ax->thmb = NULL;
ax->sel_theme = NULL;
} }
void ax__ctxt_cleanup(struct ax_ctxt* ax) void ax__ctxt_cleanup(struct ax_ctxt* ax)
{ {
if (ax->thmb != NULL) { rgn_cleanup(&ax->thmb_rgn);
ax__theme_builder_cleanup(ax->thmb);
}
rgn_cleanup(&ax->err_rgn); rgn_cleanup(&ax->err_rgn);
} }
@ -61,21 +58,15 @@ void ax__ctxt_cleanup(struct ax_ctxt* ax)
void ax_begin_theme(struct ax_ctxt* ax) void ax_begin_theme(struct ax_ctxt* ax)
{ {
if (ax->thmb != NULL) { rgn_clear(&ax->thmb_rgn);
ax__theme_builder_cleanup(ax->thmb); ax->thmb = ralloc_typed(&ax->thmb_rgn, struct ax_theme_builder, 1);
} ax__theme_builder_init(ax->thmb, &ax->thmb_rgn);
ax->thmb = ax->thmb0;
ax__theme_builder_init(ax->thmb);
} }
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)
{ {
ASSERT(ax->thmb != NULL, "`ax_end_theme' called while not building a theme"); ASSERT(ax->thmb != NULL, "`ax_end_theme' called while not building a theme");
ax__theme_builder_finish(ax->thmb, ax->init_rgn, out_thm); ax__theme_builder_finish(ax->thmb, ax->init_rgn, out_thm);
ax__theme_builder_cleanup(ax->thmb);
ax->thmb = NULL;
return 0; return 0;
} }

View File

@ -1,7 +1,6 @@
#include "theme.h" #include "theme.h"
#include "../util.h" #include "../util.h"
#include "../util/region.h"
#define THMB_RGN_SIZE MEDIUM
static void theme_init(struct ax_theme* thm) static void theme_init(struct ax_theme* thm)
{ {
@ -28,14 +27,11 @@ static void theme_init(struct ax_theme* thm)
thm->font_size[AX_FONT_BUTTON] = 14; thm->font_size[AX_FONT_BUTTON] = 14;
} }
void ax__theme_builder_init(struct ax_theme_builder* thmb) void ax__theme_builder_init(struct ax_theme_builder* thmb, struct rgn* rgn)
{ {
theme_init(&thmb->thm); thmb->rgn = rgn;
thmb->dflt_font_path = NULL; thmb->dflt_font_path = NULL;
} theme_init(&thmb->thm);
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb)
{
} }
void ax__theme_set_color( void ax__theme_set_color(

View File

@ -1,7 +1,10 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "../util/region.h" #include <stddef.h>
struct rgn;
#define THEME_BUILDER_DESIRED_REGION_SIZE (16*1024)
enum ax_color_cat { enum ax_color_cat {
AX_COLOR_BACKGROUND = 0, AX_COLOR_BACKGROUND = 0,
@ -35,16 +38,17 @@ struct ax_theme {
}; };
struct ax_theme_builder { struct ax_theme_builder {
struct ax_theme thm; struct rgn* rgn;
const char* dflt_font_path; const char* dflt_font_path;
struct ax_theme thm;
}; };
int ax__string_to_color_cat(const char* str, enum ax_color_cat* out_cat); int ax__string_to_color_cat(const char* str, enum ax_color_cat* out_cat);
int ax__string_to_font_cat(const char* str, enum ax_font_cat* out_cat); 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__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(
void ax__theme_builder_cleanup(struct ax_theme_builder* thmb); struct ax_theme_builder* thmb, struct rgn* rgn);
void ax__theme_set_color( void ax__theme_set_color(
struct ax_theme_builder* thmb, struct ax_theme_builder* thmb,