Hi,
it seems that native.newtextfields do not propagate touch events through to buttons sitting behind the input field. Is there any chance to make that happen?
thanks
Hi,
it seems that native.newtextfields do not propagate touch events through to buttons sitting behind the input field. Is there any chance to make that happen?
thanks
Hello,
You can dispatch the touch event inside the code after the userInput began :
For example :
local nT=native.newTextField( 0,0,100,100 ) local im=display.newImageRect( ... , 200, 200 ) im:addEventListener( "touch", function(event) -- the code here end ) nT:addEventListener( "userInput", function(event) if event.phase=="began" then --code here im:dispatchEvent({name="touch",phase="ended"}) \<\<--I dispatch the touch of the image behind the textfield end end )
If it’s a widget button but not an image, I don’t know how to do.
edit : you can take the function used in the widget (onRelease-function) and call it inside the “began”-phase of the textField.
Yvan.
That’s a very good idea, thank you yvandetot.
The only problem is that this solution dispatches the touch event to the button (or imagerect, …) behind it no matter where on the native.newtextfield you touch. In my scenario I have a native.newtextfield with a button behind it on the left side (lets say the first 10% of the inputfield) and a button on the right side (again, about the last 10% of inputfield.width).
In other words, lets say my inputfield is 100px wide, then the left button is from pixel 0 - 10 behind it and the right button is from pixel 90-100 behind it. And I’d like to make these buttons work
Sorry for being unclear in my original post, hope the situation got clearer now
If you want to leave the textfield in front of the screen, I think there a no way to make the difference between a portion of the field ( left or right ).
What you can do is to have a fake image of the texfield to replace the texfield. So the textfield is invisible while the image is visible.
When selecting an button, you make the image invisible, the textfield visible and focusing on it with setKeyboardFocus.
It’s not so elegant but it’s will works lol.
Yvan.
Wow, that’s very creative and I’ll play around with this solution. Jup, seems like I can make that work with this idea. Thank you sir
Hello,
You can dispatch the touch event inside the code after the userInput began :
For example :
local nT=native.newTextField( 0,0,100,100 ) local im=display.newImageRect( ... , 200, 200 ) im:addEventListener( "touch", function(event) -- the code here end ) nT:addEventListener( "userInput", function(event) if event.phase=="began" then --code here im:dispatchEvent({name="touch",phase="ended"}) \<\<--I dispatch the touch of the image behind the textfield end end )
If it’s a widget button but not an image, I don’t know how to do.
edit : you can take the function used in the widget (onRelease-function) and call it inside the “began”-phase of the textField.
Yvan.
That’s a very good idea, thank you yvandetot.
The only problem is that this solution dispatches the touch event to the button (or imagerect, …) behind it no matter where on the native.newtextfield you touch. In my scenario I have a native.newtextfield with a button behind it on the left side (lets say the first 10% of the inputfield) and a button on the right side (again, about the last 10% of inputfield.width).
In other words, lets say my inputfield is 100px wide, then the left button is from pixel 0 - 10 behind it and the right button is from pixel 90-100 behind it. And I’d like to make these buttons work
Sorry for being unclear in my original post, hope the situation got clearer now
If you want to leave the textfield in front of the screen, I think there a no way to make the difference between a portion of the field ( left or right ).
What you can do is to have a fake image of the texfield to replace the texfield. So the textfield is invisible while the image is visible.
When selecting an button, you make the image invisible, the textfield visible and focusing on it with setKeyboardFocus.
It’s not so elegant but it’s will works lol.
Yvan.
Wow, that’s very creative and I’ll play around with this solution. Jup, seems like I can make that work with this idea. Thank you sir