Browse Source

Added the possibility to specify and auto-call a software keyboard for all TextInput (#1143)

Yuxiao Mao 2 years ago
parent
commit
cb834ba1ad
1 changed files with 13 additions and 1 deletions
  1. 13 1
      h2d/TextInput.hx

+ 13 - 1
h2d/TextInput.hx

@@ -51,6 +51,13 @@ class TextInput extends Text {
 	**/
 	public var backgroundColor(get, set) : Null<Int>;
 
+	/**
+		When disabled, showSoftwareKeyboard will not be called.
+	**/
+	public var useSoftwareKeyboard : Bool = true;
+	public static dynamic function showSoftwareKeyboard(target:TextInput) {}
+	public static dynamic function hideSoftwareKeyboard(target:TextInput) {}
+
 	var interactive : h2d.Interactive;
 	var cursorText : String;
 	var cursorX : Float;
@@ -121,9 +128,15 @@ class TextInput extends Text {
 			onTextInput(e);
 			handleKey(e);
 		};
+		interactive.onFocus = function(e) {
+			onFocus(e);
+			if ( useSoftwareKeyboard && canEdit )
+				showSoftwareKeyboard(this);
+		}
 		interactive.onFocusLost = function(e) {
 			cursorIndex = -1;
 			selectionRange = null;
+			hideSoftwareKeyboard(this);
 			onFocusLost(e);
 		};
 
@@ -142,7 +155,6 @@ class TextInput extends Text {
 
 		interactive.onKeyUp = function(e) onKeyUp(e);
 		interactive.onRelease = function(e) onRelease(e);
-		interactive.onFocus = function(e) onFocus(e);
 		interactive.onKeyUp = function(e) onKeyUp(e);
 		interactive.onMove = function(e) onMove(e);
 		interactive.onOver = function(e) onOver(e);