Ported: Add support for multiple virtual keyboard types - brianwinterpixel

ce24b48e50
This commit is contained in:
Relintai 2022-08-19 16:18:53 +02:00
parent 1cab11a1c1
commit 58da70524b
23 changed files with 855 additions and 605 deletions

View File

@ -30,6 +30,7 @@
#include "core_bind.h"
#include "core/config/project_settings.h"
#include "core/crypto/crypto_core.h"
#include "core/io/file_access_compressed.h"
#include "core/io/file_access_encrypted.h"
@ -39,7 +40,6 @@
#include "core/object/method_bind_ext.gen.inc"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/config/project_settings.h"
/**
* Time constants borrowed from loc_time.h
@ -1086,8 +1086,8 @@ bool _OS::has_virtual_keyboard() const {
return OS::get_singleton()->has_virtual_keyboard();
}
void _OS::show_virtual_keyboard(const String &p_existing_text, bool p_multiline) {
OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2(), p_multiline);
void _OS::show_virtual_keyboard(const String &p_existing_text, _OS::VirtualKeyboardType p_type) {
OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2(), OS::VirtualKeyboardType(p_type));
}
void _OS::hide_virtual_keyboard() {
@ -1403,7 +1403,8 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("dump_memory_to_file", "file"), &_OS::dump_memory_to_file);
ClassDB::bind_method(D_METHOD("dump_resources_to_file", "file"), &_OS::dump_resources_to_file);
ClassDB::bind_method(D_METHOD("has_virtual_keyboard"), &_OS::has_virtual_keyboard);
ClassDB::bind_method(D_METHOD("show_virtual_keyboard", "existing_text", "multiline"), &_OS::show_virtual_keyboard, DEFVAL(""), DEFVAL(false));
ClassDB::bind_method(D_METHOD("show_virtual_keyboard", "existing_text", "multiline"), &_OS::_show_virtual_keyboard, DEFVAL(""), DEFVAL(false));
ClassDB::bind_method(D_METHOD("show_virtual_keyboard_type", "existing_text", "type"), &_OS::show_virtual_keyboard, DEFVAL(""), DEFVAL(_OS::KEYBOARD_TYPE_DEFAULT));
ClassDB::bind_method(D_METHOD("hide_virtual_keyboard"), &_OS::hide_virtual_keyboard);
ClassDB::bind_method(D_METHOD("get_virtual_keyboard_height"), &_OS::get_virtual_keyboard_height);
ClassDB::bind_method(D_METHOD("print_resources_in_use", "short"), &_OS::print_resources_in_use, DEFVAL(false));
@ -1553,6 +1554,15 @@ void _OS::_bind_methods() {
BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR_PORTRAIT);
BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_DEFAULT);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_MULTILINE);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER_DECIMAL);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PHONE);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_EMAIL_ADDRESS);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PASSWORD);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_URL);
BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);

View File

@ -30,16 +30,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "core/io/image.h"
#include "core/io/compression.h"
#include "core/io/image.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "core/os/safe_refcount.h"
#include "core/os/semaphore.h"
#include "core/os/thread.h"
#include "core/os/safe_refcount.h"
class _ResourceLoader : public Object {
GDCLASS(_ResourceLoader, Object);
@ -272,8 +272,23 @@ public:
void dump_memory_to_file(const String &p_file);
void dump_resources_to_file(const String &p_file);
enum VirtualKeyboardType {
KEYBOARD_TYPE_DEFAULT,
KEYBOARD_TYPE_MULTILINE,
KEYBOARD_TYPE_NUMBER,
KEYBOARD_TYPE_NUMBER_DECIMAL,
KEYBOARD_TYPE_PHONE,
KEYBOARD_TYPE_EMAIL_ADDRESS,
KEYBOARD_TYPE_PASSWORD,
KEYBOARD_TYPE_URL
};
void _show_virtual_keyboard(const String &p_existing_text = "", bool p_multiline = false) {
show_virtual_keyboard(p_existing_text, p_multiline ? KEYBOARD_TYPE_MULTILINE : KEYBOARD_TYPE_DEFAULT);
}
bool has_virtual_keyboard() const;
void show_virtual_keyboard(const String &p_existing_text = "", bool p_multiline = false);
void show_virtual_keyboard(const String &p_existing_text = "", VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT);
void hide_virtual_keyboard();
int get_virtual_keyboard_height();
@ -408,6 +423,7 @@ VARIANT_ENUM_CAST(_OS::VideoDriver);
VARIANT_ENUM_CAST(_OS::PowerState);
VARIANT_ENUM_CAST(_OS::Weekday);
VARIANT_ENUM_CAST(_OS::Month);
VARIANT_ENUM_CAST(_OS::VirtualKeyboardType);
VARIANT_ENUM_CAST(_OS::SystemDir);
VARIANT_ENUM_CAST(_OS::ScreenOrientation);
VARIANT_ENUM_CAST(_OS::HandleType);

View File

@ -337,7 +337,7 @@ bool OS::has_virtual_keyboard() const {
return false;
}
void OS::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
void OS::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
}
void OS::hide_virtual_keyboard() {

View File

@ -31,12 +31,12 @@
/*************************************************************************/
#include "core/config/engine.h"
#include "core/containers/list.h"
#include "core/containers/vector.h"
#include "core/io/image.h"
#include "core/io/logger.h"
#include "core/containers/list.h"
#include "core/os/main_loop.h"
#include "core/string/ustring.h"
#include "core/containers/vector.h"
#include <stdarg.h>
#include <stdlib.h>
@ -449,8 +449,19 @@ public:
CURSOR_MAX
};
enum VirtualKeyboardType {
KEYBOARD_TYPE_DEFAULT,
KEYBOARD_TYPE_MULTILINE,
KEYBOARD_TYPE_NUMBER,
KEYBOARD_TYPE_NUMBER_DECIMAL,
KEYBOARD_TYPE_PHONE,
KEYBOARD_TYPE_EMAIL_ADDRESS,
KEYBOARD_TYPE_PASSWORD,
KEYBOARD_TYPE_URL
};
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void hide_virtual_keyboard();
// returns height of the currently shown virtual keyboard (0 if keyboard is hidden)

