Skip to content

Commit 9efc7fe

Browse files
committed
Update CHANGELOG and Rebuild nuklear.h
1 parent 5a8af88 commit 9efc7fe

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

clib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuklear",
3-
"version": "4.12.8",
3+
"version": "4.13.0",
44
"repo": "Immediate-Mode-UI/Nuklear",
55
"description": "A small ANSI C gui toolkit",
66
"keywords": ["gl", "ui", "toolkit"],

nuklear.h

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

49224927
struct nk_input {
@@ -4941,6 +4946,10 @@ NK_API nk_bool nk_input_is_mouse_released(const struct nk_input*, enum nk_button
49414946
NK_API nk_bool nk_input_is_key_pressed(const struct nk_input*, enum nk_keys);
49424947
NK_API nk_bool nk_input_is_key_released(const struct nk_input*, enum nk_keys);
49434948
NK_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,15 @@ 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_bool ret;
18489+
NK_ASSERT(i);
18490+
ret = !i->keyboard.text_want;
18491+
i->keyboard.text_want = nk_true;
18492+
return ret;
18493+
}
1847318494

1847418495

1847518496

@@ -27997,6 +28018,9 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2799728018
char cursor_follow = 0;
2799828019
struct nk_rect old_clip;
2799928020
struct nk_rect clip;
28021+
/*Variables for text keyboard(kb) support*/
28022+
nk_bool kb_text_want = nk_false;
28023+
struct nk_rect kb_text_cursor = nk_rect(0.0f, 0.0f, 0.0f, 0.0f);
2800028024

2800128025
NK_ASSERT(state);
2800228026
NK_ASSERT(out);
@@ -28082,13 +28106,17 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2808228106
cursor_follow = nk_true;
2808328107
}
2808428108
}
28085-
if (old_mode != edit->mode) {
28109+
/* If mode changes and text keys are pressed in the same frame,
28110+
* mode change takes priority (may transition to VIEW mode) */
28111+
if (old_mode != edit->mode)
2808628112
in->keyboard.text_len = 0;
28087-
}}
28113+
else if (edit->mode == NK_TEXT_EDIT_MODE_INSERT || edit->mode == NK_TEXT_EDIT_MODE_REPLACE)
28114+
kb_text_want = nk_input_want_text_keyboard(in);
28115+
}
2808828116

2808928117
/* text input */
2809028118
edit->filter = filter;
28091-
if (in->keyboard.text_len) {
28119+
if (kb_text_want && in->keyboard.text_len) {
2809228120
nk_textedit_text(edit, in->keyboard.text, in->keyboard.text_len);
2809328121
cursor_follow = nk_true;
2809428122
in->keyboard.text_len = 0;
@@ -28407,12 +28435,23 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2840728435
row_height, font, background_color, text_color, nk_false);
2840828436
}
2840928437
if (edit->select_start != edit->select_end) {
28438+
int glyph_len;
28439+
nk_rune unicode;
28440+
2841028441
/* draw selected text */
2841128442
NK_ASSERT(select_begin_ptr);
2841228443
if (!select_end_ptr) {
2841328444
const char *begin = nk_str_get_const(&edit->string);
2841428445
select_end_ptr = begin + nk_str_len_char(&edit->string);
2841528446
}
28447+
28448+
glyph_len = nk_utf_decode(select_begin_ptr, &unicode, (int)(select_end_ptr - select_begin_ptr));
28449+
/* In this case, we set the cursor to the first selected character */
28450+
kb_text_cursor = nk_rect(
28451+
area.x + selection_offset_start.x - edit->scrollbar.x,
28452+
area.y + selection_offset_start.y - edit->scrollbar.y,
28453+
font->width(font->userdata, font->height, select_begin_ptr, glyph_len), row_height);
28454+
2841628455
nk_edit_draw_text(out, style,
2841728456
area.x - edit->scrollbar.x,
2841828457
area.y + selection_offset_start.y - edit->scrollbar.y,
@@ -28449,6 +28488,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2844928488
cursor.x = area.x + cursor_pos.x - edit->scrollbar.x;
2845028489
cursor.y = area.y + cursor_pos.y + row_height/2.0f - cursor.h/2.0f;
2845128490
cursor.y -= edit->scrollbar.y;
28491+
kb_text_cursor = cursor;
2845228492
nk_fill_rect(out, cursor, 0, cursor_color);
2845328493
} else {
2845428494
/* draw cursor inside text */
@@ -28468,6 +28508,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2846828508
txt.padding = nk_vec2(0,0);
2846928509
txt.background = cursor_color;;
2847028510
txt.text = cursor_text_color;
28511+
kb_text_cursor = label;
2847128512
nk_fill_rect(out, label, 0, cursor_color);
2847228513
nk_widget_text(out, label, cursor_ptr, glyph_len, &txt, NK_TEXT_LEFT, font);
2847328514
}
@@ -28504,6 +28545,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2850428545
background_color, text_color, nk_false);
2850528546
}
2850628547
nk_push_scissor(out, old_clip);}
28548+
if (kb_text_want) {
28549+
NK_ASSERT(in);
28550+
in->keyboard.text_cursor = kb_text_cursor;
28551+
in->keyboard.text_area = clip;
28552+
}
2850728553
return ret;
2850828554
}
2850928555
NK_API void
@@ -30729,6 +30775,9 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
3072930775
/// - [y]: Minor version with non-breaking API and library changes
3073030776
/// - [z]: Patch version with no direct changes to the API
3073130777
///
30778+
/// - 2025/11/13 (4.13.0) - Introduced minimal text keyboard request API (nk_input_want_text_keyboard)
30779+
/// with support for text input area and cursor position.
30780+
/// This functionality is required for SDL_SetTextInputRect
3073230781
/// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default,
3073330782
/// instead of silently failing when no x-axis alignment is provided,
3073430783
/// and refactor this function to keep the code style consistent

src/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/// - [y]: Minor version with non-breaking API and library changes
88
/// - [z]: Patch version with no direct changes to the API
99
///
10+
/// - 2025/11/13 (4.13.0) - Introduced minimal text keyboard request API (nk_input_want_text_keyboard)
11+
/// with support for text input area and cursor position.
12+
/// This functionality is required for SDL_SetTextInputRect
1013
/// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default,
1114
/// instead of silently failing when no x-axis alignment is provided,
1215
/// and refactor this function to keep the code style consistent

0 commit comments

Comments
 (0)