diff --git a/esp32/modules/dialogs.py b/esp32/modules/dialogs.py index 371cdad5b..b45a0827a 100644 --- a/esp32/modules/dialogs.py +++ b/esp32/modules/dialogs.py @@ -90,18 +90,8 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back", ugfx.set_default_font(font) label = ugfx.Label(5, 1, int(width*4/5), height-kb_height-5-edit_height-5, description, parent=window) - def vkey_pressed(key): - new_text = edit.text() + key - edit.text(new_text) - edit.cursor_pos(len(new_text)) - edit.text(new_text) - ugfx.flush() - def vkey_backspace(): - new_text = edit.text()[:-1] - edit.text(new_text) - edit.cursor_pos(len(new_text)) - edit.text(new_text) + edit.backspace() ugfx.flush() focus = 0 @@ -111,10 +101,8 @@ def toggle_focus(pressed): if focus == 0: edit.set_focus() kb.enabled(1) - # Do we manually have to transfer keypresses to the editbox? - print("attaching") ugfx.input_attach(ugfx.BTN_B, lambda pressed: vkey_backspace() if pressed else 0) - ugfx.input_attach(ugfx.BTN_A, lambda pressed: vkey_pressed(kb.selected_key()) if pressed else 0) + ugfx.input_attach(ugfx.BTN_A, lambda pressed: 0 if pressed else ugfx.flush()) focus = 1 elif focus == 1 or not button_no: button_yes.set_focus() diff --git a/esp32/ugfx_widgets.c b/esp32/ugfx_widgets.c index 25ef71438..caf9b5e6b 100644 --- a/esp32/ugfx_widgets.c +++ b/esp32/ugfx_widgets.c @@ -429,6 +429,18 @@ STATIC mp_obj_t ugfx_textbox_cursor_pos(mp_uint_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ugfx_textbox_cursor_pos_obj, 1, 2, ugfx_textbox_cursor_pos); +/// \method backspace() +/// +/// removes the character before the cursor +STATIC mp_obj_t ugfx_textbox_backspace(mp_obj_t self_in) { + ugfx_textbox_obj_t *self = self_in; + + gwinTexteditBackspace(self->ghTextbox); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(ugfx_textbox_backspace_obj, ugfx_textbox_backspace); + /// \method destroy() /// /// frees up all resources @@ -447,6 +459,7 @@ STATIC const mp_map_elem_t ugfx_textbox_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_destroy), (mp_obj_t)&ugfx_textbox_destroy_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&ugfx_textbox_destroy_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_cursor_pos), (mp_obj_t)&ugfx_textbox_cursor_pos_obj}, + { MP_OBJ_NEW_QSTR(MP_QSTR_backspace), (mp_obj_t)&ugfx_textbox_backspace_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_visible), (mp_obj_t)&ugfx_widget_visible_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_attach_input), (mp_obj_t)&ugfx_widget_attach_input_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_detach_input), (mp_obj_t)&ugfx_widget_detach_input_obj },