View File

@ -192,6 +192,9 @@
<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>
<member name="virtual_keyboard_type" type="int" setter="set_virtual_keyboard_type" getter="get_virtual_keyboard_type" enum="LineEdit.VirtualKeyboardType" default="0">
Specifies the type of virtual keyboard to show.
</member>
</members>
<signals>
<signal name="text_change_rejected">
@ -251,6 +254,31 @@
<constant name="MENU_MAX" value="7" enum="MenuItems">
Represents the size of the [enum MenuItems] enum.
</constant>
<constant name="KEYBOARD_TYPE_DEFAULT" value="0" enum="VirtualKeyboardType">
Default text virtual keyboard.
</constant>
<constant name="KEYBOARD_TYPE_MULTILINE" value="1" enum="VirtualKeyboardType">
Multiline virtual keyboard.
</constant>
<constant name="KEYBOARD_TYPE_NUMBER" value="2" enum="VirtualKeyboardType">
Virtual number keypad, useful for PIN entry.
</constant>
<constant name="KEYBOARD_TYPE_NUMBER_DECIMAL" value="3" enum="VirtualKeyboardType">
Virtual number keypad, useful for entering fractional numbers.
</constant>
<constant name="KEYBOARD_TYPE_PHONE" value="4" enum="VirtualKeyboardType">
Virtual phone number keypad.
</constant>
<constant name="KEYBOARD_TYPE_EMAIL_ADDRESS" value="5" enum="VirtualKeyboardType">
Virtual keyboard with additional keys to assist with typing email addresses.
</constant>
<constant name="KEYBOARD_TYPE_PASSWORD" value="6" enum="VirtualKeyboardType">
Virtual keyboard for entering a password. On most platforms, this should disable autocomplete and autocapitalization.
[b]Note:[/b] This is not supported on HTML5 or below iOS version 11.0. Instead, this will behave identically to [constant KEYBOARD_TYPE_DEFAULT].
</constant>
<constant name="KEYBOARD_TYPE_URL" value="7" enum="VirtualKeyboardType">
Virtual keyboard with additional keys to assist with typing URLs.
</constant>
</constants>
<theme_items>
<theme_item name="clear_button_color" data_type="color" type="Color" default="Color( 0.88, 0.88, 0.88, 1 )">

