From 930c880fa691d0c313375d9ea31287d6d4d2d483 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Wed, 22 Jul 2020 08:04:48 +0200 Subject: [PATCH] Add option to disable virtual keyboard for LineEdit Co-authored-by: Alexander Holland (cherry picked from commit 0aa56e3ab8722217c2d377672aa73d67f10aabd0) --- doc/classes/LineEdit.xml | 3 +++ scene/gui/line_edit.cpp | 19 +++++++++++++++---- scene/gui/line_edit.h | 5 +++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index 09296fb624a..18065ee48d4 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -165,6 +165,9 @@ String value of the [LineEdit]. [b]Note:[/b] Changing text using this property won't emit the [signal text_changed] signal. + + If [code]true[/code], the native virtual keyboard is shown when focused on platforms that support it. + diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index d752979a118..01535396537 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -127,7 +127,7 @@ void LineEdit::_gui_input(Ref p_event) { selection.creating = false; selection.doubleclick = false; - if (OS::get_singleton()->has_virtual_keyboard()) { + if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) { if (selection.enabled) { OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length, selection.begin, selection.end); } else { @@ -323,7 +323,7 @@ void LineEdit::_gui_input(Ref p_event) { case KEY_ENTER: { emit_signal("text_entered", text); - if (OS::get_singleton()->has_virtual_keyboard()) + if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) OS::get_singleton()->hide_virtual_keyboard(); } break; @@ -930,7 +930,7 @@ void LineEdit::_notification(int p_what) { OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos2); } - if (OS::get_singleton()->has_virtual_keyboard()) { + if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) { if (selection.enabled) { OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length, selection.begin, selection.end); } else { @@ -949,7 +949,7 @@ void LineEdit::_notification(int p_what) { ime_text = ""; ime_selection = Point2(); - if (OS::get_singleton()->has_virtual_keyboard()) + if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) OS::get_singleton()->hide_virtual_keyboard(); } break; @@ -1667,6 +1667,14 @@ bool LineEdit::is_shortcut_keys_enabled() const { return shortcut_keys_enabled; } +void LineEdit::set_virtual_keyboard_enabled(bool p_enable) { + virtual_keyboard_enabled = p_enable; +} + +bool LineEdit::is_virtual_keyboard_enabled() const { + return virtual_keyboard_enabled; +} + void LineEdit::set_selecting_enabled(bool p_enabled) { selecting_enabled = p_enabled; @@ -1821,6 +1829,8 @@ void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("get_menu"), &LineEdit::get_menu); ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &LineEdit::set_context_menu_enabled); ClassDB::bind_method(D_METHOD("is_context_menu_enabled"), &LineEdit::is_context_menu_enabled); + ClassDB::bind_method(D_METHOD("set_virtual_keyboard_enabled", "enable"), &LineEdit::set_virtual_keyboard_enabled); + ClassDB::bind_method(D_METHOD("is_virtual_keyboard_enabled"), &LineEdit::is_virtual_keyboard_enabled); ClassDB::bind_method(D_METHOD("set_clear_button_enabled", "enable"), &LineEdit::set_clear_button_enabled); ClassDB::bind_method(D_METHOD("is_clear_button_enabled"), &LineEdit::is_clear_button_enabled); ClassDB::bind_method(D_METHOD("set_shortcut_keys_enabled", "enable"), &LineEdit::set_shortcut_keys_enabled); @@ -1856,6 +1866,7 @@ void LineEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "secret_character"), "set_secret_character", "get_secret_character"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_to_text_length"), "set_expand_to_text_length", "get_expand_to_text_length"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "virtual_keyboard_enabled"), "set_virtual_keyboard_enabled", "is_virtual_keyboard_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clear_button_enabled"), "set_clear_button_enabled", "is_clear_button_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled"); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 037238d6827..57f72459c9b 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -91,6 +91,8 @@ private: bool shortcut_keys_enabled; + bool virtual_keyboard_enabled = true; + Ref right_icon; struct Selection { @@ -229,6 +231,9 @@ public: void set_shortcut_keys_enabled(bool p_enabled); bool is_shortcut_keys_enabled() const; + void set_virtual_keyboard_enabled(bool p_enable); + bool is_virtual_keyboard_enabled() const; + void set_selecting_enabled(bool p_enabled); bool is_selecting_enabled() const;