-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Bug fixes and add feature: text edit wrap #819
base: master
Are you sure you want to change the base?
Conversation
Bug fixes and add new widget feature: text edit multiline auto wrap
i wonder who uses vertical tab '\v' these days |
Add feature: Multiline edit widget with automatic text wrap. Fix some bugs too.
Header after amalgama.
@@ -98,7 +98,7 @@ nk_edit_draw_text(struct nk_command_buffer *out, | |||
if (!glyph_len) return; | |||
while ((text_len < byte_len) && glyph_len) | |||
{ | |||
if (unicode == '\n') { | |||
if (unicode == '\n' || unicode == '\v') { | |||
/* new line separator so draw previous line */ |
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.
For edit auto wrap feature. Consider a vertical tab (\v) as a line break too.
@@ -421,7 +429,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||
selection_offset_end.x = row_size.x; | |||
select_end_ptr = text + text_len; | |||
} | |||
if (unicode == '\n') { | |||
if (unicode == '\n' || unicode == '\v') { | |||
text_size.x = NK_MAX(text_size.x, line_width); |
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.
For edit auto wrap feature. Consider a vertical tab (\v) as a line break too.
@@ -1078,7 +1078,7 @@ nk_text_calculate_text_bounds(const struct nk_user_font *font, | |||
|
|||
*glyphs = 0; | |||
while ((text_len < byte_len) && glyph_len) { | |||
if (unicode == '\n') { | |||
if (unicode == '\n' || unicode == '\v') { | |||
text_size.x = NK_MAX(text_size.x, line_width); |
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.
For edit auto wrap feature. Consider a vertical tab (\v) as a line break too.
nk_textedit_makeundo_insert(state, state->cursor, glyphs); | ||
state->cursor += len; | ||
state->cursor += glyphs; | ||
state->has_preferred_x = 0; |
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.
Bug fix: weird behavior on multibyte characters operations.
} | ||
NK_API int | ||
nk_str_insert_str_char(struct nk_str *str, int pos, const char *text) | ||
{ | ||
return nk_str_insert_text_utf8(str, pos, text, nk_strlen(text)); | ||
return nk_str_insert_text_char(str, pos, text, nk_strlen(text)); | ||
} |
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.
Bug fix: weird behavior on multibyte characters operations.
@@ -149,6 +149,7 @@ nk_nonblock_begin(struct nk_context *ctx, | |||
root->flags |= NK_WINDOW_REMOVE_ROM; | |||
root = root->parent; | |||
} | |||
win->popup.buf.active = is_active; | |||
return is_active; |
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.
Bug fix: combo boxes crashes program (points to invalid memory) in draw rotine.
win->edit.active = nk_false; | ||
} return ret_flags; | ||
} | ||
NK_API nk_flags | ||
nk_edit_string_zero_terminated(struct nk_context *ctx, nk_flags flags, | ||
char *buffer, int max, nk_plugin_filter filter) |
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.
Add feature: Multiline edit box with automatic text wrap.
@@ -468,7 +476,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, | |||
/* vertical scroll */ | |||
if (cursor_pos.y < edit->scrollbar.y) | |||
edit->scrollbar.y = NK_MAX(0.0f, cursor_pos.y - row_height); | |||
if (cursor_pos.y >= edit->scrollbar.y + area.h) | |||
if (cursor_pos.y >= edit->scrollbar.y + area.h - row_height) |
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.
Bug fix: text rendering out of clip box.
/* calculate clipping rectangle */ | ||
old_clip = out->clip; | ||
nk_unify(&clip, &old_clip, area.x, area.y, area.x + area.w, area.y + area.h); | ||
} | ||
if (edit->active) |
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.
Bug fix: text rendering out of clip box.
Done. Please verify if I made correctly. |
else tolerance = byte_len - text_len; /* tolerance until the string end */ | ||
if (tolerance > 3){ /* need to break */ | ||
if (last_spc){ /* if has a good point for break, use it */ | ||
nk_str_insert_text_char(&edit->string, last_spc + 1, "\v", 1); |
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.
@vurtun does something like this happen also on other places in the library?
IMHO we shall not allow this as we can't guarantee, that we'll put the string to it's original state once edited internally by Nuklear (because it's not distinguishable from a user made edition). It seems also not intuitive for the programmer to edit the string internally when the function itself is "just for visualisation" (this edition of "inserting \v
" is not done by user).
I can though understand, that such internal editions do make the code simpler. For that purpose we could consider something like a string view providing this "metainformation" about internally inserted/deleted characters, but not editing the underlying string unless it's a user made edition.
Bug fixes:
New widget feature: