From 7c9659f3b8396db69cbbcdbe9c52fd4c575d7564 Mon Sep 17 00:00:00 2001 From: vurtun Date: Thu, 21 Apr 2016 10:54:01 +0200 Subject: [PATCH] Fixed #99 forgot to set clipboard callbacks Previously if you use `nk_edit_string` and use flag `NK_EDIT_CLIPBOARD`, callbacks were not passed. I only tested it with `nk_edit_buffer` and set the callbacks directly. This wrong behavior is now fixed and should work copy & paste should behave correctly. --- demo/allegro5/main.c | 2 +- demo/glfw/main.c | 2 +- demo/sdl/main.c | 7 ++++--- demo/x11/main.c | 2 +- nuklear.h | 15 +++++++++------ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/demo/allegro5/main.c b/demo/allegro5/main.c index 0587e08..e1c5614 100644 --- a/demo/allegro5/main.c +++ b/demo/allegro5/main.c @@ -93,7 +93,7 @@ main(void) if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; - nk_layout_row_dynamic(ctx, 22, 1); + nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); {struct nk_panel combo; diff --git a/demo/glfw/main.c b/demo/glfw/main.c index 26d8c3e..aa2dba9 100644 --- a/demo/glfw/main.c +++ b/demo/glfw/main.c @@ -100,7 +100,7 @@ int main(void) if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; - nk_layout_row_dynamic(ctx, 22, 1); + nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); {struct nk_panel combo; diff --git a/demo/sdl/main.c b/demo/sdl/main.c index c768657..21ec262 100644 --- a/demo/sdl/main.c +++ b/demo/sdl/main.c @@ -69,13 +69,13 @@ main(void) {struct nk_font_atlas *atlas; nk_sdl_font_stash_begin(&atlas); /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ - /*struct nk_font *robot = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Robot-Regular.ttf", 14, 0);*/ + /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/ /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ nk_sdl_font_stash_end(); - /*nk_style_set_font(ctx, &droid->handle)*/;} + /*nk_style_set_font(ctx, &roboto->handle)*/;} background = nk_rgb(28,48,62); while (running) @@ -98,13 +98,14 @@ main(void) 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", NK_BUTTON_DEFAULT)) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; - nk_layout_row_dynamic(ctx, 22, 1); + nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); {struct nk_panel combo; diff --git a/demo/x11/main.c b/demo/x11/main.c index 182e9db..f58bb2e 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -138,7 +138,7 @@ main(void) nk_layout_row_dynamic(ctx, 30, 2); if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; - nk_layout_row_dynamic(ctx, 22, 1); + nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } nk_end(ctx);} diff --git a/nuklear.h b/nuklear.h index bbacbe3..bddc80f 100644 --- a/nuklear.h +++ b/nuklear.h @@ -12764,18 +12764,19 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, /* cut & copy handler */ {int copy= nk_input_is_key_pressed(in, NK_KEY_COPY); int cut = nk_input_is_key_pressed(in, NK_KEY_CUT); - if ((copy || cut) && (flags & NK_EDIT_CLIPBOARD) && edit->clip.copy) + if ((copy || cut) && (flags & NK_EDIT_CLIPBOARD)) { int glyph_len; nk_rune unicode; const char *text; - int begin = edit->select_start; - int end = edit->select_end; + int b = edit->select_start; + int e = edit->select_end; - begin = NK_MIN(begin, end); - end = NK_MAX(begin, end); + int begin = NK_MIN(b, e); + int end = NK_MAX(b, e); text = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len); - edit->clip.copy(edit->clip.userdata, text, end - begin); + if (edit->clip.copy) + edit->clip.copy(edit->clip.userdata, text, end - begin); if (cut){ nk_textedit_cut(edit); cursor_follow = nk_true; @@ -17541,6 +17542,8 @@ nk_edit_buffer(struct nk_context *ctx, nk_flags flags, edit->select_start = edit->cursor; edit->select_end = edit->cursor; } + if (flags & NK_EDIT_CLIPBOARD) + edit->clip = ctx->clip; } filter = (!filter) ? nk_filter_default: filter;