From 682c9b180231c34d96e8130fd7cfa65155d2d86a Mon Sep 17 00:00:00 2001 From: lixianjing Date: Sun, 11 Oct 2020 09:08:32 +0800 Subject: [PATCH] if keyboard is not overlap edit, do not push window --- docs/changes.md | 3 ++- src/input_methods/input_method_default.inc | 31 +++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index a7a87bcc3..9308143df 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,7 +2,8 @@ 2020/10/11 * label 增加 line\_wrap 属性。 - + * 完善输入法。如果 keyboard 与 edit 没有重叠,不再上推窗口。 + 2020/10/10 * window\_manager\_back 支持 overlay 和 popup。 * 完善 API 注释(感谢兆坤提供补丁)。 diff --git a/src/input_methods/input_method_default.inc b/src/input_methods/input_method_default.inc index 4ec3cdcaa..6d6fc69ae 100644 --- a/src/input_methods/input_method_default.inc +++ b/src/input_methods/input_method_default.inc @@ -146,7 +146,7 @@ static ret_t input_method_on_win_close(void* ctx, event_t* e) { widget_get_prop(im->keyboard, WIDGET_PROP_CLOSE_ANIM_HINT, &v); if (im->idle_close_id == TK_INVALID_ID) { window_close_force(im->keyboard); - + im->keyboard = NULL; im->widget = NULL; im->win = NULL; @@ -163,6 +163,21 @@ static ret_t input_method_default_on_keyboard_open(void* ctx, event_t* e) { return RET_REMOVE; } +static bool_t is_key_board_overlap_edit(widget_t* keyboard, widget_t* edit) { + point_t p = {0, 0}; + widget_to_screen(edit, &p); + + if (p.x > keyboard->x && p.x < (keyboard->x + keyboard->w)) { + return TRUE; + } + + if (keyboard->x > p.x && keyboard->x < (p.x + edit->w)) { + return TRUE; + } + + return FALSE; +} + static ret_t input_type_open_keyboard(input_method_t* im, const char* keyboard_name, bool_t open_anim) { value_t v; @@ -189,13 +204,17 @@ static ret_t input_type_open_keyboard(input_method_t* im, const char* keyboard_n widget_on(im->keyboard, EVT_DESTROY, input_method_default_on_keyboard_destroy, im); if ((p.y + widget->h) > im->keyboard->y) { - close_anim_hint = "vtranslate"; - open_anim_hint = close_anim_hint; - im->win = win; - im->win_delta_y = win->y + win->h - im->keyboard->y; + if (is_key_board_overlap_edit(widget, im->keyboard)) { + im->win_delta_y = win->y + win->h - im->keyboard->y; + close_anim_hint = "vtranslate"; + } else { + im->win_delta_y = 0; + close_anim_hint = "popup"; + } + open_anim_hint = close_anim_hint; widget_on(im->keyboard, EVT_WINDOW_OPEN, on_push_window, im); - } else if (win->y + win->h < im->keyboard->y) { + } else if ((win->y + win->h) < im->keyboard->y) { /*when new keyboard height is not eq old keyboard height*/ close_anim_hint = "vtranslate"; im->win_delta_y += win->y + win->h - im->keyboard->y;