Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on tab: insert '\t' instead of changing focus #38

Closed
nicanorrr opened this issue May 17, 2020 · 5 comments
Closed

on tab: insert '\t' instead of changing focus #38

nicanorrr opened this issue May 17, 2020 · 5 comments

Comments

@nicanorrr
Copy link

Hi, instead of using tab to cycle between input fields, I wanted it to insert '\t'. I was able to edit the code a bit to do this and wanted to share it here. Sorry if this is the wrong place to share this. I'm new to git and am still figuring things out.

The problem with this solution is that you can't switch between the "insert \t" and "cycle input fields" functionality easily without hard editing the code. Part of the solution was changing the callback of a tab keydown event from OnTab to OnValueChanged. I don't know if you might have a more elegant solution where a user can choose which functionality they want in the Unity Inspector.

Great work btw! I don't understand most of it because I don't know javascript. You might have a better and less buggy idea on how to do the functionality I coded.

Changes:
In WebGLInput.jslib:

WebGLInputTab:function(id, cb) {
	var input = instances[id];
	// for tab key
    input.addEventListener('keydown', function (e) {
        if ((e.which && e.which === 9) || (e.keyCode && e.keyCode === 9)) {
            e.preventDefault();
            // Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]);
           var s = input.selectionStart;
           input.value = input.value.substring(0,input.selectionStart) + "\t" + input.value.substring(input.selectionEnd);
           input.selectionEnd = s+1;
           var value = allocate(intArrayFromString(input.value), 'i8', ALLOC_NORMAL);
           Runtime.dynCall("vii", cb, [id,value]);
        }
	});
},

In WebGLInput.cs, WebGLInputPlugin method declarations

    //[DllImport("__Internal")]
    //public static extern void WebGLInputTab(int id, Action<int, int> cb);
    [DllImport("__Internal")]
    public static extern void WebGLInputTab(int id, Action<int, string> cb);

    //public static void WebGLInputTab(int id, Action<int, int> cb) { }
    public static void WebGLInputTab(int id, Action<int, string> cb) { }

In WebGLInput.cs OnSelect():

    //WebGLInputPlugin.WebGLInputTab(id, OnTab);
    WebGLInputPlugin.WebGLInputTab(id, OnValueChange);
@kou-yeung
Copy link
Owner

thank you for share.
tab key to changing focus is default behaviour.

you can add a flag to WebGLInput.cs to switch "change focus" or "\t".
i will make a sample for this.

@nicanorrr
Copy link
Author

ok :) if you update the code with this functionality, I will replace my fixes with yours :)

@kou-yeung
Copy link
Owner

release a new unitypackage to switch tab function
https://github.com/kou-yeung/WebGLInput/releases/tag/0.82

Add "WEBGLINPUT_TAB" to Scripting Define Symbols in PlayerSettings.
then you can see WebGLInput added a flag named "Enable Tab Text".
if enable this flag. you can insert '\t'.

i want the plugins keep simply. so take this solution :)

@nicanorrr
Copy link
Author

thank you :) will try it as soon as I can :)

@nicanorrr
Copy link
Author

i just tried it and works perfectly :) will let you know if there are any bugs I find :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants