Browse Source

Added functions to manually set edit widget focus

I added function `nk_edit_focus` to set the focus to the next edit
widget that will be called after calling.
vurtun 9 years ago
parent
commit
867b3359b9
2 changed files with 38 additions and 17 deletions
  1. 1 0
      CHANGELOG.md
  2. 37 17
      nuklear.h

+ 1 - 0
CHANGELOG.md

@@ -1,4 +1,5 @@
 # Changelog
 # Changelog
+- 2016/10/18 (1.160)- Added `nk_edit_focus` for manually edit widget focus control
 - 2016/09/29 (1.157)- Fixed deduction of basic type in non `<stdint.h>` compilation
 - 2016/09/29 (1.157)- Fixed deduction of basic type in non `<stdint.h>` compilation
 - 2016/09/29 (1.156)- Fixed edit widget UTF-8 text cursor drawing bug
 - 2016/09/29 (1.156)- Fixed edit widget UTF-8 text cursor drawing bug
 - 2016/09/28 (1.156)- Fixed edit widget UTF-8 text appending/inserting/removing
 - 2016/09/28 (1.156)- Fixed edit widget UTF-8 text appending/inserting/removing

+ 37 - 17
nuklear.h

@@ -49,7 +49,7 @@ USAGE:
 FEATURES:
 FEATURES:
     - Absolutely no platform dependend code
     - Absolutely no platform dependend code
     - Memory management control ranging from/to
     - Memory management control ranging from/to
-        - Ease of use by allocating everything from the standard library
+        - Ease of use by allocating everything from standard library
         - Control every byte of memory inside the library
         - Control every byte of memory inside the library
     - Font handling control ranging from/to
     - Font handling control ranging from/to
         - Use your own font implementation for everything
         - Use your own font implementation for everything
@@ -134,6 +134,13 @@ OPTIONAL DEFINES:
         define this it will only trigger if a button is released.
         define this it will only trigger if a button is released.
         <!> If used it is only required to be defined for the implementation part <!>
         <!> If used it is only required to be defined for the implementation part <!>
 
 
+    NK_ZERO_COMMAND_MEMORY
+        Defining this will zero out memory for each drawing command added to a
+        drawing queue (inside nk_command_buffer_push). Zeroing command memory
+        is very useful for fast checking (using memcmp) if command buffers are
+        equal and avoid drawing frames when nothing on screen has changed since
+        previous frame.
+
     NK_ASSERT
     NK_ASSERT
         If you don't define this, nuklear will use <assert.h> with assert().
         If you don't define this, nuklear will use <assert.h> with assert().
         <!> Adds the standard library so define to nothing of not wanted <!>
         <!> Adds the standard library so define to nothing of not wanted <!>
@@ -214,15 +221,8 @@ OPTIONAL DEFINES:
         will be selected and compile time validated. If they are incorrect you can
         will be selected and compile time validated. If they are incorrect you can
         define the correct types by overloading these type defines.
         define the correct types by overloading these type defines.
 
 
-    NK_ZERO_COMMAND_MEMORY
-        Defining this will zero out memory for each drawing command added to a
-        drawing queue (inside nk_command_buffer_push). This can be used to
-        implement fast check (using memcmp) that command buffers are equal and
-        avoid drawing frames when nothing on screen has changed since previous
-        frame.
-
 CREDITS:
 CREDITS:
-    Developed by Micha Mettke and every direct or indirect contributor to the GitHub.
+    Developed by Micha Mettke and every direct or indirect contributor.
 
 
     Embeds stb_texedit, stb_truetype and stb_rectpack by Sean Barret (public domain)
     Embeds stb_texedit, stb_truetype and stb_rectpack by Sean Barret (public domain)
     Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license).
     Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license).
@@ -838,6 +838,7 @@ NK_API float                    nk_propertyf(struct nk_context*, const char *nam
 NK_API double                   nk_propertyd(struct nk_context*, const char *name, double min, double val, double max, double step, float inc_per_pixel);
 NK_API double                   nk_propertyd(struct nk_context*, const char *name, double min, double val, double max, double step, float inc_per_pixel);
 
 
 /* Widgets: TextEdit */
 /* Widgets: TextEdit */
+NK_API void                     nk_edit_focus(struct nk_context *ctx, nk_flags flags);
 NK_API nk_flags                 nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_plugin_filter);
 NK_API nk_flags                 nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_plugin_filter);
 NK_API nk_flags                 nk_edit_buffer(struct nk_context*, nk_flags, struct nk_text_edit*, nk_plugin_filter);
 NK_API nk_flags                 nk_edit_buffer(struct nk_context*, nk_flags, struct nk_text_edit*, nk_plugin_filter);
 NK_API nk_flags                 nk_edit_string_zero_terminated(struct nk_context*, nk_flags, char *buffer, int max, nk_plugin_filter);
 NK_API nk_flags                 nk_edit_string_zero_terminated(struct nk_context*, nk_flags, char *buffer, int max, nk_plugin_filter);
@@ -3810,8 +3811,8 @@ nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args)
     nk_flags flag = 0;
     nk_flags flag = 0;
 
 
     int len = 0;
     int len = 0;
-    const char *iter = fmt;
     int result = -1;
     int result = -1;
+    const char *iter = fmt;
 
 
     NK_ASSERT(buf);
     NK_ASSERT(buf);
     NK_ASSERT(buf_size);
     NK_ASSERT(buf_size);
@@ -10059,8 +10060,8 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
     const void *in_memory)
     const void *in_memory)
 {
 {
     int n = 0;
     int n = 0;
-    const nk_byte *src;
     nk_rune *dst;
     nk_rune *dst;
+    const nk_byte *src;
 
 
     NK_ASSERT(out_memory);
     NK_ASSERT(out_memory);
     NK_ASSERT(in_memory);
     NK_ASSERT(in_memory);
@@ -10814,9 +10815,8 @@ nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height,
 
 
     /* allocate glyph memory for all fonts */
     /* allocate glyph memory for all fonts */
     baker = nk_font_baker(tmp, atlas->glyph_count, atlas->font_num, &atlas->temporary);
     baker = nk_font_baker(tmp, atlas->glyph_count, atlas->font_num, &atlas->temporary);
-    atlas->glyphs = (struct nk_font_glyph*)
-        atlas->permanent.alloc(atlas->permanent.userdata,0,
-                sizeof(struct nk_font_glyph) * (nk_size)atlas->glyph_count);
+    atlas->glyphs = (struct nk_font_glyph*)atlas->permanent.alloc(
+        atlas->permanent.userdata,0, sizeof(struct nk_font_glyph)*(nk_size)atlas->glyph_count);
     NK_ASSERT(atlas->glyphs);
     NK_ASSERT(atlas->glyphs);
     if (!atlas->glyphs)
     if (!atlas->glyphs)
         goto failed;
         goto failed;
@@ -15712,6 +15712,7 @@ nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds,
     NK_ASSERT(cmds);
     NK_ASSERT(cmds);
     NK_ASSERT(pool);
     NK_ASSERT(pool);
     if (!cmds || !pool) return 0;
     if (!cmds || !pool) return 0;
+
     nk_setup(ctx, font);
     nk_setup(ctx, font);
     ctx->memory = *cmds;
     ctx->memory = *cmds;
     if (pool->type == NK_BUFFER_FIXED) {
     if (pool->type == NK_BUFFER_FIXED) {
@@ -15756,9 +15757,8 @@ nk_free(struct nk_context *ctx)
     NK_ASSERT(ctx);
     NK_ASSERT(ctx);
     if (!ctx) return;
     if (!ctx) return;
     nk_buffer_free(&ctx->memory);
     nk_buffer_free(&ctx->memory);
-    if (ctx->use_pool) {
+    if (ctx->use_pool)
         nk_pool_free(&ctx->pool);
         nk_pool_free(&ctx->pool);
-    }
 
 
     nk_zero(&ctx->input, sizeof(ctx->input));
     nk_zero(&ctx->input, sizeof(ctx->input));
     nk_zero(&ctx->style, sizeof(ctx->style));
     nk_zero(&ctx->style, sizeof(ctx->style));
@@ -16593,7 +16593,7 @@ nk_panel_end(struct nk_context *ctx)
 
 
     /* edit garbage collector */
     /* edit garbage collector */
     if (window->edit.active && window->edit.old != window->edit.seq &&
     if (window->edit.active && window->edit.old != window->edit.seq &&
-        window->edit.active == window->edit.prev) {
+       window->edit.active == window->edit.prev) {
         nk_zero(&window->edit, sizeof(window->edit));
         nk_zero(&window->edit, sizeof(window->edit));
     } else {
     } else {
         window->edit.old = window->edit.seq;
         window->edit.old = window->edit.seq;
@@ -18658,6 +18658,7 @@ nk_button_pop_behavior(struct nk_context *ctx)
     *element->address = element->old_value;
     *element->address = element->old_value;
     return 1;
     return 1;
 }
 }
+
 NK_API int
 NK_API int
 nk_button_text(struct nk_context *ctx, const char *title, int len)
 nk_button_text(struct nk_context *ctx, const char *title, int len)
 {
 {
@@ -19194,6 +19195,24 @@ NK_API nk_size nk_prog(struct nk_context *ctx, nk_size cur, nk_size max, int mod
  *                          EDIT
  *                          EDIT
  *
  *
  * --------------------------------------------------------------*/
  * --------------------------------------------------------------*/
+NK_API void
+nk_edit_focus(struct nk_context *ctx, nk_flags flags)
+{
+    nk_hash hash;
+    struct nk_window *win;
+
+    NK_ASSERT(ctx);
+    NK_ASSERT(ctx->current);
+    if (!ctx || !ctx->current) return;
+
+    win = ctx->current;
+    hash = win->edit.seq;
+    win->edit.active = nk_true;
+    win->edit.name = hash;
+    if (flags & NK_EDIT_ALWAYS_INSERT_MODE)
+        win->edit.mode = NK_TEXT_EDIT_MODE_INSERT;
+}
+
 NK_API nk_flags
 NK_API nk_flags
 nk_edit_string(struct nk_context *ctx, nk_flags flags,
 nk_edit_string(struct nk_context *ctx, nk_flags flags,
     char *memory, int *len, int max, nk_plugin_filter filter)
     char *memory, int *len, int max, nk_plugin_filter filter)
@@ -19600,6 +19619,7 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type,
     NK_ASSERT(ctx);
     NK_ASSERT(ctx);
     NK_ASSERT(ctx->current);
     NK_ASSERT(ctx->current);
     NK_ASSERT(ctx->current->layout);
     NK_ASSERT(ctx->current->layout);
+
     if (!ctx || !ctx->current || !ctx->current->layout) return 0;
     if (!ctx || !ctx->current || !ctx->current->layout) return 0;
     if (!nk_widget(&bounds, ctx)) {
     if (!nk_widget(&bounds, ctx)) {
         chart = &ctx->current->layout->chart;
         chart = &ctx->current->layout->chart;