-
Notifications
You must be signed in to change notification settings - Fork 676
Introduce minimal API for text keyboard request with text area and cursor support #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PavelSharp
wants to merge
3
commits into
Immediate-Mode-UI:master
Choose a base branch
from
PavelSharp:feat-want_text_keyboard
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−9
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4917,6 +4917,11 @@ struct nk_keyboard { | |||||||
| struct nk_key keys[NK_KEY_MAX]; | ||||||||
| char text[NK_INPUT_MAX]; | ||||||||
| int text_len; | ||||||||
|
|
||||||||
| /*Text keyboard request system*/ | ||||||||
| nk_bool text_want; /*When true, text input is actively requested*/ | ||||||||
| struct nk_rect text_area; /*Input area (valid only when text_want == true)*/ | ||||||||
| struct nk_rect text_cursor; /*Cursor position (valid only when text_want == true)*/ | ||||||||
| }; | ||||||||
|
|
||||||||
| struct nk_input { | ||||||||
|
|
@@ -4941,6 +4946,10 @@ NK_API nk_bool nk_input_is_mouse_released(const struct nk_input*, enum nk_button | |||||||
| NK_API nk_bool nk_input_is_key_pressed(const struct nk_input*, enum nk_keys); | ||||||||
| NK_API nk_bool nk_input_is_key_released(const struct nk_input*, enum nk_keys); | ||||||||
| NK_API nk_bool nk_input_is_key_down(const struct nk_input*, enum nk_keys); | ||||||||
| /* This is a utility function that should be called inside a widget | ||||||||
| * to mark text keyboard for opening. | ||||||||
| * Returns true only on the first request each frame */ | ||||||||
| NK_API nk_bool nk_input_want_text_keyboard(struct nk_input*); | ||||||||
|
|
||||||||
| /* =============================================================== | ||||||||
| * | ||||||||
|
|
@@ -18199,6 +18208,10 @@ nk_input_begin(struct nk_context *ctx) | |||||||
| for (i = 0; i < NK_BUTTON_MAX; ++i) | ||||||||
| in->mouse.buttons[i].clicked = 0; | ||||||||
|
|
||||||||
| in->keyboard.text_want = nk_false; | ||||||||
| in->keyboard.text_area = nk_rect(0.0f, 0.0f, 0.0f, 0.0f); | ||||||||
| in->keyboard.text_cursor = nk_rect(0.0f, 0.0f, 0.0f, 0.0f); | ||||||||
|
|
||||||||
| in->keyboard.text_len = 0; | ||||||||
| in->mouse.scroll_delta = nk_vec2(0,0); | ||||||||
| in->mouse.prev.x = in->mouse.pos.x; | ||||||||
|
|
@@ -18469,7 +18482,15 @@ nk_input_is_key_down(const struct nk_input *i, enum nk_keys key) | |||||||
| if (k->down) return nk_true; | ||||||||
| return nk_false; | ||||||||
| } | ||||||||
|
|
||||||||
| NK_API nk_bool | ||||||||
| nk_input_want_text_keyboard(struct nk_input* i) | ||||||||
| { | ||||||||
| nk_bool ret; | ||||||||
| NK_ASSERT(i); | ||||||||
| ret = !i->keyboard.text_want; | ||||||||
| i->keyboard.text_want = nk_true; | ||||||||
| return ret; | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
|
|
||||||||
|
|
@@ -27997,6 +28018,9 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||||||
| char cursor_follow = 0; | ||||||||
| struct nk_rect old_clip; | ||||||||
| struct nk_rect clip; | ||||||||
| /*Variables for text keyboard(kb) support*/ | ||||||||
| nk_bool kb_text_want = nk_false; | ||||||||
| struct nk_rect kb_text_cursor = nk_rect(0.0f, 0.0f, 0.0f, 0.0f); | ||||||||
|
|
||||||||
| NK_ASSERT(state); | ||||||||
| NK_ASSERT(out); | ||||||||
|
|
@@ -28082,13 +28106,17 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||||||
| cursor_follow = nk_true; | ||||||||
| } | ||||||||
| } | ||||||||
| if (old_mode != edit->mode) { | ||||||||
| /* If mode changes and text keys are pressed in the same frame, | ||||||||
| * mode change takes priority (may transition to VIEW mode) */ | ||||||||
| if (old_mode != edit->mode) | ||||||||
| in->keyboard.text_len = 0; | ||||||||
| }} | ||||||||
| else if (edit->mode == NK_TEXT_EDIT_MODE_INSERT || edit->mode == NK_TEXT_EDIT_MODE_REPLACE) | ||||||||
| kb_text_want = nk_input_want_text_keyboard(in); | ||||||||
| } | ||||||||
|
|
||||||||
| /* text input */ | ||||||||
| edit->filter = filter; | ||||||||
| if (in->keyboard.text_len) { | ||||||||
| if (kb_text_want && in->keyboard.text_len) { | ||||||||
| nk_textedit_text(edit, in->keyboard.text, in->keyboard.text_len); | ||||||||
| cursor_follow = nk_true; | ||||||||
| in->keyboard.text_len = 0; | ||||||||
|
|
@@ -28407,12 +28435,23 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||||||
| row_height, font, background_color, text_color, nk_false); | ||||||||
| } | ||||||||
| if (edit->select_start != edit->select_end) { | ||||||||
| int glyph_len; | ||||||||
| nk_rune unicode; | ||||||||
|
|
||||||||
| /* draw selected text */ | ||||||||
| NK_ASSERT(select_begin_ptr); | ||||||||
| if (!select_end_ptr) { | ||||||||
| const char *begin = nk_str_get_const(&edit->string); | ||||||||
| select_end_ptr = begin + nk_str_len_char(&edit->string); | ||||||||
| } | ||||||||
|
|
||||||||
| glyph_len = nk_utf_decode(select_begin_ptr, &unicode, (int)(select_end_ptr - select_begin_ptr)); | ||||||||
| /* In this case, we set the cursor to the first selected character */ | ||||||||
| kb_text_cursor = nk_rect( | ||||||||
| area.x + selection_offset_start.x - edit->scrollbar.x, | ||||||||
| area.y + selection_offset_start.y - edit->scrollbar.y, | ||||||||
| font->width(font->userdata, font->height, select_begin_ptr, glyph_len), row_height); | ||||||||
|
|
||||||||
| nk_edit_draw_text(out, style, | ||||||||
| area.x - edit->scrollbar.x, | ||||||||
| area.y + selection_offset_start.y - edit->scrollbar.y, | ||||||||
|
|
@@ -28449,6 +28488,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||||||
| cursor.x = area.x + cursor_pos.x - edit->scrollbar.x; | ||||||||
| cursor.y = area.y + cursor_pos.y + row_height/2.0f - cursor.h/2.0f; | ||||||||
| cursor.y -= edit->scrollbar.y; | ||||||||
| kb_text_cursor = cursor; | ||||||||
| nk_fill_rect(out, cursor, 0, cursor_color); | ||||||||
| } else { | ||||||||
| /* draw cursor inside text */ | ||||||||
|
|
@@ -28468,6 +28508,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||||||
| txt.padding = nk_vec2(0,0); | ||||||||
| txt.background = cursor_color;; | ||||||||
| txt.text = cursor_text_color; | ||||||||
| kb_text_cursor = label; | ||||||||
| nk_fill_rect(out, label, 0, cursor_color); | ||||||||
| nk_widget_text(out, label, cursor_ptr, glyph_len, &txt, NK_TEXT_LEFT, font); | ||||||||
| } | ||||||||
|
|
@@ -28504,6 +28545,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||||||
| background_color, text_color, nk_false); | ||||||||
| } | ||||||||
| nk_push_scissor(out, old_clip);} | ||||||||
| if (kb_text_want) { | ||||||||
| NK_ASSERT(in); | ||||||||
| in->keyboard.text_cursor = kb_text_cursor; | ||||||||
| in->keyboard.text_area = clip; | ||||||||
| } | ||||||||
| return ret; | ||||||||
| } | ||||||||
| NK_API void | ||||||||
|
|
@@ -30729,6 +30775,9 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) | |||||||
| /// - [y]: Minor version with non-breaking API and library changes | ||||||||
| /// - [z]: Patch version with no direct changes to the API | ||||||||
| /// | ||||||||
| /// - 2025/11/13 (4.13.0) - Introduced minimal text keyboard request API (nk_input_want_text_keyboard) | ||||||||
| /// with support for text input area and cursor position. | ||||||||
| /// This functionality is required for SDL_SetTextInputRect | ||||||||
|
Comment on lines
+30778
to
+30780
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| /// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default, | ||||||||
| /// instead of silently failing when no x-axis alignment is provided, | ||||||||
| /// and refactor this function to keep the code style consistent | ||||||||
|
|
||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,9 @@ | |||||||
| /// - [y]: Minor version with non-breaking API and library changes | ||||||||
| /// - [z]: Patch version with no direct changes to the API | ||||||||
| /// | ||||||||
| /// - 2025/11/13 (4.13.0) - Introduced minimal text keyboard request API (nk_input_want_text_keyboard) | ||||||||
| /// with support for text input area and cursor position. | ||||||||
| /// This functionality is required for SDL_SetTextInputRect | ||||||||
|
Comment on lines
+10
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll avoid the changelog going forwards to avoid conflicts
Suggested change
|
||||||||
| /// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default, | ||||||||
| /// instead of silently failing when no x-axis alignment is provided, | ||||||||
| /// and refactor this function to keep the code style consistent | ||||||||
|
|
||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.