aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-11-10 22:03:55 +0100
committerMarvin Borner2020-11-10 22:03:55 +0100
commitbef485ad8159d79b9ea7a31aa41450fc995f5724 (patch)
tree4d5958175c4e21469bab8aea38e9baf9bf775f25
parent2c9c650c70a0622a2097105745eaba52e9170dd1 (diff)
Added backspace support
-rw-r--r--libgui/gui.c24
1 files changed, 15 insertions, 9 deletions
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 &&