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.
This commit is contained in:
parent
ca4d5bad8c
commit
7c9659f3b8
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);}
|
||||
|
15
nuklear.h
15
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;
|
||||
|
Loading…
Reference in New Issue
Block a user