View File

@ -1017,7 +1017,19 @@
Shows the virtual keyboard if the platform has one.
The [code]existing_text[/code] parameter is useful for implementing your own [LineEdit] or [TextEdit], as it tells the virtual keyboard what text has already been typed (the virtual keyboard uses it for auto-correct and predictions).
The [code]multiline[/code] parameter needs to be set to [code]true[/code] to be able to enter multiple lines of text, as in [TextEdit].
[b]Note:[/b] This method is implemented on Android, iOS and UWP.
[b]Note:[/b] This method is equivalent to calling [method show_virtual_keyboard_type] with either default or multiline keyboard type. It is kept for compatibility with previous Godot releases and should be considered [i]deprecated[/i] and replaced by [method show_virtual_keyboard_type].
[b]Note:[/b] This method is implemented on Android, iOS, UWP, and HTML5.
</description>
</method>
<method name="show_virtual_keyboard_type">
<return type="void" />
<argument index="0" name="existing_text" type="String" default="&quot;&quot;" />
<argument index="1" name="type" type="int" enum="OS.VirtualKeyboardType" default="0" />
<description>
Shows the virtual keyboard if the platform has one.
The [code]existing_text[/code] parameter is useful for implementing your own [LineEdit] or [TextEdit], as it tells the virtual keyboard what text has already been typed (the virtual keyboard uses it for auto-correct and predictions).
The [code]type[/code] parameter allows selecting which virtual keyboard to show.
[b]Note:[/b] This method is implemented on Android, iOS, UWP, and HTML5.
</description>
</method>
</methods>
@ -1204,6 +1216,31 @@
<constant name="SCREEN_ORIENTATION_SENSOR" value="6" enum="ScreenOrientation">
Uses most suitable orientation based on the hardware sensor.
</constant>
<constant name="KEYBOARD_TYPE_DEFAULT" value="0" enum="VirtualKeyboardType">
Default text virtual keyboard.
</constant>
<constant name="KEYBOARD_TYPE_MULTILINE" value="1" enum="VirtualKeyboardType">
Multiline virtual keyboard.
</constant>
<constant name="KEYBOARD_TYPE_NUMBER" value="2" enum="VirtualKeyboardType">
Virtual number keypad, useful for PIN entry.
</constant>
<constant name="KEYBOARD_TYPE_NUMBER_DECIMAL" value="3" enum="VirtualKeyboardType">
Virtual number keypad, useful for entering fractional numbers.
</constant>
<constant name="KEYBOARD_TYPE_PHONE" value="4" enum="VirtualKeyboardType">
Virtual phone number keypad.
</constant>
<constant name="KEYBOARD_TYPE_EMAIL_ADDRESS" value="5" enum="VirtualKeyboardType">
Virtual keyboard with additional keys to assist with typing email addresses.
</constant>
<constant name="KEYBOARD_TYPE_PASSWORD" value="6" enum="VirtualKeyboardType">
Virtual keyboard for entering a password. On most platforms, this should disable autocomplete and autocapitalization.
[b]Note:[/b] This is not supported on HTML5 or below iOS version 11.0. Instead, this will behave identically to [constant KEYBOARD_TYPE_DEFAULT].
</constant>
<constant name="KEYBOARD_TYPE_URL" value="7" enum="VirtualKeyboardType">
Virtual keyboard with additional keys to assist with typing URLs.
</constant>
<constant name="SYSTEM_DIR_DESKTOP" value="0" enum="SystemDir">
Desktop directory path.
</constant>

View File

