Просмотр исходного кода

Pass color array in as a parameter

Robert Winkler 5 лет назад
Родитель
Сommit
2327f81a7d
2 измененных файлов с 23 добавлено и 13 удалено
  1. 21 2
      demo/sdl_opengl3/main.c
  2. 2 11
      demo/style_configurator.c

+ 21 - 2
demo/sdl_opengl3/main.c

@@ -131,6 +131,25 @@ int main(int argc, char *argv[])
     /*nk_style_load_all_cursors(ctx, atlas->cursors);*/
     /*nk_style_set_font(ctx, &roboto->handle);*/}
 
+    /* style.c */
+    #ifdef INCLUDE_STYLE
+    /* ease regression testing during Nuklear release process; not needed for anything else */
+    #ifdef STYLE_WHITE
+    set_style(ctx, THEME_WHITE);
+    #elif defined(STYLE_RED)
+    set_style(ctx, THEME_RED);
+    #elif defined(STYLE_BLUE)
+    set_style(ctx, THEME_BLUE);
+    #elif defined(STYLE_DARK)
+    set_style(ctx, THEME_DARK);
+    #endif
+    #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)
     {
@@ -188,8 +207,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);

+ 2 - 11
demo/style_configurator.c

@@ -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;
@@ -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)) {
@@ -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);
 		}