Exclude edit area text from inline color code to avoid cursor being in the wrong location

This commit is contained in:
JS Deck 2023-09-12 05:54:43 -03:00
parent c80d58717e
commit ec998c5ee2
3 changed files with 23 additions and 1 deletions

View File

@ -208,11 +208,11 @@ web_colors_preview(struct nk_context *ctx)
snprintf(text_count, NK_LEN(text_count), "%d/%d", field_len, (int)NK_LEN(field_buffer) - 1);
nk_label(ctx, text_count, NK_TEXT_RIGHT);
nk_draw_push_color_inline(ctx, NK_COLOR_INLINE_TAG);
nk_layout_row_dynamic(ctx, 30, 1);
nk_edit_string(ctx, NK_EDIT_SIMPLE, field_buffer, &field_len, NK_LEN(field_buffer), nk_filter_default);
nk_layout_row_dynamic(ctx, 150, 1);
nk_draw_push_color_inline(ctx, NK_COLOR_INLINE_TAG);
if (wrap_text)
nk_text_wrap(ctx, field_buffer, field_len);
else

View File

@ -27758,6 +27758,7 @@ nk_edit_draw_text(struct nk_command_buffer *out,
const char *line = text;
float line_offset = 0;
int line_count = 0;
enum nk_color_inline_type color_inline = NK_COLOR_INLINE_NONE;
struct nk_text txt;
txt.padding = nk_vec2(0,0);
@ -27766,6 +27767,12 @@ nk_edit_draw_text(struct nk_command_buffer *out,
glyph_len = nk_utf_decode(text+text_len, &unicode, byte_len-text_len);
if (!glyph_len) return;
if (out->draw_config) {
color_inline = out->draw_config->color_inline;
out->draw_config->color_inline = NK_COLOR_INLINE_NONE;
}
while ((text_len < byte_len) && glyph_len)
{
if (unicode == '\n') {
@ -27816,6 +27823,10 @@ nk_edit_draw_text(struct nk_command_buffer *out,
nk_fill_rect(out, label, 0, background);
nk_widget_text(out, label, line, (int)((text + text_len) - line),
&txt, NK_TEXT_LEFT, font);
}
if (out->draw_config) {
out->draw_config->color_inline = color_inline;
}}
}
NK_LIB nk_flags

View File

@ -88,6 +88,7 @@ nk_edit_draw_text(struct nk_command_buffer *out,
const char *line = text;
float line_offset = 0;
int line_count = 0;
enum nk_color_inline_type color_inline = NK_COLOR_INLINE_NONE;
struct nk_text txt;
txt.padding = nk_vec2(0,0);
@ -96,6 +97,12 @@ nk_edit_draw_text(struct nk_command_buffer *out,
glyph_len = nk_utf_decode(text+text_len, &unicode, byte_len-text_len);
if (!glyph_len) return;
if (out->draw_config) {
color_inline = out->draw_config->color_inline;
out->draw_config->color_inline = NK_COLOR_INLINE_NONE;
}
while ((text_len < byte_len) && glyph_len)
{
if (unicode == '\n') {
@ -146,6 +153,10 @@ nk_edit_draw_text(struct nk_command_buffer *out,
nk_fill_rect(out, label, 0, background);
nk_widget_text(out, label, line, (int)((text + text_len) - line),
&txt, NK_TEXT_LEFT, font);
}
if (out->draw_config) {
out->draw_config->color_inline = color_inline;
}}
}
NK_LIB nk_flags