@@ -4917,6 +4917,11 @@ struct nk_keyboard {
49174917 struct nk_key keys[NK_KEY_MAX];
49184918 char text[NK_INPUT_MAX];
49194919 int text_len;
4920+
4921+ /*Text keyboard request system*/
4922+ nk_bool text_want; /*When true, text input is actively requested*/
4923+ struct nk_rect text_area; /*Input area (valid only when text_want == true)*/
4924+ struct nk_rect text_cursor; /*Cursor position (valid only when text_want == true)*/
49204925};
49214926
49224927struct nk_input {
@@ -4941,6 +4946,10 @@ NK_API nk_bool nk_input_is_mouse_released(const struct nk_input*, enum nk_button
49414946NK_API nk_bool nk_input_is_key_pressed(const struct nk_input*, enum nk_keys);
49424947NK_API nk_bool nk_input_is_key_released(const struct nk_input*, enum nk_keys);
49434948NK_API nk_bool nk_input_is_key_down(const struct nk_input*, enum nk_keys);
4949+ /* This is a utility function that should be called inside a widget
4950+ * to mark text keyboard for opening.
4951+ * Returns true only on the first request each frame */
4952+ NK_API nk_bool nk_input_want_text_keyboard(struct nk_input*);
49444953
49454954/* ===============================================================
49464955 *
@@ -18199,6 +18208,10 @@ nk_input_begin(struct nk_context *ctx)
1819918208 for (i = 0; i < NK_BUTTON_MAX; ++i)
1820018209 in->mouse.buttons[i].clicked = 0;
1820118210
18211+ in->keyboard.text_want = nk_false;
18212+ in->keyboard.text_area = nk_rect(0.0f, 0.0f, 0.0f, 0.0f);
18213+ in->keyboard.text_cursor = nk_rect(0.0f, 0.0f, 0.0f, 0.0f);
18214+
1820218215 in->keyboard.text_len = 0;
1820318216 in->mouse.scroll_delta = nk_vec2(0,0);
1820418217 in->mouse.prev.x = in->mouse.pos.x;
@@ -18469,7 +18482,14 @@ nk_input_is_key_down(const struct nk_input *i, enum nk_keys key)
1846918482 if (k->down) return nk_true;
1847018483 return nk_false;
1847118484}
18472-
18485+ NK_API nk_bool
18486+ nk_input_want_text_keyboard(struct nk_input* i)
18487+ {
18488+ NK_ASSERT(i);
18489+ nk_bool ret = !i->keyboard.text_want;
18490+ i->keyboard.text_want = nk_true;
18491+ return ret;
18492+ }
1847318493
1847418494
1847518495
@@ -27997,6 +28017,9 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2799728017 char cursor_follow = 0;
2799828018 struct nk_rect old_clip;
2799928019 struct nk_rect clip;
28020+ /*Variables for text keyboard(kb) support*/
28021+ nk_bool kb_text_want = nk_false;
28022+ struct nk_rect kb_text_cursor = nk_rect(0.0f, 0.0f, 0.0f, 0.0f);
2800028023
2800128024 NK_ASSERT(state);
2800228025 NK_ASSERT(out);
@@ -28082,13 +28105,17 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2808228105 cursor_follow = nk_true;
2808328106 }
2808428107 }
28085- if (old_mode != edit->mode) {
28108+ /* If mode changes and text keys are pressed in the same frame,
28109+ * mode change takes priority (may transition to VIEW mode) */
28110+ if (old_mode != edit->mode)
2808628111 in->keyboard.text_len = 0;
28087- }}
28112+ else if (edit->mode == NK_TEXT_EDIT_MODE_INSERT || edit->mode == NK_TEXT_EDIT_MODE_REPLACE)
28113+ kb_text_want = nk_input_want_text_keyboard(in);
28114+ }
2808828115
2808928116 /* text input */
2809028117 edit->filter = filter;
28091- if (in->keyboard.text_len) {
28118+ if (kb_text_want && in->keyboard.text_len) {
2809228119 nk_textedit_text(edit, in->keyboard.text, in->keyboard.text_len);
2809328120 cursor_follow = nk_true;
2809428121 in->keyboard.text_len = 0;
@@ -28449,6 +28476,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2844928476 cursor.x = area.x + cursor_pos.x - edit->scrollbar.x;
2845028477 cursor.y = area.y + cursor_pos.y + row_height/2.0f - cursor.h/2.0f;
2845128478 cursor.y -= edit->scrollbar.y;
28479+ kb_text_cursor = cursor;
2845228480 nk_fill_rect(out, cursor, 0, cursor_color);
2845328481 } else {
2845428482 /* draw cursor inside text */
@@ -28468,6 +28496,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2846828496 txt.padding = nk_vec2(0,0);
2846928497 txt.background = cursor_color;;
2847028498 txt.text = cursor_text_color;
28499+ kb_text_cursor = label;
2847128500 nk_fill_rect(out, label, 0, cursor_color);
2847228501 nk_widget_text(out, label, cursor_ptr, glyph_len, &txt, NK_TEXT_LEFT, font);
2847328502 }
@@ -28504,6 +28533,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2850428533 background_color, text_color, nk_false);
2850528534 }
2850628535 nk_push_scissor(out, old_clip);}
28536+ if (kb_text_want) {
28537+ NK_ASSERT(in);
28538+ in->keyboard.text_cursor = kb_text_cursor;
28539+ in->keyboard.text_area = clip;
28540+ }
2850728541 return ret;
2850828542}
2850928543NK_API void
@@ -30729,6 +30763,9 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
3072930763/// - [y]: Minor version with non-breaking API and library changes
3073030764/// - [z]: Patch version with no direct changes to the API
3073130765///
30766+ /// - 2025/11/13 (4.13.0) - Introduced minimal text keyboard request API (nk_input_want_text_keyboard)
30767+ /// with support for text input area and cursor position.
30768+ /// This functionality is required for SDL_SetTextInputRect
3073230769/// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default,
3073330770/// instead of silently failing when no x-axis alignment is provided,
3073430771/// and refactor this function to keep the code style consistent
0 commit comments