Add support for multiple virtual keyboard types
This commit is contained in:
parent
9f408aef45
commit
103c0fa6e6
|
@ -930,7 +930,7 @@
|
|||
<return type="void" />
|
||||
<argument index="0" name="existing_text" type="String" />
|
||||
<argument index="1" name="position" type="Rect2" default="Rect2(0, 0, 0, 0)" />
|
||||
<argument index="2" name="multiline" type="bool" default="false" />
|
||||
<argument index="2" name="type" type="int" enum="DisplayServer.VirtualKeyboardType" default="0" />
|
||||
<argument index="3" name="max_length" type="int" default="-1" />
|
||||
<argument index="4" name="cursor_start" type="int" default="-1" />
|
||||
<argument index="5" name="cursor_end" type="int" default="-1" />
|
||||
|
@ -938,11 +938,11 @@
|
|||
Shows the virtual keyboard if the platform has one.
|
||||
[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).
|
||||
[code]position[/code] parameter is the screen space [Rect2] of the edited text.
|
||||
[code]multiline[/code] parameter needs to be set to [code]true[/code] to be able to enter multiple lines of text, as in [TextEdit].
|
||||
[code]type[/code] parameter allows configuring which type of virtual keyboard to show.
|
||||
[code]max_length[/code] limits the number of characters that can be entered if different from [code]-1[/code].
|
||||
[code]cursor_start[/code] can optionally define the current text cursor position if [code]cursor_end[/code] is not set.
|
||||
[code]cursor_start[/code] and [code]cursor_end[/code] can optionally define the current text selection.
|
||||
[b]Note:[/b] This method is implemented on Android, iOS and UWP.
|
||||
[b]Note:[/b] This method is implemented on Android, iOS and HTML5.
|
||||
</description>
|
||||
</method>
|
||||
<method name="warp_mouse">
|
||||
|
@ -1323,6 +1323,31 @@
|
|||
</constant>
|
||||
<constant name="SCREEN_SENSOR" value="6" enum="ScreenOrientation">
|
||||
</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. Instead, this behaves 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="CURSOR_ARROW" value="0" enum="CursorShape">
|
||||
</constant>
|
||||
<constant name="CURSOR_IBEAM" value="1" enum="CursorShape">
|
||||
|
|
|
@ -246,6 +246,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">
|
||||
|
@ -356,6 +359,31 @@
|
|||
<constant name="MENU_MAX" value="28" 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. Instead, this behaves 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="caret_color" data_type="color" type="Color" default="Color(0.95, 0.95, 0.95, 1)">
|
||||
|
|
|
@ -221,12 +221,12 @@ bool DisplayServerAndroid::screen_is_touchscreen(int p_screen) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void DisplayServerAndroid::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_length, int p_cursor_start, int p_cursor_end) {
|
||||
void DisplayServerAndroid::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) {
|
||||
GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java();
|
||||
ERR_FAIL_NULL(godot_io_java);
|
||||
|
||||
if (godot_io_java->has_vk()) {
|
||||
godot_io_java->show_vk(p_existing_text, p_multiline, p_max_length, p_cursor_start, p_cursor_end);
|
||||
godot_io_java->show_vk(p_existing_text, (int)p_type, p_max_length, p_cursor_start, p_cursor_end);
|
||||
} else {
|
||||
ERR_PRINT("Virtual keyboard not available");
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ public:
|
|||
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
|
||||
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override;
|
||||
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override;
|
||||
virtual void virtual_keyboard_hide() override;
|
||||
virtual int virtual_keyboard_get_height() const override;
|
||||
|
||||
|
|
|
@ -203,9 +203,10 @@ public class GodotIO {
|
|||
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);
|
||||
|
|
|
@ -52,6 +52,18 @@ public class GodotEditText 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 DisplayServer::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 GodotEditText 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<GodotEditText> mEdit;
|
||||
|
@ -100,8 +112,8 @@ public class GodotEditText extends EditText {
|
|||
setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE);
|
||||
}
|
||||
|
||||
public boolean isMultiline() {
|
||||
return mMultiline;
|
||||
public VirtualKeyboardType getKeyboardType() {
|
||||
return mKeyboardType;
|
||||
}
|
||||
|
||||
private void handleMessage(final Message msg) {
|
||||
|
@ -122,8 +134,31 @@ public class GodotEditText 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);
|
||||
|
||||
|
@ -201,7 +236,7 @@ public class GodotEditText 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;
|
||||
|
@ -214,7 +249,7 @@ public class GodotEditText 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;
|
||||
|
|
|
@ -115,7 +115,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
}
|
||||
for (int i = 0; i < count; ++i) {
|
||||
int key = newChars[i];
|
||||
if ((key == '\n') && !mEdit.isMultiline()) {
|
||||
if ((key == '\n') && !(mEdit.getKeyboardType() == GodotEditText.VirtualKeyboardType.KEYBOARD_TYPE_MULTILINE)) {
|
||||
// Return keys are handled through action events
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
|
|||
_get_scaled_density = p_env->GetMethodID(cls, "getScaledDensity", "()F");
|
||||
_get_screen_refresh_rate = p_env->GetMethodID(cls, "getScreenRefreshRate", "(D)D");
|
||||
_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 GodotIOJavaWrapper::has_vk() {
|
|||
return (_show_keyboard != nullptr) && (_hide_keyboard != nullptr);
|
||||
}
|
||||
|
||||
void GodotIOJavaWrapper::show_vk(const String &p_existing, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
||||
void GodotIOJavaWrapper::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_NULL(env);
|
||||
jstring jStr = env->NewStringUTF(p_existing.utf8().get_data());
|
||||
env->CallVoidMethod(godot_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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
Rect2i get_display_safe_area();
|
||||
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);
|
||||
|
|
|
@ -199,7 +199,7 @@ public:
|
|||
|
||||
virtual bool screen_is_touchscreen(int p_screen) const override;
|
||||
|
||||
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_length, int p_cursor_start, int p_cursor_end) override;
|
||||
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) override;
|
||||
virtual void virtual_keyboard_hide() override;
|
||||
|
||||
void virtual_keyboard_set_height(int height);
|
||||
|
|
|
@ -585,12 +585,44 @@ bool DisplayServerIOS::screen_is_touchscreen(int p_screen) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void DisplayServerIOS::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_length, int p_cursor_start, int p_cursor_end) {
|
||||
void DisplayServerIOS::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_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;
|
||||
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];
|
||||
}
|
||||
|
|
|
@ -32,6 +32,6 @@
|
|||
|
||||
@interface GodotKeyboardInputView : 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
|
||||
|
|
|
@ -84,7 +84,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;
|
||||
|
||||
|
|
|
@ -604,8 +604,8 @@ void DisplayServerJavaScript::vk_input_text_callback(const char *p_text, int p_c
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::virtual_keyboard_show(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) {
|
||||
godot_js_display_vk_show(p_existing_text.utf8().get_data(), p_multiline, p_cursor_start, p_cursor_end);
|
||||
void DisplayServerJavaScript::virtual_keyboard_show(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 DisplayServerJavaScript::virtual_keyboard_hide() {
|
||||
|
|
|
@ -157,7 +157,7 @@ public:
|
|||
virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
|
||||
virtual void virtual_keyboard_show(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) override;
|
||||
virtual void virtual_keyboard_show(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) override;
|
||||
virtual void virtual_keyboard_hide() override;
|
||||
|
||||
// windows
|
||||
|
|
|
@ -121,7 +121,7 @@ extern void godot_js_display_notification_cb(void (*p_callback)(int p_notificati
|
|||
extern int godot_js_display_vk_available();
|
||||
extern int godot_js_display_tts_available();
|
||||
extern void godot_js_display_vk_cb(void (*p_input)(const char *p_text, int p_cursor));
|
||||
extern void godot_js_display_vk_show(const char *p_text, int p_multiline, int p_start, int p_end);
|
||||
extern void godot_js_display_vk_show(const char *p_text, int p_type, int p_start, int p_end);
|
||||
extern void godot_js_display_vk_hide();
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -73,7 +73,7 @@ const GodotDisplayVK = {
|
|||
GodotDisplayVK.textarea = create('textarea');
|
||||
GodotDisplayVK.updateSize();
|
||||
},
|
||||
show: function (text, multiline, start, end) {
|
||||
show: function (text, type, start, end) {
|
||||
if (!GodotDisplayVK.textinput || !GodotDisplayVK.textarea) {
|
||||
return;
|
||||
}
|
||||
|
@ -81,7 +81,46 @@ const GodotDisplayVK = {
|
|||
GodotDisplayVK.hide();
|
||||
}
|
||||
GodotDisplayVK.updateSize();
|
||||
const elem = multiline ? GodotDisplayVK.textarea : GodotDisplayVK.textinput;
|
||||
|
||||
let elem = GodotDisplayVK.textinput;
|
||||
switch (type) {
|
||||
case 0: // KEYBOARD_TYPE_DEFAULT
|
||||
elem.type = 'text';
|
||||
elem.inputmode = '';
|
||||
break;
|
||||
case 1: // KEYBOARD_TYPE_MULTILINE
|
||||
elem = GodotDisplayVK.textarea;
|
||||
break;
|
||||
case 2: // KEYBOARD_TYPE_NUMBER
|
||||
elem.type = 'text';
|
||||
elem.inputmode = 'numeric';
|
||||
break;
|
||||
case 3: // KEYBOARD_TYPE_NUMBER_DECIMAL
|
||||
elem.type = 'text';
|
||||
elem.inputmode = 'decimal';
|
||||
break;
|
||||
case 4: // KEYBOARD_TYPE_PHONE
|
||||
elem.type = 'tel';
|
||||
elem.inputmode = '';
|
||||
break;
|
||||
case 5: // KEYBOARD_TYPE_EMAIL_ADDRESS
|
||||
elem.type = 'email';
|
||||
elem.inputmode = '';
|
||||
break;
|
||||
case 6: // KEYBOARD_TYPE_PASSWORD
|
||||
elem.type = 'password';
|
||||
elem.inputmode = '';
|
||||
break;
|
||||
case 7: // KEYBOARD_TYPE_URL
|
||||
elem.type = 'url';
|
||||
elem.inputmode = '';
|
||||
break;
|
||||
default:
|
||||
elem.type = 'text';
|
||||
elem.inputmode = '';
|
||||
break;
|
||||
}
|
||||
|
||||
elem.readonly = false;
|
||||
elem.disabled = false;
|
||||
elem.value = text;
|
||||
|
@ -694,11 +733,11 @@ const GodotDisplay = {
|
|||
* Virtual Keyboard
|
||||
*/
|
||||
godot_js_display_vk_show__sig: 'viiii',
|
||||
godot_js_display_vk_show: function (p_text, p_multiline, p_start, p_end) {
|
||||
godot_js_display_vk_show: function (p_text, p_type, p_start, p_end) {
|
||||
const text = GodotRuntime.parseString(p_text);
|
||||
const start = p_start > 0 ? p_start : 0;
|
||||
const end = p_end > 0 ? p_end : start;
|
||||
GodotDisplayVK.show(text, p_multiline, start, end);
|
||||
GodotDisplayVK.show(text, p_type, start, end);
|
||||
},
|
||||
|
||||
godot_js_display_vk_hide__sig: 'v',
|
||||
|
|
|
@ -716,7 +716,7 @@ bool OS_UWP::has_virtual_keyboard() const {
|
|||
return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch;
|
||||
}
|
||||
|
||||
void OS_UWP::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_UWP::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) {
|
||||
InputPane ^ pane = InputPane::GetForCurrentView();
|
||||
pane->TryShow();
|
||||
}
|
||||
|
|
|
@ -231,7 +231,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 Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr);
|
||||
|
|
|
@ -1513,9 +1513,9 @@ void LineEdit::clear() {
|
|||
void LineEdit::show_virtual_keyboard() {
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
|
||||
if (selection.enabled) {
|
||||
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, selection.begin, selection.end);
|
||||
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), DisplayServer::VirtualKeyboardType(virtual_keyboard_type), max_length, selection.begin, selection.end);
|
||||
} else {
|
||||
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, caret_column);
|
||||
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), DisplayServer::VirtualKeyboardType(virtual_keyboard_type), max_length, caret_column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2040,6 +2040,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_middle_mouse_paste_enabled(bool p_enabled) {
|
||||
middle_mouse_paste_enabled = p_enabled;
|
||||
}
|
||||
|
@ -2280,6 +2288,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);
|
||||
|
@ -2329,6 +2339,15 @@ void LineEdit::_bind_methods() {
|
|||
BIND_ENUM_CONSTANT(MENU_INSERT_SHY);
|
||||
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::STRING, "placeholder_text"), "set_placeholder", "get_placeholder");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment");
|
||||
|
@ -2339,6 +2358,7 @@ void LineEdit::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_to_text_length"), "set_expand_to_text_length_enabled", "is_expand_to_text_length_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::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, "middle_mouse_paste_enabled"), "set_middle_mouse_paste_enabled", "is_middle_mouse_paste_enabled");
|
||||
|
|
|
@ -70,6 +70,17 @@ public:
|
|||
MENU_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
|
||||
};
|
||||
|
||||
private:
|
||||
HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT;
|
||||
|
||||
|
@ -120,6 +131,7 @@ private:
|
|||
bool shortcut_keys_enabled = true;
|
||||
|
||||
bool virtual_keyboard_enabled = true;
|
||||
VirtualKeyboardType virtual_keyboard_type = KEYBOARD_TYPE_DEFAULT;
|
||||
|
||||
bool middle_mouse_paste_enabled = true;
|
||||
|
||||
|
@ -311,6 +323,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_middle_mouse_paste_enabled(bool p_enabled);
|
||||
bool is_middle_mouse_paste_enabled() const;
|
||||
|
||||
|
@ -335,5 +350,6 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(LineEdit::MenuItems);
|
||||
VARIANT_ENUM_CAST(LineEdit::VirtualKeyboardType);
|
||||
|
||||
#endif // LINE_EDIT_H
|
||||
|
|
|
@ -1466,7 +1466,7 @@ void TextEdit::_notification(int p_what) {
|
|||
caret_end = caret_start + post_text.length();
|
||||
}
|
||||
|
||||
DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), true, -1, caret_start, caret_end);
|
||||
DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), DisplayServer::KEYBOARD_TYPE_MULTILINE, -1, caret_start, caret_end);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
|
|
@ -400,7 +400,7 @@ String DisplayServer::ime_get_text() const {
|
|||
ERR_FAIL_V_MSG(String(), "IME or NOTIFICATION_WM_IME_UPDATEnot supported by this display server.");
|
||||
}
|
||||
|
||||
void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_length, int p_cursor_start, int p_cursor_end) {
|
||||
void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) {
|
||||
WARN_PRINT("Virtual keyboard not supported by this display server.");
|
||||
}
|
||||
|
||||
|
@ -660,7 +660,7 @@ void DisplayServer::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("ime_get_selection"), &DisplayServer::ime_get_selection);
|
||||
ClassDB::bind_method(D_METHOD("ime_get_text"), &DisplayServer::ime_get_text);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position", "multiline", "max_length", "cursor_start", "cursor_end"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2()), DEFVAL(false), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1));
|
||||
ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position", "type", "max_length", "cursor_start", "cursor_end"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2()), DEFVAL(KEYBOARD_TYPE_DEFAULT), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1));
|
||||
ClassDB::bind_method(D_METHOD("virtual_keyboard_hide"), &DisplayServer::virtual_keyboard_hide);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("virtual_keyboard_get_height"), &DisplayServer::virtual_keyboard_get_height);
|
||||
|
@ -732,6 +732,15 @@ void DisplayServer::_bind_methods() {
|
|||
BIND_ENUM_CONSTANT(SCREEN_SENSOR_PORTRAIT);
|
||||
BIND_ENUM_CONSTANT(SCREEN_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(CURSOR_ARROW);
|
||||
BIND_ENUM_CONSTANT(CURSOR_IBEAM);
|
||||
BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
|
||||
|
|
|
@ -382,7 +382,18 @@ public:
|
|||
virtual Point2i ime_get_selection() const;
|
||||
virtual String ime_get_text() const;
|
||||
|
||||
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
|
||||
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 void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
|
||||
virtual void virtual_keyboard_hide();
|
||||
|
||||
// returns height of the currently shown virtual keyboard (0 if keyboard is hidden)
|
||||
|
@ -467,6 +478,7 @@ VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation)
|
|||
VARIANT_ENUM_CAST(DisplayServer::WindowMode)
|
||||
VARIANT_ENUM_CAST(DisplayServer::WindowFlags)
|
||||
VARIANT_ENUM_CAST(DisplayServer::HandleType)
|
||||
VARIANT_ENUM_CAST(DisplayServer::VirtualKeyboardType);
|
||||
VARIANT_ENUM_CAST(DisplayServer::CursorShape)
|
||||
VARIANT_ENUM_CAST(DisplayServer::VSyncMode)
|
||||
VARIANT_ENUM_CAST(DisplayServer::TTSUtteranceEvent)
|
||||
|
|
Loading…
Reference in New Issue