diff --git a/CHANGELOG.md b/CHANGELOG.md index 05741d3..7d25b96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +- 2016/10/29 (1.170)- Pulled `nk_panel` memory management into nuklear and out of + the hands of the user. From now on users don't have to care + about panels unless they care about some information. If you + still need the panel just call `nk_window_get_panel`. - 2016/10/21 (1.160)- Changed widget border drawing to stroked rectangle from filled rectangle for less overdraw and widget background transparency. - 2016/10/18 (1.160)- Added `nk_edit_focus` for manually edit widget focus control diff --git a/Readme.md b/Readme.md index c2c1a60..29d56d3 100644 --- a/Readme.md +++ b/Readme.md @@ -58,8 +58,7 @@ int op = EASY; float value = 0.6f; int i = 20; -struct nk_panel layout; -if (nk_begin(&ctx, &layout, "Show", nk_rect(50, 50, 220, 220), +if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { /* fixed widget pixel width */ nk_layout_row_static(&ctx, 30, 80, 1); diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index 63c3c8a..bc0dc64 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #define COBJMACROS #define WIN32_LEAN_AND_MEAN #include @@ -209,8 +209,7 @@ int main(void) nk_input_end(ctx); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 230, 250), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -227,11 +226,10 @@ int main(void) nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); - {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); - if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { + if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); @@ -240,9 +238,9 @@ int main(void) background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); - }} + } } - nk_end(ctx);} + nk_end(ctx); if (nk_window_is_closed(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ diff --git a/demo/d3d11/nuklear_d3d11.h b/demo/d3d11/nuklear_d3d11.h index 7de383e..68b067f 100644 --- a/demo/d3d11/nuklear_d3d11.h +++ b/demo/d3d11/nuklear_d3d11.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/gdi/main.c b/demo/gdi/main.c index d9a80ca..e82cd16 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #define WIN32_LEAN_AND_MEAN #include #include @@ -123,8 +123,7 @@ int main(void) nk_input_end(ctx); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -141,7 +140,7 @@ int main(void) nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } - nk_end(ctx);} + nk_end(ctx); if (nk_window_is_closed(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h index 72b8e5e..e2792e4 100644 --- a/demo/gdi/nuklear_gdi.h +++ b/demo/gdi/nuklear_gdi.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/gdip/main.c b/demo/gdip/main.c index 85b07cd..7d623e7 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #define WIN32_LEAN_AND_MEAN #include #include @@ -118,8 +118,7 @@ int main(void) nk_input_end(ctx); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -136,7 +135,7 @@ int main(void) nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } - nk_end(ctx);} + nk_end(ctx); if (nk_window_is_closed(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ diff --git a/demo/gdip/nuklear_gdip.h b/demo/gdip/nuklear_gdip.h index 0b620ed..592887a 100644 --- a/demo/gdip/nuklear_gdip.h +++ b/demo/gdip/nuklear_gdip.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c index f5ea3b0..1c0f284 100644 --- a/demo/glfw_opengl2/main.c +++ b/demo/glfw_opengl2/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #include #include #include @@ -104,8 +104,7 @@ int main(void) nk_glfw3_new_frame(); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 230, 250), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -123,11 +122,10 @@ int main(void) nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); - {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); - if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { + if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); @@ -136,9 +134,9 @@ int main(void) background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); - }} + } } - nk_end(ctx);} + nk_end(ctx); /* -------------- EXAMPLES ---------------- */ /*calculator(ctx);*/ diff --git a/demo/glfw_opengl2/nuklear_glfw_gl2.h b/demo/glfw_opengl2/nuklear_glfw_gl2.h index 798a3a2..93af773 100644 --- a/demo/glfw_opengl2/nuklear_glfw_gl2.h +++ b/demo/glfw_opengl2/nuklear_glfw_gl2.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c index 2ebe15d..d74ee56 100644 --- a/demo/glfw_opengl3/main.c +++ b/demo/glfw_opengl3/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #include #include #include @@ -118,8 +118,7 @@ int main(void) nk_glfw3_new_frame(); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 230, 250), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -137,11 +136,10 @@ int main(void) nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); - {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); - if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { + if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); @@ -150,9 +148,9 @@ int main(void) background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); - }} + } } - nk_end(ctx);} + nk_end(ctx); /* -------------- EXAMPLES ---------------- */ /*calculator(ctx);*/ diff --git a/demo/glfw_opengl3/nuklear_glfw_gl3.h b/demo/glfw_opengl3/nuklear_glfw_gl3.h index 6b8d982..aabb365 100644 --- a/demo/glfw_opengl3/nuklear_glfw_gl3.h +++ b/demo/glfw_opengl3/nuklear_glfw_gl3.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/node_editor.c b/demo/node_editor.c index 8a3e72b..e2aaf31 100644 --- a/demo/node_editor.c +++ b/demo/node_editor.c @@ -152,7 +152,6 @@ node_editor(struct nk_context *ctx) const struct nk_input *in = &ctx->input; struct nk_command_buffer *canvas; struct node *updated = 0; - struct nk_panel layout; struct node_editor *nodedit = &nodeEditor; if (!nodeEditor.initialized) { @@ -160,7 +159,7 @@ node_editor(struct nk_context *ctx) nodeEditor.initialized = 1; } - if (nk_begin(ctx, &layout, "NodeEdit", nk_rect(0, 0, 800, 600), + if (nk_begin(ctx, "NodeEdit", nk_rect(0, 0, 800, 600), NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { /* allocate complete window space */ @@ -168,7 +167,6 @@ node_editor(struct nk_context *ctx) total_space = nk_window_get_content_region(ctx); nk_layout_space_begin(ctx, NK_STATIC, total_space.h, nodedit->node_count); { - struct nk_panel node, menu; struct node *it = nodedit->begin; struct nk_rect size = nk_layout_space_bounds(ctx); @@ -190,12 +188,13 @@ node_editor(struct nk_context *ctx) it->bounds.y - nodedit->scrolling.y, it->bounds.w, it->bounds.h)); /* execute node window */ - if (nk_group_begin(ctx, &node, it->name, NK_WINDOW_MOVABLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_TITLE)) + if (nk_group_begin(ctx, it->name, NK_WINDOW_MOVABLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_TITLE)) { /* always have last selected node on top */ - if (nk_input_mouse_clicked(in, NK_BUTTON_LEFT, node.bounds) && + struct nk_panel *node = nk_window_get_panel(ctx); + if (nk_input_mouse_clicked(in, NK_BUTTON_LEFT, node->bounds) && (!(it->prev && nk_input_mouse_clicked(in, NK_BUTTON_LEFT, - nk_layout_space_rect_to_screen(ctx, node.bounds)))) && + nk_layout_space_rect_to_screen(ctx, node->bounds)))) && nodedit->end != it) { updated = it; @@ -215,17 +214,18 @@ node_editor(struct nk_context *ctx) /* node connector and linking */ float space; struct nk_rect bounds; - bounds = nk_layout_space_rect_to_local(ctx, node.bounds); + struct nk_panel *node = nk_window_get_panel(ctx); + bounds = nk_layout_space_rect_to_local(ctx, node->bounds); bounds.x += nodedit->scrolling.x; bounds.y += nodedit->scrolling.y; it->bounds = bounds; /* output connector */ - space = node.bounds.h / (float)((it->output_count) + 1); + space = node->bounds.h / (float)((it->output_count) + 1); for (n = 0; n < it->output_count; ++n) { struct nk_rect circle; - circle.x = node.bounds.x + node.bounds.w-4; - circle.y = node.bounds.y + space * (float)(n+1); + circle.x = node->bounds.x + node->bounds.w-4; + circle.y = node->bounds.y + space * (float)(n+1); circle.w = 8; circle.h = 8; nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100)); @@ -248,11 +248,11 @@ node_editor(struct nk_context *ctx) } /* input connector */ - space = node.bounds.h / (float)((it->input_count) + 1); + space = node->bounds.h / (float)((it->input_count) + 1); for (n = 0; n < it->input_count; ++n) { struct nk_rect circle; - circle.x = node.bounds.x-4; - circle.y = node.bounds.y + space * (float)(n+1); + circle.x = node->bounds.x-4; + circle.y = node->bounds.y + space * (float)(n+1); circle.w = 8; circle.h = 8; nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100)); if (nk_input_is_mouse_released(in, NK_BUTTON_LEFT) && @@ -276,11 +276,12 @@ node_editor(struct nk_context *ctx) /* draw each link */ for (n = 0; n < nodedit->link_count; ++n) { + struct nk_panel *node = nk_window_get_panel(ctx); struct node_link *link = &nodedit->links[n]; struct node *ni = node_editor_find(nodedit, link->input_id); struct node *no = node_editor_find(nodedit, link->output_id); - float spacei = node.bounds.h / (float)((ni->output_count) + 1); - float spaceo = node.bounds.h / (float)((no->input_count) + 1); + float spacei = node->bounds.h / (float)((ni->output_count) + 1); + float spaceo = node->bounds.h / (float)((no->input_count) + 1); struct nk_vec2 l0 = nk_layout_space_to_screen(ctx, nk_vec2(ni->bounds.x + ni->bounds.w, 3.0f + ni->bounds.y + spacei * (float)(link->input_slot+1))); struct nk_vec2 l1 = nk_layout_space_to_screen(ctx, @@ -316,7 +317,7 @@ node_editor(struct nk_context *ctx) } /* contextual menu */ - if (nk_contextual_begin(ctx, &menu, 0, nk_vec2(100, 220), nk_window_get_bounds(ctx))) { + if (nk_contextual_begin(ctx, 0, nk_vec2(100, 220), nk_window_get_bounds(ctx))) { const char *grid_option[] = {"Show Grid", "Hide Grid"}; nk_layout_row_dynamic(ctx, 25, 1); if (nk_contextual_item_label(ctx, "New", NK_TEXT_CENTERED)) diff --git a/demo/overview.c b/demo/overview.c index 3b26117..7772378 100644 --- a/demo/overview.c +++ b/demo/overview.c @@ -2,8 +2,6 @@ static int overview(struct nk_context *ctx) { - struct nk_panel menu; - /* window flags */ static int show_menu = nk_true; static int titlebar = nk_true; @@ -17,7 +15,6 @@ overview(struct nk_context *ctx) /* popups */ static enum nk_style_header_align header_align = NK_HEADER_RIGHT; static int show_app_about = nk_false; - struct nk_panel layout; /* window flags */ window_flags = 0; @@ -28,7 +25,7 @@ overview(struct nk_context *ctx) if (no_scrollbar) window_flags |= NK_WINDOW_NO_SCROLLBAR; if (minimizable) window_flags |= NK_WINDOW_MINIMIZABLE; - if (nk_begin(ctx, &layout, "Overview", nk_rect(10, 10, 400, 600), window_flags)) + if (nk_begin(ctx, "Overview", nk_rect(10, 10, 400, 600), window_flags)) { if (show_menu) { @@ -41,7 +38,7 @@ overview(struct nk_context *ctx) nk_menubar_begin(ctx); nk_layout_row_begin(ctx, NK_STATIC, 25, 2); nk_layout_row_push(ctx, 45); - if (nk_menu_begin_label(ctx, &menu, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200))) + if (nk_menu_begin_label(ctx, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200))) { static size_t prog = 40; static int slider = 10; @@ -66,9 +63,8 @@ overview(struct nk_context *ctx) if (show_app_about) { /* about popup */ - struct nk_panel popup; static struct nk_rect s = {20, 100, 300, 190}; - if (nk_popup_begin(ctx, &popup, NK_POPUP_STATIC, "About", NK_WINDOW_CLOSABLE, s)) + if (nk_popup_begin(ctx, NK_POPUP_STATIC, "About", NK_WINDOW_CLOSABLE, s)) { nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "Nuklear", NK_TEXT_LEFT); @@ -272,14 +268,13 @@ overview(struct nk_context *ctx) char buffer[64]; size_t sum = 0; - struct nk_panel combo; /* default combobox */ nk_layout_row_static(ctx, 25, 200, 1); current_weapon = nk_combo(ctx, weapons, LEN(weapons), current_weapon, 25, nk_vec2(200,200)); /* slider color combobox */ - if (nk_combo_begin_color(ctx, &combo, combo_color, nk_vec2(200,200))) { + if (nk_combo_begin_color(ctx, combo_color, nk_vec2(200,200))) { float ratios[] = {0.15f, 0.85f}; nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratios); nk_label(ctx, "R:", NK_TEXT_LEFT); @@ -294,7 +289,7 @@ overview(struct nk_context *ctx) } /* complex color combobox */ - if (nk_combo_begin_color(ctx, &combo, combo_color2, nk_vec2(200,400))) { + if (nk_combo_begin_color(ctx, combo_color2, nk_vec2(200,400))) { enum color_mode {COL_RGB, COL_HSV}; static int col_mode = COL_RGB; #ifndef DEMO_DO_NOT_USE_COLOR_PICKER @@ -327,7 +322,7 @@ overview(struct nk_context *ctx) /* progressbar combobox */ sum = prog_a + prog_b + prog_c + prog_d; sprintf(buffer, "%lu", sum); - if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) { + if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) { nk_layout_row_dynamic(ctx, 30, 1); nk_progress(ctx, &prog_a, 100, NK_MODIFIABLE); nk_progress(ctx, &prog_b, 100, NK_MODIFIABLE); @@ -339,7 +334,7 @@ overview(struct nk_context *ctx) /* checkbox combobox */ sum = (size_t)(check_values[0] + check_values[1] + check_values[2] + check_values[3] + check_values[4]); sprintf(buffer, "%lu", sum); - if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) { + if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) { nk_layout_row_dynamic(ctx, 30, 1); nk_checkbox_label(ctx, weapons[0], &check_values[0]); nk_checkbox_label(ctx, weapons[1], &check_values[1]); @@ -350,7 +345,7 @@ overview(struct nk_context *ctx) /* complex text combobox */ sprintf(buffer, "%.2f, %.2f, %.2f", position[0], position[1],position[2]); - if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) { + if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) { nk_layout_row_dynamic(ctx, 25, 1); nk_property_float(ctx, "#X:", -1024.0f, &position[0], 1024.0f, 1,0.5f); nk_property_float(ctx, "#Y:", -1024.0f, &position[1], 1024.0f, 1,0.5f); @@ -360,7 +355,7 @@ overview(struct nk_context *ctx) /* chart combobox */ sprintf(buffer, "%.1f", chart_selection); - if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,250))) { + if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,250))) { size_t i = 0; static const float values[]={26.0f,13.0f,30.0f,15.0f,25.0f,10.0f,20.0f,40.0f, 12.0f, 8.0f, 22.0f, 28.0f, 5.0f}; nk_layout_row_dynamic(ctx, 150, 1); @@ -393,7 +388,7 @@ overview(struct nk_context *ctx) /* time combobox */ sprintf(buffer, "%02d:%02d:%02d", sel_time.tm_hour, sel_time.tm_min, sel_time.tm_sec); - if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,250))) { + if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,250))) { time_selected = 1; nk_layout_row_dynamic(ctx, 25, 1); sel_time.tm_sec = nk_propertyi(ctx, "#S:", 0, sel_time.tm_sec, 60, 1, 1); @@ -404,7 +399,7 @@ overview(struct nk_context *ctx) /* date combobox */ sprintf(buffer, "%02d-%02d-%02d", sel_date.tm_mday, sel_date.tm_mon+1, sel_date.tm_year+1900); - if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(350,400))) + if (nk_combo_begin_label(ctx, buffer, nk_vec2(350,400))) { int i = 0; const char *month[] = {"January", "February", "March", "Apil", "May", "June", "July", "August", "September", "Ocotober", "November", "December"}; @@ -647,7 +642,7 @@ overview(struct nk_context *ctx) bounds = nk_widget_bounds(ctx); nk_label(ctx, "Right click me for menu", NK_TEXT_LEFT); - if (nk_contextual_begin(ctx, &menu, 0, nk_vec2(100, 300), bounds)) { + if (nk_contextual_begin(ctx, 0, nk_vec2(100, 300), bounds)) { static size_t prog = 40; static int slider = 10; @@ -673,7 +668,7 @@ overview(struct nk_context *ctx) nk_button_color(ctx, color); nk_layout_row_end(ctx); - if (nk_contextual_begin(ctx, &menu, 0, nk_vec2(350, 60), bounds)) { + if (nk_contextual_begin(ctx, 0, nk_vec2(350, 60), bounds)) { nk_layout_row_dynamic(ctx, 30, 4); color.r = (nk_byte)nk_propertyi(ctx, "#r", 0, color.r, 255, 1, 1); color.g = (nk_byte)nk_propertyi(ctx, "#g", 0, color.g, 255, 1, 1); @@ -694,7 +689,7 @@ overview(struct nk_context *ctx) if (popup_active) { static struct nk_rect s = {20, 100, 220, 90}; - if (nk_popup_begin(ctx, &menu, NK_POPUP_STATIC, "Error", 0, s)) + if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Error", 0, s)) { nk_layout_row_dynamic(ctx, 25, 1); nk_label(ctx, "A terrible error as occured", NK_TEXT_LEFT); @@ -800,7 +795,6 @@ overview(struct nk_context *ctx) static int group_no_scrollbar = nk_false; static int group_width = 320; static int group_height = 200; - struct nk_panel tab; nk_flags group_flags = 0; if (group_border) group_flags |= NK_WINDOW_BORDER; @@ -822,7 +816,7 @@ overview(struct nk_context *ctx) nk_layout_row_end(ctx); nk_layout_row_static(ctx, (float)group_height, group_width, 2); - if (nk_group_begin(ctx, &tab, "Group", group_flags)) { + if (nk_group_begin(ctx, "Group", group_flags)) { int i = 0; static int selected[16]; nk_layout_row_static(ctx, 18, 100, 1); @@ -836,13 +830,11 @@ overview(struct nk_context *ctx) if (nk_tree_push(ctx, NK_TREE_NODE, "Notebook", NK_MINIMIZED)) { static int current_tab = 0; - struct nk_panel group; struct nk_vec2 item_padding; struct nk_rect bounds; float step = (2*3.141592654f) / 32; enum chart_type {CHART_LINE, CHART_HISTO, CHART_MIXED}; const char *names[] = {"Lines", "Columns", "Mixed"}; - float rounding; float id = 0; int i; @@ -868,7 +860,7 @@ overview(struct nk_context *ctx) /* Body */ nk_layout_row_dynamic(ctx, 140, 1); - if (nk_group_begin(ctx, &group, "Notebook", NK_WINDOW_BORDER)) + if (nk_group_begin(ctx, "Notebook", NK_WINDOW_BORDER)) { nk_style_pop_vec2(ctx); switch (current_tab) { @@ -919,9 +911,8 @@ overview(struct nk_context *ctx) if (nk_tree_push(ctx, NK_TREE_NODE, "Simple", NK_MINIMIZED)) { - struct nk_panel tab; nk_layout_row_dynamic(ctx, 300, 2); - if (nk_group_begin(ctx, &tab, "Group_Without_Border", 0)) { + if (nk_group_begin(ctx, "Group_Without_Border", 0)) { int i = 0; char buffer[64]; nk_layout_row_static(ctx, 18, 150, 1); @@ -931,7 +922,7 @@ overview(struct nk_context *ctx) } nk_group_end(ctx); } - if (nk_group_begin(ctx, &tab, "Group_With_Border", NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "Group_With_Border", NK_WINDOW_BORDER)) { int i = 0; char buffer[64]; nk_layout_row_dynamic(ctx, 25, 2); @@ -947,10 +938,9 @@ overview(struct nk_context *ctx) if (nk_tree_push(ctx, NK_TREE_NODE, "Complex", NK_MINIMIZED)) { int i; - struct nk_panel tab; nk_layout_space_begin(ctx, NK_STATIC, 500, 64); nk_layout_space_push(ctx, nk_rect(0,0,150,500)); - if (nk_group_begin(ctx, &tab, "Group_left", NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "Group_left", NK_WINDOW_BORDER)) { static int selected[32]; nk_layout_row_static(ctx, 18, 100, 1); for (i = 0; i < 32; ++i) @@ -959,7 +949,7 @@ overview(struct nk_context *ctx) } nk_layout_space_push(ctx, nk_rect(160,0,150,240)); - if (nk_group_begin(ctx, &tab, "Group_top", NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "Group_top", NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 25, 1); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); @@ -971,7 +961,7 @@ overview(struct nk_context *ctx) } nk_layout_space_push(ctx, nk_rect(160,250,150,250)); - if (nk_group_begin(ctx, &tab, "Group_buttom", NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "Group_buttom", NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 25, 1); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); @@ -983,7 +973,7 @@ overview(struct nk_context *ctx) } nk_layout_space_push(ctx, nk_rect(320,0,150,150)); - if (nk_group_begin(ctx, &tab, "Group_right_top", NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "Group_right_top", NK_WINDOW_BORDER)) { static int selected[4]; nk_layout_row_static(ctx, 18, 100, 1); for (i = 0; i < 4; ++i) @@ -992,7 +982,7 @@ overview(struct nk_context *ctx) } nk_layout_space_push(ctx, nk_rect(320,160,150,150)); - if (nk_group_begin(ctx, &tab, "Group_right_center", NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "Group_right_center", NK_WINDOW_BORDER)) { static int selected[4]; nk_layout_row_static(ctx, 18, 100, 1); for (i = 0; i < 4; ++i) @@ -1001,7 +991,7 @@ overview(struct nk_context *ctx) } nk_layout_space_push(ctx, nk_rect(320,320,150,150)); - if (nk_group_begin(ctx, &tab, "Group_right_bottom", NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "Group_right_bottom", NK_WINDOW_BORDER)) { static int selected[4]; nk_layout_row_static(ctx, 18, 100, 1); for (i = 0; i < 4; ++i) @@ -1023,7 +1013,6 @@ overview(struct nk_context *ctx) { static float a = 100, b = 100, c = 100; struct nk_rect bounds; - struct nk_panel sub; float row_layout[5]; row_layout[0] = a; @@ -1047,7 +1036,7 @@ overview(struct nk_context *ctx) nk_layout_row(ctx, NK_STATIC, 200, 5, row_layout); /* left space */ - if (nk_group_begin(ctx, &sub, "left", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { + if (nk_group_begin(ctx, "left", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 25, 1); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); @@ -1070,7 +1059,7 @@ overview(struct nk_context *ctx) } /* middle space */ - if (nk_group_begin(ctx, &sub, "center", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { + if (nk_group_begin(ctx, "center", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 25, 1); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); @@ -1093,7 +1082,7 @@ overview(struct nk_context *ctx) } /* right space */ - if (nk_group_begin(ctx, &sub, "right", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { + if (nk_group_begin(ctx, "right", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 25, 1); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); @@ -1110,7 +1099,6 @@ overview(struct nk_context *ctx) if (nk_tree_push(ctx, NK_TREE_NODE, "Horizontal", NK_MINIMIZED)) { static float a = 100, b = 100, c = 100; - struct nk_panel sub; struct nk_rect bounds; /* header */ @@ -1126,7 +1114,7 @@ overview(struct nk_context *ctx) /* top space */ nk_layout_row_dynamic(ctx, a, 1); - if (nk_group_begin(ctx, &sub, "top", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "top", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 25, 3); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); @@ -1151,7 +1139,7 @@ overview(struct nk_context *ctx) /* middle space */ nk_layout_row_dynamic(ctx, b, 1); - if (nk_group_begin(ctx, &sub, "middle", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "middle", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 25, 3); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); @@ -1177,7 +1165,7 @@ overview(struct nk_context *ctx) /* bottom space */ nk_layout_row_dynamic(ctx, c, 1); - if (nk_group_begin(ctx, &sub, "bottom", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { + if (nk_group_begin(ctx, "bottom", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 25, 3); nk_button_label(ctx, "#FFAA"); nk_button_label(ctx, "#FFBB"); diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c index dfdfe87..0d96551 100644 --- a/demo/sdl_opengl2/main.c +++ b/demo/sdl_opengl2/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #include #include #include @@ -116,8 +116,7 @@ main(int argc, char* argv[]) nk_input_end(ctx); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 210, 250), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 210, 250), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -134,11 +133,10 @@ main(int argc, char* argv[]) nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); - {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); - if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { + if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); @@ -147,9 +145,9 @@ main(int argc, char* argv[]) background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); - }} + } } - nk_end(ctx);} + nk_end(ctx); /* -------------- EXAMPLES ---------------- */ /*calculator(ctx);*/ diff --git a/demo/sdl_opengl2/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h index 0068c12..94bfca8 100644 --- a/demo/sdl_opengl2/nuklear_sdl_gl2.h +++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c index b686c9a..aee4f82 100644 --- a/demo/sdl_opengl3/main.c +++ b/demo/sdl_opengl3/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #include #include #include @@ -26,8 +26,8 @@ #include "../../nuklear.h" #include "nuklear_sdl_gl3.h" -#define WINDOW_WIDTH 1200 -#define WINDOW_HEIGHT 800 +#define WINDOW_WIDTH 800 +#define WINDOW_HEIGHT 600 #define MAX_VERTEX_MEMORY 512 * 1024 #define MAX_ELEMENT_MEMORY 128 * 1024 @@ -123,16 +123,35 @@ main(int argc, char* argv[]) } nk_input_end(ctx); + /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(200, 200, 210, 250), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| - NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) + NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { + nk_menubar_begin(ctx); + nk_layout_row_begin(ctx, NK_STATIC, 25, 2); + nk_layout_row_push(ctx, 45); + if (nk_menu_begin_label(ctx, "FILE", NK_TEXT_LEFT, nk_vec2(120, 200))) { + nk_layout_row_dynamic(ctx, 30, 1); + nk_menu_item_label(ctx, "OPEN", NK_TEXT_LEFT); + nk_menu_item_label(ctx, "CLOSE", NK_TEXT_LEFT); + nk_menu_end(ctx); + } + nk_layout_row_push(ctx, 45); + if (nk_menu_begin_label(ctx, "EDIT", NK_TEXT_LEFT, nk_vec2(120, 200))) { + nk_layout_row_dynamic(ctx, 30, 1); + nk_menu_item_label(ctx, "COPY", NK_TEXT_LEFT); + nk_menu_item_label(ctx, "CUT", NK_TEXT_LEFT); + nk_menu_item_label(ctx, "PASTE", NK_TEXT_LEFT); + nk_menu_end(ctx); + } + nk_layout_row_end(ctx); + nk_menubar_end(ctx); + enum {EASY, HARD}; static int op = EASY; static int property = 20; - nk_layout_row_static(ctx, 30, 80, 1); if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); @@ -141,23 +160,8 @@ main(int argc, char* argv[]) if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); - - {struct nk_panel combo; - nk_layout_row_dynamic(ctx, 20, 1); - nk_label(ctx, "background:", NK_TEXT_LEFT); - nk_layout_row_dynamic(ctx, 25, 1); - if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { - nk_layout_row_dynamic(ctx, 120, 1); - background = nk_color_picker(ctx, background, NK_RGBA); - nk_layout_row_dynamic(ctx, 25, 1); - background.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, background.r, 255, 1,1); - background.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, background.g, 255, 1,1); - background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); - background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); - nk_combo_end(ctx); - }} } - nk_end(ctx);} + nk_end(ctx); /* -------------- EXAMPLES ---------------- */ /*calculator(ctx);*/ diff --git a/demo/sdl_opengl3/nuklear_sdl_gl3.h b/demo/sdl_opengl3/nuklear_sdl_gl3.h index 4dc7ec9..a55c45c 100644 --- a/demo/sdl_opengl3/nuklear_sdl_gl3.h +++ b/demo/sdl_opengl3/nuklear_sdl_gl3.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ @@ -230,7 +230,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b glBufferData(GL_ARRAY_BUFFER, max_vertex_buffer, NULL, GL_STREAM_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, max_element_buffer, NULL, GL_STREAM_DRAW); - /* load draw vertices & elements directly into vertex + element buffer */ + /* load vertices/elements directly into vertex/element buffer */ vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); { @@ -256,8 +256,8 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b /* setup buffers to load vertices and elements */ {struct nk_buffer vbuf, ebuf; - nk_buffer_init_fixed(&vbuf, vertices, (size_t)max_vertex_buffer); - nk_buffer_init_fixed(&ebuf, elements, (size_t)max_element_buffer); + nk_buffer_init_fixed(&vbuf, vertices, (nk_size)max_vertex_buffer); + nk_buffer_init_fixed(&ebuf, elements, (nk_size)max_element_buffer); nk_convert(&sdl.ctx, &dev->cmds, &vbuf, &ebuf, &config);} } glUnmapBuffer(GL_ARRAY_BUFFER); @@ -267,12 +267,10 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b nk_draw_foreach(cmd, &sdl.ctx, &dev->cmds) { if (!cmd->elem_count) continue; glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id); - glScissor( - (GLint)(cmd->clip_rect.x * scale.x), + glScissor((GLint)(cmd->clip_rect.x * scale.x), (GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y), (GLint)(cmd->clip_rect.w * scale.x), (GLint)(cmd->clip_rect.h * scale.y)); - glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset); offset += cmd->elem_count; } diff --git a/demo/x11/main.c b/demo/x11/main.c index 724b05f..8f4b12c 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #include #include #include @@ -91,8 +91,8 @@ sleep_for(long t) * and the corresponding function. */ /*#include "../style.c"*/ /*#include "../calculator.c"*/ -/*#include "../overview.c"*/ -/*#include "../node_editor.c"*/ +#include "../overview.c" +#include "../node_editor.c" /* =============================================================== * @@ -155,8 +155,7 @@ main(void) nk_input_end(ctx); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -173,13 +172,13 @@ main(void) nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } - nk_end(ctx);} + nk_end(ctx); if (nk_window_is_closed(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ /*calculator(ctx);*/ - /*overview(ctx);*/ - /*node_editor(ctx);*/ + overview(ctx); + node_editor(ctx); /* ----------------------------------------- */ /* Draw */ diff --git a/demo/x11/nuklear_xlib.h b/demo/x11/nuklear_xlib.h index ad8e646..df66d78 100644 --- a/demo/x11/nuklear_xlib.h +++ b/demo/x11/nuklear_xlib.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index 2a19d0c..cfe5604 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #include #include #include @@ -252,8 +252,7 @@ int main(int argc, char **argv) nk_input_end(ctx); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -270,11 +269,10 @@ int main(int argc, char **argv) nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); - {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); - if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { + if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); @@ -283,9 +281,9 @@ int main(int argc, char **argv) background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); - }} + } } - nk_end(ctx);} + nk_end(ctx); if (nk_window_is_closed(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ diff --git a/demo/x11_opengl2/nuklear_xlib_gl2.h b/demo/x11_opengl2/nuklear_xlib_gl2.h index cfa12b7..38787df 100644 --- a/demo/x11_opengl2/nuklear_xlib_gl2.h +++ b/demo/x11_opengl2/nuklear_xlib_gl2.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index 7297b3a..cd026f9 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -1,4 +1,4 @@ -/* nuklear - v1.09 - public domain */ +/* nuklear - v1.17 - public domain */ #include #include #include @@ -249,8 +249,7 @@ int main(int argc, char **argv) nk_input_end(ctx); /* GUI */ - {struct nk_panel layout; - if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200), + if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { @@ -267,11 +266,10 @@ int main(int argc, char **argv) nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); - {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); - if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { + if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); @@ -280,9 +278,9 @@ int main(int argc, char **argv) background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); - }} + } } - nk_end(ctx);} + nk_end(ctx); if (nk_window_is_closed(ctx, "Demo")) break; /* -------------- EXAMPLES ---------------- */ diff --git a/demo/x11_opengl3/nuklear_xlib_gl3.h b/demo/x11_opengl3/nuklear_xlib_gl3.h index b5bbeef..f176c5f 100644 --- a/demo/x11_opengl3/nuklear_xlib_gl3.h +++ b/demo/x11_opengl3/nuklear_xlib_gl3.h @@ -1,5 +1,5 @@ /* - * Nuklear - v1.00 - public domain + * Nuklear - v1.17 - public domain * no warrenty implied; use at your own risk. * authored from 2015-2016 by Micha Mettke */ diff --git a/example/canvas.c b/example/canvas.c index 9957b12..c5f5634 100644 --- a/example/canvas.c +++ b/example/canvas.c @@ -348,7 +348,6 @@ pump_input(struct nk_context *ctx, GLFWwindow *win) } struct nk_canvas { - struct nk_panel layout; struct nk_command_buffer *painter; struct nk_vec2 item_spacing; struct nk_vec2 panel_padding; @@ -371,7 +370,7 @@ canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags, /* create/update window and set position + size */ flags = flags & ~NK_WINDOW_DYNAMIC; - nk_begin(ctx, &canvas->layout, "Window", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags); + nk_begin(ctx, "Window", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags); nk_window_set_bounds(ctx, nk_rect(x, y, width, height)); /* allocate the complete window space for drawing */ diff --git a/example/extended.c b/example/extended.c index 41263e6..e555d65 100644 --- a/example/extended.c +++ b/example/extended.c @@ -80,7 +80,6 @@ ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius, { int ret = -1; struct nk_rect total_space; - struct nk_panel popup; struct nk_rect bounds; int active_item = 0; @@ -94,7 +93,7 @@ ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius, ctx->style.window.spacing = nk_vec2(0,0); ctx->style.window.padding = nk_vec2(0,0); - if (nk_popup_begin(ctx, &popup, NK_POPUP_STATIC, "piemenu", NK_WINDOW_NO_SCROLLBAR, + if (nk_popup_begin(ctx, NK_POPUP_STATIC, "piemenu", NK_WINDOW_NO_SCROLLBAR, nk_rect(pos.x - total_space.x - radius, pos.y - radius - total_space.y, 2*radius,2*radius))) { @@ -187,12 +186,10 @@ grid_demo(struct nk_context *ctx, struct media *media) static const char *items[] = {"Item 0","item 1","item 2"}; static int selected_item = 0; static int check = 1; - struct nk_panel layout; int i; - struct nk_panel combo; nk_style_set_font(ctx, &media->font_20->handle); - if (nk_begin(ctx, &layout, "Grid Demo", nk_rect(600, 350, 275, 250), + if (nk_begin(ctx, "Grid Demo", nk_rect(600, 350, 275, 250), NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_MOVABLE| NK_WINDOW_NO_SCROLLBAR)) { @@ -207,7 +204,7 @@ grid_demo(struct nk_context *ctx, struct media *media) nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT); nk_checkbox_label(ctx, "Check me", &check); nk_label(ctx, "Combobox:", NK_TEXT_RIGHT); - if (nk_combo_begin_label(ctx, &combo, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { + if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 25, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) @@ -253,15 +250,13 @@ ui_widget_centered(struct nk_context *ctx, struct media *media, float height) static void button_demo(struct nk_context *ctx, struct media *media) { - struct nk_panel layout; - struct nk_panel menu; static int option = 1; static int toggle0 = 1; static int toggle1 = 0; static int toggle2 = 1; nk_style_set_font(ctx, &media->font_20->handle); - nk_begin(ctx, &layout, "Button Demo", nk_rect(50,50,255,610), + nk_begin(ctx, "Button Demo", nk_rect(50,50,255,610), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE); /*------------------------------------------------ @@ -271,7 +266,7 @@ button_demo(struct nk_context *ctx, struct media *media) { /* toolbar */ nk_layout_row_static(ctx, 40, 40, 4); - if (nk_menu_begin_image(ctx, &menu, "Music", media->play, nk_vec2(110,120))) + if (nk_menu_begin_image(ctx, "Music", media->play, nk_vec2(110,120))) { /* settings */ nk_layout_row_dynamic(ctx, 25, 1); @@ -341,7 +336,7 @@ button_demo(struct nk_context *ctx, struct media *media) * CONTEXTUAL *------------------------------------------------*/ nk_style_set_font(ctx, &media->font_18->handle); - if (nk_contextual_begin(ctx, &menu, NK_WINDOW_NO_SCROLLBAR, nk_vec2(150, 300), nk_window_get_bounds(ctx))) { + if (nk_contextual_begin(ctx, NK_WINDOW_NO_SCROLLBAR, nk_vec2(150, 300), nk_window_get_bounds(ctx))) { nk_layout_row_dynamic(ctx, 30, 1); if (nk_contextual_item_image_label(ctx, media->copy, "Clone", NK_TEXT_RIGHT)) fprintf(stdout, "pressed clone!\n"); @@ -377,10 +372,8 @@ basic_demo(struct nk_context *ctx, struct media *media) static struct nk_vec2 piemenu_pos; int i = 0; - struct nk_panel layout; - struct nk_panel combo; nk_style_set_font(ctx, &media->font_20->handle); - nk_begin(ctx, &layout, "Basic Demo", nk_rect(320, 50, 275, 610), + nk_begin(ctx, "Basic Demo", nk_rect(320, 50, 275, 610), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE); /*------------------------------------------------ @@ -403,7 +396,7 @@ basic_demo(struct nk_context *ctx, struct media *media) *------------------------------------------------*/ if (image_active) { struct nk_panel popup; - if (nk_popup_begin(ctx, &popup, NK_POPUP_STATIC, "Image Popup", 0, nk_rect(265, 0, 320, 220))) { + if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Image Popup", 0, nk_rect(265, 0, 320, 220))) { nk_layout_row_static(ctx, 82, 82, 3); for (i = 0; i < 9; ++i) { if (nk_button_image(ctx, media->images[i])) { @@ -420,7 +413,7 @@ basic_demo(struct nk_context *ctx, struct media *media) *------------------------------------------------*/ ui_header(ctx, media, "Combo box"); ui_widget(ctx, media, 40); - if (nk_combo_begin_label(ctx, &combo, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { + if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 35, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) @@ -429,7 +422,7 @@ basic_demo(struct nk_context *ctx, struct media *media) } ui_widget(ctx, media, 40); - if (nk_combo_begin_image_label(ctx, &combo, items[selected_icon], media->images[selected_icon], nk_vec2(nk_widget_width(ctx), 200))) { + if (nk_combo_begin_image_label(ctx, items[selected_icon], media->images[selected_icon], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 35, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_image_label(ctx, media->images[i], items[i], NK_TEXT_RIGHT)) @@ -457,7 +450,7 @@ basic_demo(struct nk_context *ctx, struct media *media) * PIEMENU *------------------------------------------------*/ if (nk_input_is_mouse_click_down_in_rect(&ctx->input, NK_BUTTON_RIGHT, - layout.bounds,nk_true)){ + nk_window_get_bounds(ctx),nk_true)){ piemenu_pos = ctx->input.mouse.pos; piemenu_active = 1; } diff --git a/example/file_browser.c b/example/file_browser.c index 67ef7f7..6ca0e85 100644 --- a/example/file_browser.c +++ b/example/file_browser.c @@ -397,11 +397,10 @@ static int file_browser_run(struct file_browser *browser, struct nk_context *ctx) { int ret = 0; - struct nk_panel layout; struct media *media = browser->media; struct nk_rect total_space; - if (nk_begin(ctx, &layout, "File Browser", nk_rect(50, 50, 800, 600), + if (nk_begin(ctx, "File Browser", nk_rect(50, 50, 800, 600), NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE)) { struct nk_panel sub; @@ -434,7 +433,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx) /* window layout */ total_space = nk_window_get_content_region(ctx); nk_layout_row(ctx, NK_DYNAMIC, total_space.h, 2, ratio); - nk_group_begin(ctx, &sub, "Special", NK_WINDOW_NO_SCROLLBAR); + nk_group_begin(ctx, "Special", NK_WINDOW_NO_SCROLLBAR); { struct nk_image home = media->icons.home; struct nk_image desktop = media->icons.desktop; @@ -451,7 +450,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx) } /* output directory content window */ - nk_group_begin(ctx, &sub, "Content", 0); + nk_group_begin(ctx, "Content", 0); { int index = -1; size_t i = 0, j = 0, k = 0; diff --git a/example/skinning.c b/example/skinning.c index a1547c5..4634b09 100644 --- a/example/skinning.c +++ b/example/skinning.c @@ -735,7 +735,7 @@ int main(int argc, char *argv[]) /* GUI */ {struct nk_panel layout, tab; - if (nk_begin(&ctx, &layout, "Demo", nk_rect(50, 50, 300, 400), + if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 300, 400), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE)) { int i; @@ -785,7 +785,7 @@ int main(int argc, char *argv[]) nk_chart_end(&ctx); nk_layout_row_dynamic(&ctx, 250, 1); - if (nk_group_begin(&ctx, &tab, "Standard", NK_WINDOW_BORDER|NK_WINDOW_BORDER)) + if (nk_group_begin(&ctx, "Standard", NK_WINDOW_BORDER|NK_WINDOW_BORDER)) { if (nk_tree_push(&ctx, NK_TREE_NODE, "Window", NK_MAXIMIZED)) { static int selected[8]; diff --git a/nuklear.h b/nuklear.h index 1208ce9..42e444f 100644 --- a/nuklear.h +++ b/nuklear.h @@ -1,5 +1,5 @@ /* - Nuklear - v1.156 - public domain + Nuklear - v1.17 - public domain no warrenty implied; use at your own risk. authored from 2015-2016 by Micha Mettke @@ -313,7 +313,7 @@ extern "C" { * * =============================================================== */ -#ifdef NK_INCLUDE_FIXED_TYPES +#ifdef FIFO_INCLUDE_FIXED_TYPES #include #define NK_INT8 int8_t #define NK_UINT8 uint8_t @@ -677,8 +677,8 @@ NK_API void nk_set_user_data(struct nk_context*, nk_handle h #endif /* window */ -NK_API int nk_begin(struct nk_context*, struct nk_panel*, const char *title, struct nk_rect bounds, nk_flags flags); -NK_API int nk_begin_titled(struct nk_context*, struct nk_panel*, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); +NK_API int nk_begin(struct nk_context*, const char *title, struct nk_rect bounds, nk_flags flags); +NK_API int nk_begin_titled(struct nk_context*, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); NK_API void nk_end(struct nk_context*); NK_API struct nk_window* nk_window_find(struct nk_context *ctx, const char *name); @@ -735,7 +735,7 @@ NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context* NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); /* Layout: Group */ -NK_API int nk_group_begin(struct nk_context*, struct nk_panel*, const char *title, nk_flags); +NK_API int nk_group_begin(struct nk_context*, const char *title, nk_flags); NK_API void nk_group_end(struct nk_context*); /* Layout: Tree */ @@ -855,7 +855,7 @@ NK_API void nk_plot(struct nk_context*, enum nk_chart_type, NK_API void nk_plot_function(struct nk_context*, enum nk_chart_type, void *userdata, float(*value_getter)(void* user, int index), int count, int offset); /* Popups */ -NK_API int nk_popup_begin(struct nk_context*, struct nk_panel*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds); +NK_API int nk_popup_begin(struct nk_context*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds); NK_API void nk_popup_close(struct nk_context*); NK_API void nk_popup_end(struct nk_context*); @@ -870,15 +870,15 @@ NK_API void nk_combobox_separator(struct nk_context*, const NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size); /* Combobox: abstract */ -NK_API int nk_combo_begin_text(struct nk_context*, struct nk_panel*, const char *selected, int, struct nk_vec2 size); -NK_API int nk_combo_begin_label(struct nk_context*, struct nk_panel*, const char *selected, struct nk_vec2 size); -NK_API int nk_combo_begin_color(struct nk_context*, struct nk_panel*, struct nk_color color, struct nk_vec2 size); -NK_API int nk_combo_begin_symbol(struct nk_context*, struct nk_panel*, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_combo_begin_symbol_label(struct nk_context*, struct nk_panel*, const char *selected, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_combo_begin_symbol_text(struct nk_context*, struct nk_panel*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_combo_begin_image(struct nk_context*, struct nk_panel*, struct nk_image img, struct nk_vec2 size); -NK_API int nk_combo_begin_image_label(struct nk_context*, struct nk_panel*, const char *selected, struct nk_image, struct nk_vec2 size); -NK_API int nk_combo_begin_image_text(struct nk_context*, struct nk_panel*, const char *selected, int, struct nk_image, struct nk_vec2 size); +NK_API int nk_combo_begin_text(struct nk_context*, const char *selected, int, struct nk_vec2 size); +NK_API int nk_combo_begin_label(struct nk_context*, const char *selected, struct nk_vec2 size); +NK_API int nk_combo_begin_color(struct nk_context*, struct nk_color color, struct nk_vec2 size); +NK_API int nk_combo_begin_symbol(struct nk_context*, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_combo_begin_symbol_label(struct nk_context*, const char *selected, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_combo_begin_symbol_text(struct nk_context*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_combo_begin_image(struct nk_context*, struct nk_image img, struct nk_vec2 size); +NK_API int nk_combo_begin_image_label(struct nk_context*, const char *selected, struct nk_image, struct nk_vec2 size); +NK_API int nk_combo_begin_image_text(struct nk_context*, const char *selected, int, struct nk_image, struct nk_vec2 size); NK_API int nk_combo_item_label(struct nk_context*, const char*, nk_flags alignment); NK_API int nk_combo_item_text(struct nk_context*, const char*,int, nk_flags alignment); NK_API int nk_combo_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); @@ -889,7 +889,7 @@ NK_API void nk_combo_close(struct nk_context*); NK_API void nk_combo_end(struct nk_context*); /* Contextual */ -NK_API int nk_contextual_begin(struct nk_context*, struct nk_panel*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds); +NK_API int nk_contextual_begin(struct nk_context*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds); NK_API int nk_contextual_item_text(struct nk_context*, const char*, int,nk_flags align); NK_API int nk_contextual_item_label(struct nk_context*, const char*, nk_flags align); NK_API int nk_contextual_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); @@ -901,21 +901,21 @@ NK_API void nk_contextual_end(struct nk_context*); /* Tooltip */ NK_API void nk_tooltip(struct nk_context*, const char*); -NK_API int nk_tooltip_begin(struct nk_context*, struct nk_panel*, float width); +NK_API int nk_tooltip_begin(struct nk_context*, float width); NK_API void nk_tooltip_end(struct nk_context*); /* Menu */ NK_API void nk_menubar_begin(struct nk_context*); NK_API void nk_menubar_end(struct nk_context*); -NK_API int nk_menu_begin_text(struct nk_context*, struct nk_panel*, const char* title, int title_len, nk_flags align, struct nk_vec2 size); -NK_API int nk_menu_begin_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align, struct nk_vec2 size); -NK_API int nk_menu_begin_image(struct nk_context*, struct nk_panel*, const char*, struct nk_image, struct nk_vec2 size); -NK_API int nk_menu_begin_image_text(struct nk_context*, struct nk_panel*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size); -NK_API int nk_menu_begin_image_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size); -NK_API int nk_menu_begin_symbol(struct nk_context*, struct nk_panel*, const char*, enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_menu_begin_symbol_text(struct nk_context*, struct nk_panel*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size); -NK_API int nk_menu_begin_symbol_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_menu_begin_text(struct nk_context*, const char* title, int title_len, nk_flags align, struct nk_vec2 size); +NK_API int nk_menu_begin_label(struct nk_context*, const char*, nk_flags align, struct nk_vec2 size); +NK_API int nk_menu_begin_image(struct nk_context*, const char*, struct nk_image, struct nk_vec2 size); +NK_API int nk_menu_begin_image_text(struct nk_context*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size); +NK_API int nk_menu_begin_image_label(struct nk_context*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size); +NK_API int nk_menu_begin_symbol(struct nk_context*, const char*, enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_menu_begin_symbol_text(struct nk_context*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size); +NK_API int nk_menu_begin_symbol_label(struct nk_context*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size); NK_API int nk_menu_item_text(struct nk_context*, const char*, int,nk_flags align); NK_API int nk_menu_item_label(struct nk_context*, const char*, nk_flags alignment); NK_API int nk_menu_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); @@ -1086,6 +1086,207 @@ NK_API int nk_utf_encode(nk_rune, char*, int); NK_API int nk_utf_len(const char*, int byte_len); NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len); +/* =============================================================== + * + * FONT + * + * ===============================================================*/ +/* Font handling in this library was designed to be quite customizable and lets + you decide what you want to use and what you want to provide. In this sense + there are four different degrees between control and ease of use and two + different drawing APIs to provide for. + + So first of the easiest way to do font handling is by just providing a + `nk_user_font` struct which only requires the height in pixel of the used + font and a callback to calculate the width of a string. This way of handling + fonts is best fitted for using the normal draw shape command API were you + do all the text drawing yourself and the library does not require any kind + of deeper knowledge about which font handling mechanism you use. + + While the first approach works fine if you don't want to use the optional + vertex buffer output it is not enough if you do. To get font handling working + for these cases you have to provide two additional parameters inside the + `nk_user_font`. First a texture atlas handle used to draw text as subimages + of a bigger font atlas texture and a callback to query a character's glyph + information (offset, size, ...). So it is still possible to provide your own + font and use the vertex buffer output. + + The final approach if you do not have a font handling functionality or don't + want to use it in this library is by using the optional font baker. This API + is divided into a high- and low-level API with different priorities between + ease of use and control. Both API's can be used to create a font and + font atlas texture and can even be used with or without the vertex buffer + output. So it still uses the `nk_user_font` struct and the two different + approaches previously stated still work. + Now to the difference between the low level API and the high level API. The low + level API provides a lot of control over the baking process of the font and + provides total control over memory. It consists of a number of functions that + need to be called from begin to end and each step requires some additional + configuration, so it is a lot more complex than the high-level API. + If you don't want to do all the work required for using the low-level API + you can use the font atlas API. It provides the same functionality as the + low-level API but takes away some configuration and all of memory control and + in term provides a easier to use API. +*/ +struct nk_user_font_glyph; +typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len); +typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height, + struct nk_user_font_glyph *glyph, + nk_rune codepoint, nk_rune next_codepoint); + +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT +struct nk_user_font_glyph { + struct nk_vec2 uv[2]; + /* texture coordinates */ + struct nk_vec2 offset; + /* offset between top left and glyph */ + float width, height; + /* size of the glyph */ + float xadvance; + /* offset to the next glyph */ +}; +#endif + +struct nk_user_font { + nk_handle userdata; + /* user provided font handle */ + float height; + /* max height of the font */ + nk_text_width_f width; + /* font string width in pixel callback */ +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT + nk_query_font_glyph_f query; + /* font glyph callback to query drawing info */ + nk_handle texture; + /* texture handle to the used font atlas or texture */ +#endif +}; + +#ifdef NK_INCLUDE_FONT_BAKING +enum nk_font_coord_type { + NK_COORD_UV, /* texture coordinates inside font glyphs are clamped between 0-1 */ + NK_COORD_PIXEL /* texture coordinates inside font glyphs are in absolute pixel */ +}; + +struct nk_baked_font { + float height; + /* height of the font */ + float ascent, descent; + /* font glyphs ascent and descent */ + nk_rune glyph_offset; + /* glyph array offset inside the font glyph baking output array */ + nk_rune glyph_count; + /* number of glyphs of this font inside the glyph baking array output */ + const nk_rune *ranges; + /* font codepoint ranges as pairs of (from/to) and 0 as last element */ +}; + +struct nk_font_config { + struct nk_font_config *next; + /* NOTE: only used internally */ + void *ttf_blob; + /* pointer to loaded TTF file memory block. + * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ + nk_size ttf_size; + /* size of the loaded TTF file memory block + * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ + + unsigned char ttf_data_owned_by_atlas; + /* used inside font atlas: default to: 0*/ + unsigned char merge_mode; + /* merges this font into the last font */ + unsigned char pixel_snap; + /* align every character to pixel boundary (if true set oversample (1,1)) */ + unsigned char oversample_v, oversample_h; + /* rasterize at hight quality for sub-pixel position */ + unsigned char padding[3]; + + float size; + /* baked pixel height of the font */ + enum nk_font_coord_type coord_type; + /* texture coordinate format with either pixel or UV coordinates */ + struct nk_vec2 spacing; + /* extra pixel spacing between glyphs */ + const nk_rune *range; + /* list of unicode ranges (2 values per range, zero terminated) */ + struct nk_baked_font *font; + /* font to setup in the baking process: NOTE: not needed for font atlas */ + nk_rune fallback_glyph; + /* fallback glyph to use if a given rune is not found */ +}; + +struct nk_font_glyph { + nk_rune codepoint; + float xadvance; + float x0, y0, x1, y1, w, h; + float u0, v0, u1, v1; +}; + +struct nk_font { + struct nk_font *next; + struct nk_user_font handle; + struct nk_baked_font info; + float scale; + struct nk_font_glyph *glyphs; + const struct nk_font_glyph *fallback; + nk_rune fallback_codepoint; + nk_handle texture; + struct nk_font_config *config; +}; + +enum nk_font_atlas_format { + NK_FONT_ATLAS_ALPHA8, + NK_FONT_ATLAS_RGBA32 +}; + +struct nk_font_atlas { + void *pixel; + int tex_width; + int tex_height; + + struct nk_allocator permanent; + struct nk_allocator temporary; + struct nk_recti custom; + struct nk_cursor cursors[NK_CURSOR_COUNT]; + + int glyph_count; + struct nk_font_glyph *glyphs; + struct nk_font *default_font; + struct nk_font *fonts; + struct nk_font_config *config; + int font_num; +}; + +/* some language glyph codepoint ranges */ +NK_API const nk_rune *nk_font_default_glyph_ranges(void); +NK_API const nk_rune *nk_font_chinese_glyph_ranges(void); +NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void); +NK_API const nk_rune *nk_font_korean_glyph_ranges(void); + +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void nk_font_atlas_init_default(struct nk_font_atlas*); +#endif +NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*); +NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient); +NK_API void nk_font_atlas_begin(struct nk_font_atlas*); +NK_API struct nk_font_config nk_font_config(float pixel_height); +NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*); +#ifdef NK_INCLUDE_DEFAULT_FONT +NK_API struct nk_font* nk_font_atlas_add_default(struct nk_font_atlas*, float height, const struct nk_font_config*); +#endif +NK_API struct nk_font* nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, nk_size size, float height, const struct nk_font_config *config); +#ifdef NK_INCLUDE_STANDARD_IO +NK_API struct nk_font* nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, float height, const struct nk_font_config*); +#endif +NK_API struct nk_font *nk_font_atlas_add_compressed(struct nk_font_atlas*, void *memory, nk_size size, float height, const struct nk_font_config*); +NK_API struct nk_font* nk_font_atlas_add_compressed_base85(struct nk_font_atlas*, const char *data, float height, const struct nk_font_config *config); +NK_API const void* nk_font_atlas_bake(struct nk_font_atlas*, int *width, int *height, enum nk_font_atlas_format); +NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex, struct nk_draw_null_texture*); +NK_API void nk_font_atlas_clear(struct nk_font_atlas*); +NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune unicode); + +#endif + /* ============================================================== * * MEMORY BUFFER @@ -1350,207 +1551,6 @@ NK_API int nk_textedit_paste(struct nk_text_edit*, char const*, int len); NK_API void nk_textedit_undo(struct nk_text_edit*); NK_API void nk_textedit_redo(struct nk_text_edit*); -/* =============================================================== - * - * FONT - * - * ===============================================================*/ -/* Font handling in this library was designed to be quite customizable and lets - you decide what you want to use and what you want to provide. In this sense - there are four different degrees between control and ease of use and two - different drawing APIs to provide for. - - So first of the easiest way to do font handling is by just providing a - `nk_user_font` struct which only requires the height in pixel of the used - font and a callback to calculate the width of a string. This way of handling - fonts is best fitted for using the normal draw shape command API were you - do all the text drawing yourself and the library does not require any kind - of deeper knowledge about which font handling mechanism you use. - - While the first approach works fine if you don't want to use the optional - vertex buffer output it is not enough if you do. To get font handling working - for these cases you have to provide two additional parameters inside the - `nk_user_font`. First a texture atlas handle used to draw text as subimages - of a bigger font atlas texture and a callback to query a character's glyph - information (offset, size, ...). So it is still possible to provide your own - font and use the vertex buffer output. - - The final approach if you do not have a font handling functionality or don't - want to use it in this library is by using the optional font baker. This API - is divided into a high- and low-level API with different priorities between - ease of use and control. Both API's can be used to create a font and - font atlas texture and can even be used with or without the vertex buffer - output. So it still uses the `nk_user_font` struct and the two different - approaches previously stated still work. - Now to the difference between the low level API and the high level API. The low - level API provides a lot of control over the baking process of the font and - provides total control over memory. It consists of a number of functions that - need to be called from begin to end and each step requires some additional - configuration, so it is a lot more complex than the high-level API. - If you don't want to do all the work required for using the low-level API - you can use the font atlas API. It provides the same functionality as the - low-level API but takes away some configuration and all of memory control and - in term provides a easier to use API. -*/ -struct nk_user_font_glyph; -typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len); -typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height, - struct nk_user_font_glyph *glyph, - nk_rune codepoint, nk_rune next_codepoint); - -#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT -struct nk_user_font_glyph { - struct nk_vec2 uv[2]; - /* texture coordinates */ - struct nk_vec2 offset; - /* offset between top left and glyph */ - float width, height; - /* size of the glyph */ - float xadvance; - /* offset to the next glyph */ -}; -#endif - -struct nk_user_font { - nk_handle userdata; - /* user provided font handle */ - float height; - /* max height of the font */ - nk_text_width_f width; - /* font string width in pixel callback */ -#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT - nk_query_font_glyph_f query; - /* font glyph callback to query drawing info */ - nk_handle texture; - /* texture handle to the used font atlas or texture */ -#endif -}; - -#ifdef NK_INCLUDE_FONT_BAKING -enum nk_font_coord_type { - NK_COORD_UV, /* texture coordinates inside font glyphs are clamped between 0-1 */ - NK_COORD_PIXEL /* texture coordinates inside font glyphs are in absolute pixel */ -}; - -struct nk_baked_font { - float height; - /* height of the font */ - float ascent, descent; - /* font glyphs ascent and descent */ - nk_rune glyph_offset; - /* glyph array offset inside the font glyph baking output array */ - nk_rune glyph_count; - /* number of glyphs of this font inside the glyph baking array output */ - const nk_rune *ranges; - /* font codepoint ranges as pairs of (from/to) and 0 as last element */ -}; - -struct nk_font_config { - struct nk_font_config *next; - /* NOTE: only used internally */ - void *ttf_blob; - /* pointer to loaded TTF file memory block. - * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ - nk_size ttf_size; - /* size of the loaded TTF file memory block - * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ - - unsigned char ttf_data_owned_by_atlas; - /* used inside font atlas: default to: 0*/ - unsigned char merge_mode; - /* merges this font into the last font */ - unsigned char pixel_snap; - /* align every character to pixel boundary (if true set oversample (1,1)) */ - unsigned char oversample_v, oversample_h; - /* rasterize at hight quality for sub-pixel position */ - unsigned char padding[3]; - - float size; - /* baked pixel height of the font */ - enum nk_font_coord_type coord_type; - /* texture coordinate format with either pixel or UV coordinates */ - struct nk_vec2 spacing; - /* extra pixel spacing between glyphs */ - const nk_rune *range; - /* list of unicode ranges (2 values per range, zero terminated) */ - struct nk_baked_font *font; - /* font to setup in the baking process: NOTE: not needed for font atlas */ - nk_rune fallback_glyph; - /* fallback glyph to use if a given rune is not found */ -}; - -struct nk_font_glyph { - nk_rune codepoint; - float xadvance; - float x0, y0, x1, y1, w, h; - float u0, v0, u1, v1; -}; - -struct nk_font { - struct nk_font *next; - struct nk_user_font handle; - struct nk_baked_font info; - float scale; - struct nk_font_glyph *glyphs; - const struct nk_font_glyph *fallback; - nk_rune fallback_codepoint; - nk_handle texture; - struct nk_font_config *config; -}; - -enum nk_font_atlas_format { - NK_FONT_ATLAS_ALPHA8, - NK_FONT_ATLAS_RGBA32 -}; - -struct nk_font_atlas { - void *pixel; - int tex_width; - int tex_height; - - struct nk_allocator permanent; - struct nk_allocator temporary; - struct nk_recti custom; - struct nk_cursor cursors[NK_CURSOR_COUNT]; - - int glyph_count; - struct nk_font_glyph *glyphs; - struct nk_font *default_font; - struct nk_font *fonts; - struct nk_font_config *config; - int font_num; -}; - -/* some language glyph codepoint ranges */ -NK_API const nk_rune *nk_font_default_glyph_ranges(void); -NK_API const nk_rune *nk_font_chinese_glyph_ranges(void); -NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void); -NK_API const nk_rune *nk_font_korean_glyph_ranges(void); - -#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR -NK_API void nk_font_atlas_init_default(struct nk_font_atlas*); -#endif -NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*); -NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient); -NK_API void nk_font_atlas_begin(struct nk_font_atlas*); -NK_API struct nk_font_config nk_font_config(float pixel_height); -NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*); -#ifdef NK_INCLUDE_DEFAULT_FONT -NK_API struct nk_font* nk_font_atlas_add_default(struct nk_font_atlas*, float height, const struct nk_font_config*); -#endif -NK_API struct nk_font* nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, nk_size size, float height, const struct nk_font_config *config); -#ifdef NK_INCLUDE_STANDARD_IO -NK_API struct nk_font* nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, float height, const struct nk_font_config*); -#endif -NK_API struct nk_font *nk_font_atlas_add_compressed(struct nk_font_atlas*, void *memory, nk_size size, float height, const struct nk_font_config*); -NK_API struct nk_font* nk_font_atlas_add_compressed_base85(struct nk_font_atlas*, const char *data, float height, const struct nk_font_config *config); -NK_API const void* nk_font_atlas_bake(struct nk_font_atlas*, int *width, int *height, enum nk_font_atlas_format); -NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex, struct nk_draw_null_texture*); -NK_API void nk_font_atlas_clear(struct nk_font_atlas*); -NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune unicode); - -#endif - /* =============================================================== * * DRAWING @@ -1564,14 +1564,7 @@ NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune u After that the command buffer needs to be cleared and a new frame can be started. It is probably important to note that the command buffer is the main drawing API and the optional vertex buffer API only takes this format and - converts it into a hardware accessible format. - - Draw commands are divided into filled shapes and shape outlines but only - filled shapes as well as line, curves and scissor are required to be provided. - All other shape drawing commands can be used but are not required. This was - done to allow the maximum number of render backends to be able to use this - library without you having to do additional work. -*/ + converts it into a hardware accessible format. */ enum nk_command_type { NK_COMMAND_NOP, NK_COMMAND_SCISSOR, @@ -1836,7 +1829,6 @@ NK_API int nk_input_is_key_pressed(const struct nk_input*, enum nk_keys); NK_API int nk_input_is_key_released(const struct nk_input*, enum nk_keys); NK_API int nk_input_is_key_down(const struct nk_input*, enum nk_keys); - /* =============================================================== * * DRAW LIST @@ -2675,6 +2667,7 @@ struct nk_table { union nk_page_data { struct nk_table tbl; + struct nk_panel pan; struct nk_window win; }; @@ -6286,6 +6279,8 @@ NK_API void nk_draw_list_init(struct nk_draw_list *list) { nk_size i = 0; + NK_ASSERT(list); + if (!list) return; nk_zero(list, sizeof(*list)); for (i = 0; i < NK_LEN(list->circle_vtx); ++i) { const float a = ((float)i / (float)NK_LEN(list->circle_vtx)) * 2 * NK_PI; @@ -6298,6 +6293,14 @@ NK_API void nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements) { + NK_ASSERT(canvas); + NK_ASSERT(config); + NK_ASSERT(cmds); + NK_ASSERT(vertices); + NK_ASSERT(elements); + if (!canvas || !config || !cmds || !vertices || !elements) + return; + canvas->buffer = cmds; canvas->config = *config; canvas->elements = elements; @@ -11599,9 +11602,11 @@ nk_textedit_paste(struct nk_text_edit *state, char const *ctext, int len) int glyphs; const char *text = (const char *) ctext; if (state->mode == NK_TEXT_EDIT_MODE_VIEW) return 0; + /* if there's a selection, the paste should delete it */ nk_textedit_clamp(state); nk_textedit_delete_selection(state); + /* try to insert the characters */ glyphs = nk_utf_len(ctext, len); if (nk_str_insert_text_char(&state->string, state->cursor, text, len)) { @@ -12337,7 +12342,7 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, b.h = NK_MAX(b.h, 2 * t->padding.y); label.x = 0; label.w = 0; label.y = b.y + t->padding.y; - label.h = b.h - 2 * t->padding.y; + label.h = NK_MIN(f->height, b.h - 2 * t->padding.y); text_width = f->width(f->userdata, f->height, (const char*)string, len); text_width += (2.0f * t->padding.x); @@ -14921,7 +14926,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) /* default text */ text = &style->text; text->color = table[NK_COLOR_TEXT]; - text->padding = nk_vec2(4,4); + text->padding = nk_vec2(0,0); /* default button */ button = &style->button; @@ -15121,8 +15126,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) scroll->dec_symbol = NK_SYMBOL_CIRCLE_SOLID; scroll->inc_symbol = NK_SYMBOL_CIRCLE_SOLID; scroll->userdata = nk_handle_ptr(0); - scroll->border_color = table[NK_COLOR_BORDER]; - scroll->cursor_border_color = table[NK_COLOR_BORDER]; + scroll->border_color = table[NK_COLOR_SCROLLBAR]; + scroll->cursor_border_color = table[NK_COLOR_SCROLLBAR]; scroll->padding = nk_vec2(0,0); scroll->show_buttons = nk_false; scroll->border = 0; @@ -15660,6 +15665,8 @@ NK_INTERN void nk_remove_window(struct nk_context*, struct nk_window*); NK_INTERN void nk_free_window(struct nk_context *ctx, struct nk_window *win); NK_INTERN void nk_free_table(struct nk_context *ctx, struct nk_table *tbl); NK_INTERN void nk_remove_table(struct nk_window *win, struct nk_table *tbl); +NK_INTERN void* nk_create_panel(struct nk_context *ctx); +NK_INTERN void nk_free_panel(struct nk_context*, struct nk_panel *pan); NK_INTERN void nk_setup(struct nk_context *ctx, const struct nk_user_font *font) @@ -16610,7 +16617,6 @@ nk_panel_end(struct nk_context *ctx) NK_ASSERT(!layout->row.tree_depth); } - /* ---------------------------------------------------------------- * * PAGE ELEMENT @@ -16644,7 +16650,8 @@ nk_create_page_element(struct nk_context *ctx) } NK_INTERN void -nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) +nk_link_page_element_into_freelist(struct nk_context *ctx, + struct nk_page_element *elem) { /* link table into freelist */ if (!ctx->freelist) { @@ -16655,6 +16662,46 @@ nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) } } +NK_INTERN void +nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) +{ + /* fixed size pool so just add to free list */ + if (ctx->use_pool) { + nk_link_page_element_into_freelist(ctx, elem); + return; + } + + /* if possible remove last element from back of fixed memory buffer */ + {void *elem_end = (void*)(elem + 1); + void *buffer_end = (nk_byte*)ctx->memory.memory.ptr + ctx->memory.size; + if (elem_end == buffer_end) + ctx->memory.size -= sizeof(struct nk_page_element); + else nk_link_page_element_into_freelist(ctx, elem);} +} + +/* ---------------------------------------------------------------- + * + * PANEL + * + * ---------------------------------------------------------------*/ +NK_INTERN void* +nk_create_panel(struct nk_context *ctx) +{ + struct nk_page_element *elem; + elem = nk_create_page_element(ctx); + if (!elem) return 0; + nk_zero_struct(*elem); + return &elem->data.pan; +} + +NK_INTERN void +nk_free_panel(struct nk_context *ctx, struct nk_panel *pan) +{ + union nk_page_data *pd = NK_CONTAINER_OF(pan, union nk_page_data, pan); + struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); + nk_free_page_element(ctx, pe); +} + /* ---------------------------------------------------------------- * * TABLES @@ -16663,7 +16710,8 @@ nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) NK_INTERN struct nk_table* nk_create_table(struct nk_context *ctx) { - struct nk_page_element *elem = nk_create_page_element(ctx); + struct nk_page_element *elem; + elem = nk_create_page_element(ctx); if (!elem) return 0; nk_zero_struct(*elem); return &elem->data.tbl; @@ -16755,7 +16803,8 @@ nk_find_value(struct nk_window *win, nk_hash name) NK_INTERN void* nk_create_window(struct nk_context *ctx) { - struct nk_page_element *elem = nk_create_page_element(ctx); + struct nk_page_element *elem; + elem = nk_create_page_element(ctx); if (!elem) return 0; elem->data.win.seq = ctx->seq; return &elem->data.win; @@ -16887,15 +16936,15 @@ nk_remove_window(struct nk_context *ctx, struct nk_window *win) } NK_API int -nk_begin(struct nk_context *ctx, struct nk_panel *layout, const char *title, +nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags) { - return nk_begin_titled(ctx, layout, title, title, bounds, flags); + return nk_begin_titled(ctx, title, title, bounds, flags); } NK_API int -nk_begin_titled(struct nk_context *ctx, struct nk_panel *layout, - const char *name, const char *title, struct nk_rect bounds, nk_flags flags) +nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, + struct nk_rect bounds, nk_flags flags) { struct nk_window *win; struct nk_style *style; @@ -17019,10 +17068,10 @@ nk_begin_titled(struct nk_context *ctx, struct nk_panel *layout, win->flags |= NK_WINDOW_ROM; } - win->layout = layout; + win->layout = nk_create_panel(ctx); ctx->current = win; ret = nk_panel_begin(ctx, title, NK_PANEL_WINDOW); - layout->offset = &win->scrollbar; + win->layout->offset = &win->scrollbar; return ret; } @@ -17038,6 +17087,7 @@ nk_end(struct nk_context *ctx) return; } nk_panel_end(ctx); + nk_free_panel(ctx, ctx->current->layout); ctx->current = 0; } @@ -19913,8 +19963,7 @@ nk_plot_function(struct nk_context *ctx, enum nk_chart_type type, void *userdata * * --------------------------------------------------------------*/ NK_API int -nk_group_begin(struct nk_context *ctx, struct nk_panel *layout, const char *title, - nk_flags flags) +nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags) { struct nk_window *win; const struct nk_rect *c; @@ -19935,20 +19984,6 @@ nk_group_begin(struct nk_context *ctx, struct nk_panel *layout, const char *titl win = ctx->current; c = &win->layout->clip; nk_panel_alloc_space(&bounds, ctx); - nk_zero(layout, sizeof(*layout)); - NK_ASSERT(win->layout != layout && "Parent and group are not allowed to use the same panel"); - /* This assert triggers either if you pass the same panel to a parent parent and child group - * or forgot to add a `nk_group_end` to a `nk_group_begin`. - * Correct example: - * struct nk_panel panel; - * if (nk_begin(...,&panel,...)) { - * struct nk_panel tab; - * if (nk_group_begin(...,&tab,...)) { - * .... - * nk_group_end(...); - * } - * } - */ /* find persistent group scrollbar value */ title_len = (int)nk_strlen(title); @@ -19972,15 +20007,15 @@ nk_group_begin(struct nk_context *ctx, struct nk_panel *layout, const char *titl panel.scrollbar.x = (unsigned short)value.s->x; panel.scrollbar.y = (unsigned short)value.s->y; panel.buffer = win->buffer; - panel.layout = layout; + panel.layout = nk_create_panel(ctx); ctx->current = &panel; nk_panel_begin(ctx, (flags & NK_WINDOW_TITLE) ? title: 0, NK_PANEL_GROUP); win->buffer = panel.buffer; - win->buffer.clip = layout->clip; - layout->offset = value.s; - layout->parent = win->layout; - win->layout = layout; + win->buffer.clip = panel.layout->clip; + panel.layout->offset = value.s; + panel.layout->parent = win->layout; + win->layout = panel.layout; ctx->current = win; return 1; } @@ -20054,8 +20089,8 @@ nk_group_end(struct nk_context *ctx) * * --------------------------------------------------------------*/ NK_API int -nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout, - enum nk_popup_type type, const char *title, nk_flags flags, struct nk_rect rect) +nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, + const char *title, nk_flags flags, struct nk_rect rect) { struct nk_window *popup; struct nk_window *win; @@ -20106,7 +20141,7 @@ nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout, popup->parent = win; popup->bounds = rect; popup->seq = ctx->seq; - popup->layout = layout; + popup->layout = nk_create_panel(ctx); popup->flags = flags; popup->flags |= NK_WINDOW_BORDER; if (type == NK_POPUP_DYNAMIC) @@ -20127,8 +20162,8 @@ nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout, root = root->parent; } win->popup.active = 1; - layout->offset = &popup->scrollbar; - layout->parent = win->layout; + popup->layout->offset = &popup->scrollbar; + popup->layout->parent = win->layout; return 1; } else { /* popup was closed/is invalid so cleanup */ @@ -20147,7 +20182,7 @@ nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout, } NK_INTERN int -nk_nonblock_begin(struct nk_panel *layout, struct nk_context *ctx, +nk_nonblock_begin(struct nk_context *ctx, nk_flags flags, struct nk_rect body, struct nk_rect header, enum nk_panel_type panel_type) { @@ -20198,12 +20233,13 @@ nk_nonblock_begin(struct nk_panel *layout, struct nk_context *ctx, popup->bounds = body; popup->parent = win; - popup->layout = layout; + popup->layout = nk_create_panel(ctx); popup->flags = flags; popup->flags |= NK_WINDOW_BORDER; popup->flags |= NK_WINDOW_DYNAMIC; popup->seq = ctx->seq; win->popup.active = 1; + NK_ASSERT(popup->layout); nk_start_popup(ctx, win); popup->buffer = win->buffer; @@ -20212,8 +20248,8 @@ nk_nonblock_begin(struct nk_panel *layout, struct nk_context *ctx, nk_panel_begin(ctx, 0, panel_type); win->buffer = popup->buffer; - layout->parent = win->layout; - layout->offset = &popup->scrollbar; + popup->layout->parent = win->layout; + popup->layout->offset = &popup->scrollbar; /* set read only mode to all parent panels */ {struct nk_panel *root; @@ -20276,7 +20312,7 @@ nk_popup_end(struct nk_context *ctx) * * -------------------------------------------------------------- */ NK_API int -nk_tooltip_begin(struct nk_context *ctx, struct nk_panel *layout, float width) +nk_tooltip_begin(struct nk_context *ctx, float width) { struct nk_window *win; const struct nk_input *in; @@ -20300,11 +20336,11 @@ nk_tooltip_begin(struct nk_context *ctx, struct nk_panel *layout, float width) bounds.x = (in->mouse.pos.x + 1) - win->layout->clip.x; bounds.y = (in->mouse.pos.y + 1) - win->layout->clip.y; - ret = nk_popup_begin(ctx, layout, NK_POPUP_DYNAMIC, + ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC, "__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds); if (ret) win->layout->flags &= ~(nk_flags)NK_WINDOW_ROM; win->popup.type = NK_PANEL_TOOLTIP; - layout->type = NK_PANEL_TOOLTIP; + ctx->current->layout->type = NK_PANEL_TOOLTIP; return ret; } @@ -20324,7 +20360,6 @@ nk_tooltip(struct nk_context *ctx, const char *text) { const struct nk_style *style; struct nk_vec2 padding; - struct nk_panel layout; int text_len; float text_width; @@ -20349,7 +20384,7 @@ nk_tooltip(struct nk_context *ctx, const char *text) text_height = (style->font->height + 2 * padding.y); /* execute tooltip and fill with text */ - if (nk_tooltip_begin(ctx, &layout, (float)text_width)) { + if (nk_tooltip_begin(ctx, (float)text_width)) { nk_layout_row_dynamic(ctx, (float)text_height, 1); nk_text(ctx, text, text_len, NK_TEXT_LEFT); nk_tooltip_end(ctx); @@ -20361,8 +20396,8 @@ nk_tooltip(struct nk_context *ctx, const char *text) * * -------------------------------------------------------------- */ NK_API int -nk_contextual_begin(struct nk_context *ctx, struct nk_panel *layout, - nk_flags flags, struct nk_vec2 size, struct nk_rect trigger_bounds) +nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, + struct nk_rect trigger_bounds) { struct nk_window *win; struct nk_window *popup; @@ -20405,7 +20440,7 @@ nk_contextual_begin(struct nk_context *ctx, struct nk_panel *layout, body.h = size.y; /* start nonblocking contextual popup */ - ret = nk_nonblock_begin(layout, ctx, flags|NK_WINDOW_NO_SCROLLBAR, body, + ret = nk_nonblock_begin(ctx, flags|NK_WINDOW_NO_SCROLLBAR, body, null_rect, NK_PANEL_CONTEXTUAL); if (ret) win->popup.type = NK_PANEL_CONTEXTUAL; else { @@ -20578,7 +20613,7 @@ nk_contextual_end(struct nk_context *ctx) * * --------------------------------------------------------------*/ NK_INTERN int -nk_combo_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window *win, +nk_combo_begin(struct nk_context *ctx, struct nk_window *win, struct nk_vec2 size, int is_clicked, struct nk_rect header) { struct nk_window *popup; @@ -20604,7 +20639,7 @@ nk_combo_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_COMBO); if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || (!is_open && !is_active && !is_clicked)) return 0; - if (!nk_nonblock_begin(layout, ctx, 0, body, + if (!nk_nonblock_begin(ctx, 0, body, (is_clicked && is_open)?nk_rect(0,0,0,0):header, NK_PANEL_COMBO)) return 0; win->popup.type = NK_PANEL_COMBO; @@ -20613,8 +20648,8 @@ nk_combo_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window } NK_API int -nk_combo_begin_text(struct nk_context *ctx, struct nk_panel *layout, - const char *selected, int len, struct nk_vec2 size) +nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, + struct nk_vec2 size) { const struct nk_input *in; struct nk_window *win; @@ -20699,16 +20734,14 @@ nk_combo_begin_text(struct nk_context *ctx, struct nk_panel *layout, nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, &ctx->style.combo.button, sym, style->font); } - return nk_combo_begin(layout, ctx, win, size, is_clicked, header); + return nk_combo_begin(ctx, win, size, is_clicked, header); } -NK_API int nk_combo_begin_label(struct nk_context *ctx, struct nk_panel *layout, - const char *selected, struct nk_vec2 size) -{return nk_combo_begin_text(ctx, layout, selected, nk_strlen(selected), size);} +NK_API int nk_combo_begin_label(struct nk_context *ctx, const char *selected, struct nk_vec2 size) +{return nk_combo_begin_text(ctx, selected, nk_strlen(selected), size);} NK_API int -nk_combo_begin_color(struct nk_context *ctx, struct nk_panel *layout, - struct nk_color color, struct nk_vec2 size) +nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; @@ -20782,12 +20815,11 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_panel *layout, nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, &ctx->style.combo.button, sym, style->font); } - return nk_combo_begin(layout, ctx, win, size, is_clicked, header); + return nk_combo_begin(ctx, win, size, is_clicked, header); } NK_API int -nk_combo_begin_symbol(struct nk_context *ctx, struct nk_panel *layout, - enum nk_symbol_type symbol, struct nk_vec2 size) +nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; @@ -20871,12 +20903,12 @@ nk_combo_begin_symbol(struct nk_context *ctx, struct nk_panel *layout, nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state, &ctx->style.combo.button, sym, style->font); } - return nk_combo_begin(layout, ctx, win, size, is_clicked, header); + return nk_combo_begin(ctx, win, size, is_clicked, header); } NK_API int -nk_combo_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout, - const char *selected, int len, enum nk_symbol_type symbol, struct nk_vec2 size) +nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len, + enum nk_symbol_type symbol, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; @@ -20968,12 +21000,11 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout, label.h = header.h - 2 * style->combo.content_padding.y; nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font); } - return nk_combo_begin(layout, ctx, win, size, is_clicked, header); + return nk_combo_begin(ctx, win, size, is_clicked, header); } NK_API int -nk_combo_begin_image(struct nk_context *ctx, struct nk_panel *layout, - struct nk_image img, struct nk_vec2 size) +nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; @@ -21047,12 +21078,12 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_panel *layout, nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state, &ctx->style.combo.button, sym, style->font); } - return nk_combo_begin(layout, ctx, win, size, is_clicked, header); + return nk_combo_begin(ctx, win, size, is_clicked, header); } NK_API int -nk_combo_begin_image_text(struct nk_context *ctx, struct nk_panel *layout, - const char *selected, int len, struct nk_image img, struct nk_vec2 size) +nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, + struct nk_image img, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; @@ -21139,16 +21170,16 @@ nk_combo_begin_image_text(struct nk_context *ctx, struct nk_panel *layout, label.h = header.h - 2 * style->combo.content_padding.y; nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font); } - return nk_combo_begin(layout, ctx, win, size, is_clicked, header); + return nk_combo_begin(ctx, win, size, is_clicked, header); } -NK_API int nk_combo_begin_symbol_label(struct nk_context *ctx, struct nk_panel *layout, +NK_API int nk_combo_begin_symbol_label(struct nk_context *ctx, const char *selected, enum nk_symbol_type type, struct nk_vec2 size) -{return nk_combo_begin_symbol_text(ctx, layout, selected, nk_strlen(selected), type, size);} +{return nk_combo_begin_symbol_text(ctx, selected, nk_strlen(selected), type, size);} -NK_API int nk_combo_begin_image_label(struct nk_context *ctx, struct nk_panel *layout, +NK_API int nk_combo_begin_image_label(struct nk_context *ctx, const char *selected, struct nk_image img, struct nk_vec2 size) -{return nk_combo_begin_image_text(ctx, layout, selected, nk_strlen(selected), img, size);} +{return nk_combo_begin_image_text(ctx, selected, nk_strlen(selected), img, size);} NK_API int nk_combo_item_text(struct nk_context *ctx, const char *text, int len,nk_flags align) {return nk_contextual_item_text(ctx, text, len, align);} @@ -21184,7 +21215,6 @@ nk_combo(struct nk_context *ctx, const char **items, int count, { int i = 0; int max_height; - struct nk_panel combo; struct nk_vec2 item_spacing; struct nk_vec2 window_padding; @@ -21199,7 +21229,7 @@ nk_combo(struct nk_context *ctx, const char **items, int count, max_height = count * item_height + count * (int)item_spacing.y; max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; size.y = NK_MIN(size.y, (float)max_height); - if (nk_combo_begin_label(ctx, &combo, items[selected], size)) { + if (nk_combo_begin_label(ctx, items[selected], size)) { nk_layout_row_dynamic(ctx, (float)item_height, 1); for (i = 0; i < count; ++i) { if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) @@ -21216,7 +21246,6 @@ nk_combo_separator(struct nk_context *ctx, const char *items_separated_by_separa { int i; int max_height; - struct nk_panel combo; struct nk_vec2 item_spacing; struct nk_vec2 window_padding; const char *current_item; @@ -21244,7 +21273,7 @@ nk_combo_separator(struct nk_context *ctx, const char *items_separated_by_separa current_item = iter + 1; } - if (nk_combo_begin_text(ctx, &combo, current_item, length, size)) { + if (nk_combo_begin_text(ctx, current_item, length, size)) { current_item = items_separated_by_separator; nk_layout_row_dynamic(ctx, (float)item_height, 1); for (i = 0; i < count; ++i) { @@ -21271,7 +21300,6 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c { int i; int max_height; - struct nk_panel combo; struct nk_vec2 item_spacing; struct nk_vec2 window_padding; const char *item; @@ -21289,7 +21317,7 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c size.y = NK_MIN(size.y, (float)max_height); item_getter(userdata, selected, &item); - if (nk_combo_begin_label(ctx, &combo, item, size)) { + if (nk_combo_begin_label(ctx, item, size)) { nk_layout_row_dynamic(ctx, (float)item_height, 1); for (i = 0; i < count; ++i) { item_getter(userdata, i, &item); @@ -21327,7 +21355,7 @@ NK_API void nk_combobox_callback(struct nk_context *ctx, * -------------------------------------------------------------- */ NK_INTERN int -nk_menu_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window *win, +nk_menu_begin(struct nk_context *ctx, struct nk_window *win, const char *id, int is_clicked, struct nk_rect header, struct nk_vec2 size) { int is_open = 0; @@ -21352,7 +21380,7 @@ nk_menu_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_MENU); if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || (!is_open && !is_active && !is_clicked)) return 0; - if (!nk_nonblock_begin(layout, ctx, NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU)) + if (!nk_nonblock_begin(ctx, NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU)) return 0; win->popup.type = NK_PANEL_MENU; @@ -21361,8 +21389,8 @@ nk_menu_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window } NK_API int -nk_menu_begin_text(struct nk_context *ctx, struct nk_panel *layout, - const char *title, int len, nk_flags align, struct nk_vec2 size) +nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, + nk_flags align, struct nk_vec2 size) { struct nk_window *win; const struct nk_input *in; @@ -21383,16 +21411,16 @@ nk_menu_begin_text(struct nk_context *ctx, struct nk_panel *layout, if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, header, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) is_clicked = nk_true; - return nk_menu_begin(layout, ctx, win, title, is_clicked, header, size); + return nk_menu_begin(ctx, win, title, is_clicked, header, size); } -NK_API int nk_menu_begin_label(struct nk_context *ctx, struct nk_panel *layout, +NK_API int nk_menu_begin_label(struct nk_context *ctx, const char *text, nk_flags align, struct nk_vec2 size) -{return nk_menu_begin_text(ctx, layout, text, nk_strlen(text), align, size);} +{return nk_menu_begin_text(ctx, text, nk_strlen(text), align, size);} NK_API int -nk_menu_begin_image(struct nk_context *ctx, struct nk_panel *layout, - const char *id, struct nk_image img, struct nk_vec2 size) +nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, + struct nk_vec2 size) { struct nk_window *win; struct nk_rect header; @@ -21413,12 +21441,12 @@ nk_menu_begin_image(struct nk_context *ctx, struct nk_panel *layout, if (nk_do_button_image(&ctx->last_widget_state, &win->buffer, header, img, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in)) is_clicked = nk_true; - return nk_menu_begin(layout, ctx, win, id, is_clicked, header, size); + return nk_menu_begin(ctx, win, id, is_clicked, header, size); } NK_API int -nk_menu_begin_symbol(struct nk_context *ctx, struct nk_panel *layout, - const char *id, enum nk_symbol_type sym, struct nk_vec2 size) +nk_menu_begin_symbol(struct nk_context *ctx, const char *id, + enum nk_symbol_type sym, struct nk_vec2 size) { struct nk_window *win; const struct nk_input *in; @@ -21439,12 +21467,12 @@ nk_menu_begin_symbol(struct nk_context *ctx, struct nk_panel *layout, if (nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, header, sym, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) is_clicked = nk_true; - return nk_menu_begin(layout, ctx, win, id, is_clicked, header, size); + return nk_menu_begin(ctx, win, id, is_clicked, header, size); } NK_API int -nk_menu_begin_image_text(struct nk_context *ctx, struct nk_panel *layout, - const char *title, int len, nk_flags align, struct nk_image img, struct nk_vec2 size) +nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, + nk_flags align, struct nk_image img, struct nk_vec2 size) { struct nk_window *win; struct nk_rect header; @@ -21466,16 +21494,16 @@ nk_menu_begin_image_text(struct nk_context *ctx, struct nk_panel *layout, header, img, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, ctx->style.font, in)) is_clicked = nk_true; - return nk_menu_begin(layout, ctx, win, title, is_clicked, header, size); + return nk_menu_begin(ctx, win, title, is_clicked, header, size); } -NK_API int nk_menu_begin_image_label(struct nk_context *ctx, struct nk_panel *layout, +NK_API int nk_menu_begin_image_label(struct nk_context *ctx, const char *title, nk_flags align, struct nk_image img, struct nk_vec2 size) -{return nk_menu_begin_image_text(ctx, layout, title, nk_strlen(title), align, img, size);} +{return nk_menu_begin_image_text(ctx, title, nk_strlen(title), align, img, size);} NK_API int -nk_menu_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout, - const char *title, int len, nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size) +nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len, + nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size) { struct nk_window *win; struct nk_rect header; @@ -21497,12 +21525,12 @@ nk_menu_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout, if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, header, sym, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, ctx->style.font, in)) is_clicked = nk_true; - return nk_menu_begin(layout, ctx, win, title, is_clicked, header, size); + return nk_menu_begin(ctx, win, title, is_clicked, header, size); } -NK_API int nk_menu_begin_symbol_label(struct nk_context *ctx, struct nk_panel *layout, +NK_API int nk_menu_begin_symbol_label(struct nk_context *ctx, const char *title, nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size ) -{return nk_menu_begin_symbol_text(ctx, layout, title, nk_strlen(title), align,sym,size);} +{return nk_menu_begin_symbol_text(ctx, title, nk_strlen(title), align,sym,size);} NK_API int nk_menu_item_text(struct nk_context *ctx, const char *title, int len, nk_flags align) {return nk_contextual_item_text(ctx, title, len, align);}