@ -203,9 +203,10 @@ public class PandemoniumIO {
return result;
}
public void showKeyboard(String p_existing_text, boolean p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
if (edit != null)
edit.showKeyboard(p_existing_text, p_multiline, p_max_input_length, p_cursor_start, p_cursor_end);
public void showKeyboard(String p_existing_text, int p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
if (edit != null) {
edit.showKeyboard(p_existing_text, GodotEditText.VirtualKeyboardType.values()[p_type], p_max_input_length, p_cursor_start, p_cursor_end);
}
//InputMethodManager inputMgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
//inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

View File

@ -52,6 +52,18 @@ public class PandemoniumEditText extends EditText {
private final static int HANDLER_OPEN_IME_KEYBOARD = 2;
private final static int HANDLER_CLOSE_IME_KEYBOARD = 3;
// Enum must be kept up-to-date with OS::VirtualKeyboardType
public enum VirtualKeyboardType {
KEYBOARD_TYPE_DEFAULT,
KEYBOARD_TYPE_MULTILINE,
KEYBOARD_TYPE_NUMBER,
KEYBOARD_TYPE_NUMBER_DECIMAL,
KEYBOARD_TYPE_PHONE,
KEYBOARD_TYPE_EMAIL_ADDRESS,
KEYBOARD_TYPE_PASSWORD,
KEYBOARD_TYPE_URL
}
// ===========================================================
// Fields
// ===========================================================
@ -60,7 +72,7 @@ public class PandemoniumEditText extends EditText {
private EditHandler sHandler = new EditHandler(this);
private String mOriginText;
private int mMaxInputLength = Integer.MAX_VALUE;
private boolean mMultiline = false;
private VirtualKeyboardType mKeyboardType = VirtualKeyboardType.KEYBOARD_TYPE_DEFAULT;
private static class EditHandler extends Handler {
private final WeakReference<PandemoniumEditText> mEdit;
@ -101,7 +113,11 @@ public class PandemoniumEditText extends EditText {
}
public boolean isMultiline() {
return mMultiline;
return mKeyboardType == VirtualKeyboardType.KEYBOARD_TYPE_MULTILINE;
}
public VirtualKeyboardType getKeyboardType() {
return mKeyboardType;
}
private void handleMessage(final Message msg) {
@ -122,8 +138,31 @@ public class PandemoniumEditText extends EditText {
}
int inputType = InputType.TYPE_CLASS_TEXT;
if (edit.isMultiline()) {
inputType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
switch (edit.getKeyboardType()) {
case KEYBOARD_TYPE_DEFAULT:
inputType = InputType.TYPE_CLASS_TEXT;
break;
case KEYBOARD_TYPE_MULTILINE:
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
break;
case KEYBOARD_TYPE_NUMBER:
inputType = InputType.TYPE_CLASS_NUMBER;
break;
case KEYBOARD_TYPE_NUMBER_DECIMAL:
inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
break;
case KEYBOARD_TYPE_PHONE:
inputType = InputType.TYPE_CLASS_PHONE;
break;
case KEYBOARD_TYPE_EMAIL_ADDRESS:
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
break;
case KEYBOARD_TYPE_PASSWORD:
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
break;
case KEYBOARD_TYPE_URL:
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
break;
}
edit.setInputType(inputType);
@ -197,7 +236,7 @@ public class PandemoniumEditText extends EditText {
// ===========================================================
// Methods
// ===========================================================
public void showKeyboard(String p_existing_text, boolean p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
public void showKeyboard(String p_existing_text, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
int maxInputLength = (p_max_input_length <= 0) ? Integer.MAX_VALUE : p_max_input_length;
if (p_cursor_start == -1) { // cursor position not given
this.mOriginText = p_existing_text;
@ -210,7 +249,7 @@ public class PandemoniumEditText extends EditText {
this.mMaxInputLength = maxInputLength - (p_existing_text.length() - p_cursor_end);
}
this.mMultiline = p_multiline;
this.mKeyboardType = p_type;
final Message msg = new Message();
msg.what = HANDLER_OPEN_IME_KEYBOARD;

View File

@ -60,7 +60,7 @@ PandemoniumIOJavaWrapper::PandemoniumIOJavaWrapper(JNIEnv *p_env, jobject p_pand
_get_screen_refresh_rate = p_env->GetMethodID(cls, "getScreenRefreshRate", "(D)D");
_get_window_safe_area = p_env->GetMethodID(cls, "getWindowSafeArea", "()[I"),
_get_unique_id = p_env->GetMethodID(cls, "getUniqueID", "()Ljava/lang/String;");
_show_keyboard = p_env->GetMethodID(cls, "showKeyboard", "(Ljava/lang/String;ZIII)V");
_show_keyboard = p_env->GetMethodID(cls, "showKeyboard", "(Ljava/lang/String;IIII)V");
_hide_keyboard = p_env->GetMethodID(cls, "hideKeyboard", "()V");
_set_screen_orientation = p_env->GetMethodID(cls, "setScreenOrientation", "(I)V");
_get_screen_orientation = p_env->GetMethodID(cls, "getScreenOrientation", "()I");
@ -214,12 +214,12 @@ bool PandemoniumIOJavaWrapper::has_vk() {
return (_show_keyboard != 0) && (_hide_keyboard != 0);
}
void PandemoniumIOJavaWrapper::show_vk(const String &p_existing, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
void PandemoniumIOJavaWrapper::show_vk(const String &p_existing, int p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
if (_show_keyboard) {
JNIEnv *env = get_jni_env();
ERR_FAIL_COND(env == nullptr);
jstring jStr = env->NewStringUTF(p_existing.utf8().get_data());
env->CallVoidMethod(pandemonium_io_instance, _show_keyboard, jStr, p_multiline, p_max_input_length, p_cursor_start, p_cursor_end);
env->CallVoidMethod(godot_io_instance, _show_keyboard, jStr, p_type, p_max_input_length, p_cursor_start, p_cursor_end);
}
}

View File

@ -79,7 +79,7 @@ public:
float get_screen_refresh_rate(float p_fallback);
String get_unique_id();
bool has_vk();
void show_vk(const String &p_existing, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end);
void show_vk(const String &p_existing, int p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end);
void hide_vk();
int get_vk_height();
void set_vk_height(int p_height);

View File

@ -375,9 +375,9 @@ int OS_Android::get_virtual_keyboard_height() const {
// return 0;
}
void OS_Android::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
void OS_Android::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
if (pandemonium_io_java->has_vk()) {
pandemonium_io_java->show_vk(p_existing_text, p_multiline, p_max_input_length, p_cursor_start, p_cursor_end);
pandemonium_io_java->show_vk(p_existing_text, (int)p_type, p_max_input_length, p_cursor_start, p_cursor_end);
} else {
ERR_PRINT("Virtual keyboard not available");
};

View File

@ -132,7 +132,7 @@ public:
virtual bool has_touchscreen_ui_hint() const;
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void hide_virtual_keyboard();
virtual int get_virtual_keyboard_height() const;

View File

@ -32,6 +32,6 @@
@interface PandemoniumKeyboardInputView : UITextView
- (BOOL)becomeFirstResponderWithString:(NSString *)existingString multiline:(BOOL)flag cursorStart:(NSInteger)start cursorEnd:(NSInteger)end;
- (BOOL)becomeFirstResponderWithString:(NSString *)existingString cursorStart:(NSInteger)start cursorEnd:(NSInteger)end;
@end

View File

@ -83,7 +83,7 @@
return YES;
}
- (BOOL)becomeFirstResponderWithString:(NSString *)existingString multiline:(BOOL)flag cursorStart:(NSInteger)start cursorEnd:(NSInteger)end {
- (BOOL)becomeFirstResponderWithString:(NSString *)existingString cursorStart:(NSInteger)start cursorEnd:(NSInteger)end {
self.text = existingString;
self.previousText = existingString;

View File

@ -174,7 +174,7 @@ public:
virtual bool can_draw() const;
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void hide_virtual_keyboard();
virtual int get_virtual_keyboard_height() const;

View File

@ -38,10 +38,10 @@
#include "main/main.h"
#include "core/config/project_settings.h"
#include "core/io/file_access_pack.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/config/project_settings.h"
#include "drivers/unix/syslog_logger.h"
#import "app_delegate.h"
@ -439,12 +439,46 @@ bool OSIPhone::has_virtual_keyboard() const {
return true;
};
void OSIPhone::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
void OSIPhone::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
NSString *existingString = [[NSString alloc] initWithUTF8String:p_existing_text.utf8().get_data()];
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
AppDelegate.viewController.keyboardView.textContentType = nil;
switch (p_type) {
case KEYBOARD_TYPE_DEFAULT: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
} break;
case KEYBOARD_TYPE_MULTILINE: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
} break;
case KEYBOARD_TYPE_NUMBER: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeNumberPad;
} break;
case KEYBOARD_TYPE_NUMBER_DECIMAL: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDecimalPad;
} break;
case KEYBOARD_TYPE_PHONE: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypePhonePad;
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypeTelephoneNumber;
} break;
case KEYBOARD_TYPE_EMAIL_ADDRESS: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeEmailAddress;
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypeEmailAddress;
} break;
case KEYBOARD_TYPE_PASSWORD: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
if (@available(iOS 11.0, *)) {
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypePassword;
}
} break;
case KEYBOARD_TYPE_URL: {
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeWebSearch;
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypeURL;
} break;
}
[AppDelegate.viewController.keyboardView
becomeFirstResponderWithString:existingString
multiline:p_multiline
cursorStart:p_cursor_start
cursorEnd:p_cursor_end];
};

File diff suppressed because it is too large Load Diff

View File

@ -785,8 +785,8 @@ bool OS_JavaScript::has_virtual_keyboard() const {
return pandemonium_js_display_vk_available() != 0;
}
void OS_JavaScript::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
pandemonium_js_display_vk_show(p_existing_text.utf8().get_data(), p_multiline, p_cursor_start, p_cursor_end);
void OS_JavaScript::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
godot_js_display_vk_show(p_existing_text.utf8().get_data(), p_type, p_cursor_start, p_cursor_end);
}
void OS_JavaScript::hide_virtual_keyboard() {

View File

@ -124,7 +124,7 @@ public:
static OS_JavaScript *get_singleton();
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void hide_virtual_keyboard();
virtual bool get_swap_ok_cancel();

View File

@ -110,7 +110,7 @@ extern void pandemonium_js_display_notification_cb(void (*p_callback)(int p_noti
// Display Virtual Keyboard
extern int pandemonium_js_display_vk_available();
extern void pandemonium_js_display_vk_cb(void (*p_input)(const char *p_text, int p_cursor));
extern void pandemonium_js_display_vk_show(const char *p_text, int p_multiline, int p_start, int p_end);
extern void pandemonium_js_display_vk_show(const char *p_text, int p_type, int p_start, int p_end);
extern void pandemonium_js_display_vk_hide();
#ifdef __cplusplus

View File

@ -30,15 +30,15 @@
#include "line_edit.h"
#include "core/object/message_queue.h"
#include "core/input/input.h"
#include "core/input/shortcut.h"
#include "core/object/message_queue.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/string/print_string.h"
#include "core/string/translation.h"
#include "label.h"
#include "scene/gui/popup_menu.h"
#include "core/input/shortcut.h"
#include "scene/main/timer.h"
#include "scene/main/viewport.h"
@ -1391,9 +1391,9 @@ void LineEdit::clear() {
void LineEdit::show_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(), false, max_length, selection.begin, selection.end);
OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), (OS::VirtualKeyboardType)virtual_keyboard_type, max_length, selection.begin, selection.end);
} else {
OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), false, max_length, cursor_pos);
OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), (OS::VirtualKeyboardType)virtual_keyboard_type, max_length, cursor_pos);
}
}
}
@ -1807,6 +1807,14 @@ bool LineEdit::is_virtual_keyboard_enabled() const {
return virtual_keyboard_enabled;
}
void LineEdit::set_virtual_keyboard_type(VirtualKeyboardType p_type) {
virtual_keyboard_type = p_type;
}
LineEdit::VirtualKeyboardType LineEdit::get_virtual_keyboard_type() const {
return virtual_keyboard_type;
}
void LineEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = p_enabled;
@ -1982,6 +1990,8 @@ void LineEdit::_bind_methods() {
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_virtual_keyboard_type", "type"), &LineEdit::set_virtual_keyboard_type);
ClassDB::bind_method(D_METHOD("get_virtual_keyboard_type"), &LineEdit::get_virtual_keyboard_type);
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);
@ -2011,6 +2021,15 @@ void LineEdit::_bind_methods() {
BIND_ENUM_CONSTANT(MENU_REDO);
BIND_ENUM_CONSTANT(MENU_MAX);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_DEFAULT);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_MULTILINE);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER_DECIMAL);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PHONE);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_EMAIL_ADDRESS);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PASSWORD);
BIND_ENUM_CONSTANT(KEYBOARD_TYPE_URL);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text");
ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_length", PROPERTY_HINT_RANGE, "0,1000,1,or_greater"), "set_max_length", "get_max_length");
@ -2020,6 +2039,7 @@ void LineEdit::_bind_methods() {
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::INT, "virtual_keyboard_type", PROPERTY_HINT_ENUM, "Default,Multiline,Number,Decimal,Phone,Email,Password,URL"), "set_virtual_keyboard_type", "get_virtual_keyboard_type");
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");
@ -2054,6 +2074,7 @@ LineEdit::LineEdit() {
deselect_on_focus_loss_enabled = true;
popup_show = false;
virtual_keyboard_enabled = true;
virtual_keyboard_type = KEYBOARD_TYPE_DEFAULT;
drag_action = false;
drag_caret_force_displayed = false;

View File

@ -58,6 +58,17 @@ public:
};
enum VirtualKeyboardType {
KEYBOARD_TYPE_DEFAULT,
KEYBOARD_TYPE_MULTILINE,
KEYBOARD_TYPE_NUMBER,
KEYBOARD_TYPE_NUMBER_DECIMAL,
KEYBOARD_TYPE_PHONE,
KEYBOARD_TYPE_EMAIL_ADDRESS,
KEYBOARD_TYPE_PASSWORD,
KEYBOARD_TYPE_URL
};
private:
Align align;
@ -93,6 +104,7 @@ private:
bool shortcut_keys_enabled;
bool virtual_keyboard_enabled;
VirtualKeyboardType virtual_keyboard_type;
bool drag_action;
bool drag_caret_force_displayed;
@ -243,6 +255,9 @@ public:
void set_virtual_keyboard_enabled(bool p_enable);
bool is_virtual_keyboard_enabled() const;
void set_virtual_keyboard_type(VirtualKeyboardType p_type);
VirtualKeyboardType get_virtual_keyboard_type() const;
void set_selecting_enabled(bool p_enabled);
bool is_selecting_enabled() const;
@ -262,5 +277,6 @@ public:
VARIANT_ENUM_CAST(LineEdit::Align);
VARIANT_ENUM_CAST(LineEdit::MenuItems);
VARIANT_ENUM_CAST(LineEdit::VirtualKeyboardType);
#endif

View File

@ -1877,7 +1877,7 @@ void TextEdit::_notification(int p_what) {
cursor_end = cursor_start + post_text.length();
}
OS::get_singleton()->show_virtual_keyboard(get_text(), get_global_rect(), true, -1, cursor_start, cursor_end);
OS::get_singleton()->show_virtual_keyboard(get_text(), get_global_rect(), OS::KEYBOARD_TYPE_MULTILINE, -1, cursor_start, cursor_end);
}
} break;
case NOTIFICATION_FOCUS_EXIT: {