From bef485ad8159d79b9ea7a31aa41450fc995f5724 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 10 Nov 2020 22:03:55 +0100 Subject: Added backspace support --- libgui/gui.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'libgui/gui.c') diff --git a/libgui/gui.c b/libgui/gui.c index 7a47bc9..fe78883 100644 --- a/libgui/gui.c +++ b/libgui/gui.c @@ -332,17 +332,23 @@ void gui_event_loop(struct element *container) case GUI_KEYBOARD: { struct gui_event_keyboard *event = msg->data; - if (focused && focused->type == GUI_TYPE_TEXT_INPUT && event->press && - event->ch && event->ch >= ' ') { + if (focused && focused->type == GUI_TYPE_TEXT_INPUT && event->press) { char *s = ((struct element_text_input *)focused->data)->text; u32 l = strlen(s); - if (l >= MAX_INPUT_LENGTH) - continue; - s[l] = event->ch; - s[l + 1] = '\0'; - gui_sync_text_input(focused); - merge_elements(get_root(focused->window_id)); - gfx_redraw_focused(); + if (event->ch >= ' ') { + if (l >= MAX_INPUT_LENGTH) + continue; + s[l] = event->ch; + s[l + 1] = '\0'; + gui_sync_text_input(focused); + merge_elements(get_root(focused->window_id)); + gfx_redraw_focused(); + } else if (event->scancode == KEY_BACKSPACE && l > 0) { + s[l - 1] = '\0'; + gui_sync_text_input(focused); + merge_elements(get_root(focused->window_id)); + gfx_redraw_focused(); + } } if (focused && focused->event.on_submit && event->press && -- cgit v1.2.3