From ca212ed1abfc5ee0fe41d6c8a53520f34d8a379e Mon Sep 17 00:00:00 2001 From: vurtun Date: Thu, 9 Jul 2015 13:50:10 +0200 Subject: [PATCH] fixed editbox glyph removing --- gui.c | 15 ++++++++++++++- gui.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 4e9f1f9..ef9a852 100644 --- a/gui.c +++ b/gui.c @@ -896,8 +896,21 @@ gui_edit_box_buffer_input(struct gui_edit_box *box, const struct gui_input *i) void gui_edit_box_remove(struct gui_edit_box *eb) { + gui_long unicode; + gui_size src_len = 0; + gui_size last_glyph = 0; + gui_size glyph_len = 0; + gui_char *text = gui_edit_box_get(eb); + gui_size text_len = gui_edit_box_len(eb); GUI_ASSERT(eb); - gui_edit_buffer_remove(&eb->buffer, 1); + + glyph_len = gui_utf_decode(text, &unicode, text_len); + while (glyph_len) { + src_len = src_len + glyph_len; + last_glyph = glyph_len; + glyph_len = gui_utf_decode(text + src_len, &unicode, text_len - src_len); + } + gui_edit_buffer_remove(&eb->buffer, last_glyph); } gui_char* diff --git a/gui.h b/gui.h index fc48d3b..dfa19b2 100644 --- a/gui.h +++ b/gui.h @@ -741,7 +741,7 @@ char *gui_edit_buffer_at(gui_edit_buffer*, gui_size pos); The Editbox first needs to be initialized either with a fixed size memory block or a allocator. After that it can be used by either the `gui_editobx` or `gui_panel_editbox` function. In addition symbols can be - added and removed with either `gui_edit_box_add` and `gui_edit_box_remove`. + added and removed with `gui_edit_box_add` and `gui_edit_box_remove`. Widget function API gui_edit_box_init() -- initialize a dynamically growing edit box