Skip to content

Commit 9236b92

Browse files
lundriltrace32
authored andcommitted
fix nk_do_edit: Keep scroll position when re-activating edit widget.
How to test: Construct two edit widgets. Enter a long text into the first edit widget, so that the widget autoscrolls. Click into second (still empty) edit widget. Click into first edit widget again. => Text jums back, so that first character of text in first edit widget is visible again. This patch keeps the scroll position of the edit widget constant.
1 parent 363c2ac commit 9236b92

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

nuklear.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26535,7 +26535,10 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2653526535
if (!prev_state && edit->active) {
2653626536
const enum nk_text_edit_type type = (flags & NK_EDIT_MULTILINE) ?
2653726537
NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE;
26538+
/* keep scroll position when re-activating edit widget */
26539+
struct nk_vec2 oldscrollbar = edit->scrollbar;
2653826540
nk_textedit_clear_state(edit, type, filter);
26541+
edit->scrollbar = oldscrollbar;
2653926542
if (flags & NK_EDIT_AUTO_SELECT)
2654026543
select_all = nk_true;
2654126544
if (flags & NK_EDIT_GOTO_END_ON_ACTIVATE) {
@@ -29094,6 +29097,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
2909429097
/// - [yy]: Minor version with non-breaking API and library changes
2909529098
/// - [zz]: Bug fix version with no direct changes to API
2909629099
///
29100+
/// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
2909729101
/// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug
2909829102
/// - 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS
2909929103
/// - 2020/04/30 (4.02.2) - Fix nk_edit border drawing bug

package.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.02.4",
3+
"version": "4.02.5",
44
"repo": "Immediate-Mode-UI/Nuklear",
55
"description": "A small ANSI C gui toolkit",
66
"keywords": ["gl", "ui", "toolkit"],

src/CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/// - [yy]: Minor version with non-breaking API and library changes
99
/// - [zz]: Bug fix version with no direct changes to API
1010
///
11+
/// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
1112
/// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug
1213
/// - 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS
1314
/// - 2020/04/30 (4.02.2) - Fix nk_edit border drawing bug

src/nuklear_edit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
195195
if (!prev_state && edit->active) {
196196
const enum nk_text_edit_type type = (flags & NK_EDIT_MULTILINE) ?
197197
NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE;
198+
/* keep scroll position when re-activating edit widget */
199+
struct nk_vec2 oldscrollbar = edit->scrollbar;
198200
nk_textedit_clear_state(edit, type, filter);
201+
edit->scrollbar = oldscrollbar;
199202
if (flags & NK_EDIT_AUTO_SELECT)
200203
select_all = nk_true;
201204
if (flags & NK_EDIT_GOTO_END_ON_ACTIVATE) {

0 commit comments

Comments
 (0)