Skip to content

Commit

Permalink
Pass color array in as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rswinkle committed Mar 31, 2020
1 parent dfff31f commit 6bd90a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
9 changes: 7 additions & 2 deletions demo/sdl_opengl3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ int main(int argc, char *argv[])
/*set_style(ctx, THEME_DARK);*/
#endif

#ifdef INCLUDE_CONFIGURATOR
static struct nk_color color_table[NK_COLOR_COUNT];
memcpy(color_table, nk_default_color_style, sizeof(color_table));
#endif

bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{
Expand Down Expand Up @@ -183,8 +188,8 @@ int main(int argc, char *argv[])
#ifdef INCLUDE_OVERVIEW
overview(ctx);
#endif
#ifdef INCLUDE_OVERVIEW
style_configurator(ctx);
#ifdef INCLUDE_CONFIGURATOR
style_configurator(ctx, color_table);
#endif
#ifdef INCLUDE_NODE_EDITOR
node_editor(ctx);
Expand Down
13 changes: 2 additions & 11 deletions demo/style_configurator.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ style_window(struct nk_context* ctx, struct nk_style_window* out_style)
}

static int
style_configurator(struct nk_context *ctx)
style_configurator(struct nk_context *ctx, struct nk_color color_table[NK_COLOR_COUNT])
{
/* window flags */
int border = nk_true;
Expand All @@ -678,15 +678,6 @@ style_configurator(struct nk_context *ctx)

struct nk_style *style = &ctx->style;

// TODO better way?
static int initialized = nk_false;
static struct nk_color color_table[NK_COLOR_COUNT];

if (!initialized) {
memcpy(color_table, nk_default_color_style, sizeof(color_table));
initialized = nk_true;
}

if (nk_begin(ctx, "Configurator", nk_rect(10, 10, 400, 600), window_flags))
{
if (nk_tree_push(ctx, NK_TREE_TAB, "Global Colors", NK_MINIMIZED)) {
Expand Down Expand Up @@ -804,7 +795,7 @@ style_configurator(struct nk_context *ctx)

nk_layout_row_dynamic(ctx, 30, 1);
if (nk_button_label(ctx, "Reset all styles to defaults")) {
memcpy(color_table, nk_default_color_style, sizeof(color_table));
memcpy(color_table, nk_default_color_style, sizeof(nk_default_color_style));
nk_style_default(ctx);
}

Expand Down

0 comments on commit 6bd90a9

Please sign in to comment.