Add option to disable virtual keyboard for LineEdit

Co-authored-by: Alexander Holland <alexander.holland@live.de>
(cherry picked from commit 0aa56e3ab8)
This commit is contained in:
PouleyKetchoupp 2020-07-22 08:04:48 +02:00 committed by Rémi Verschelde
parent 925371d08f
commit 930c880fa6
3 changed files with 23 additions and 4 deletions

View File

@ -165,6 +165,9 @@
String value of the [LineEdit]. String value of the [LineEdit].
[b]Note:[/b] Changing text using this property won't emit the [signal text_changed] signal. [b]Note:[/b] Changing text using this property won't emit the [signal text_changed] signal.
</member> </member>
<member name="virtual_keyboard_enabled" type="bool" setter="set_virtual_keyboard_enabled" getter="is_virtual_keyboard_enabled" default="true">
If [code]true[/code], the native virtual keyboard is shown when focused on platforms that support it.
</member>
</members> </members>
<signals> <signals>
<signal name="text_change_rejected"> <signal name="text_change_rejected">

View File

@ -127,7 +127,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
selection.creating = false; selection.creating = false;
selection.doubleclick = false; selection.doubleclick = false;
if (OS::get_singleton()->has_virtual_keyboard()) { if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) {
if (selection.enabled) { if (selection.enabled) {
OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length, selection.begin, selection.end); OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length, selection.begin, selection.end);
} else { } else {
@ -323,7 +323,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case KEY_ENTER: { case KEY_ENTER: {
emit_signal("text_entered", text); 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(); OS::get_singleton()->hide_virtual_keyboard();
} break; } break;
@ -930,7 +930,7 @@ void LineEdit::_notification(int p_what) {
OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos2); 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) { if (selection.enabled) {
OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length, selection.begin, selection.end); OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length, selection.begin, selection.end);
} else { } else {
@ -949,7 +949,7 @@ void LineEdit::_notification(int p_what) {
ime_text = ""; ime_text = "";
ime_selection = Point2(); 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(); OS::get_singleton()->hide_virtual_keyboard();
} break; } break;
@ -1667,6 +1667,14 @@ bool LineEdit::is_shortcut_keys_enabled() const {
return shortcut_keys_enabled; 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) { void LineEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = 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("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("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("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("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("is_clear_button_enabled"), &LineEdit::is_clear_button_enabled);
ClassDB::bind_method(D_METHOD("set_shortcut_keys_enabled", "enable"), &LineEdit::set_shortcut_keys_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::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, "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, "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, "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, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled");

View File

@ -91,6 +91,8 @@ private:
bool shortcut_keys_enabled; bool shortcut_keys_enabled;
bool virtual_keyboard_enabled = true;
Ref<Texture> right_icon; Ref<Texture> right_icon;
struct Selection { struct Selection {
@ -229,6 +231,9 @@ public:
void set_shortcut_keys_enabled(bool p_enabled); void set_shortcut_keys_enabled(bool p_enabled);
bool is_shortcut_keys_enabled() const; 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); void set_selecting_enabled(bool p_enabled);
bool is_selecting_enabled() const; bool is_selecting_enabled() const;