I’ve found something strange :
In most of the case, Nifty does consume mouse input event.
But on this case it does not :
When you click on a button that cause the button itself ( or the panel containing it ) to disappear or be hidden, the input event isn’t consumed.
I don’t know why oO
I guess because the system decides if the click is obstructed by the GUI after it has been changed. As a solution you could enqueue the removing as a callable so it will be removed the next frame so the event still gets consumed in that frame.
Well, I’ve tried this with the HelloWorldExample one minute ago (using the latest Nifty). I’ve simply changed the onClick=“quit()” method implementation to hide the panel and I’ve logged inside of Nifty if the event was consumed (true) or not (false).
What’s happening is this:
- when I move around the panel then Nifty consumes the mouse move events
- when I click the mouse button the panel gets hidden and the mouse click event (or being more specific: the mouse down event) correctly gets consumed as well
- at the time I release the mouse button the panel is already hidden and so the “mouse up” event will not be consumed by Nifty anymore (the panel is gone)
- all other events from now on, like mouse move events and so on will never hit the panel anymore (it’s still gone) and therefore will not be consumed
Changing “onClick” to “onRelease” will consume the “mouse up” event too which might be what you’re expecting?
That makes sense. I think I will change most of my interaction to the onRelease method
→ It’s not a bug. I will change to title of the post and close it.
Thanks for the answer.
I still have a problem.
I have changed all my interact to the onRelease method for one of my sheets.
When I was using the onClick attribute, once a button was clicked, the layers below weren’t triggered.
Now, when I use onRelease instead, all my Nifty Layers consume the mouse click oO
Is that an intended feature ?
what exactly do you mean? how do you know that “all nifty layers” consume the mouse click? I’m a bit confused now can you give an example?
Here is one of my ‘view’
The important part is in the red rect.
Each one is defined in a different control :
<controlDefinition name=“story” controller=“com.didigame.acariaempire.gui.quest.StoryController” >
<control id=“skipButton” name=“ae-button” style=“bigButton” height=“25px” width=“200px” text=“Skip” align=“center” valign=“bottom” >
<interact onRelease=“skipText()” />
<controlDefinition name=“worldMap” controller=“com.didigame.acariaempire.gui.worldmap.MapController” >
<control id=“localMapButton” name=“ae-imgButton” height=“55px” width=“55px” align=“center” valign=“center” firstEffect=“iconMap” >
<interact onRelease=“localMapClick()” />
Each one of those control have this parent :
<layer id=“sheetLayer” childLayout=“overlay” />
When I use :
[java]<interact onRelease="…" />[/java] the two controls are triggered.
[java]<interact onClick="…" />[/java] only the top control is triggered.
What if you have an onClick that essentially does nothing and then an onRelease that does what you want?
I’m only making wild stabs in the dark but maybe if all components get the down then they all capture the release, too… or if someone consume the down or the click then they won’t bother watching for release. Interested to see what you find out as I may hit similar issues soon.
I just witnessed another thing :
If I change my ‘skip Button’ by a simple panel
[java]<panel visibleToMouse=“true” >[/java]
It doesn’t change anything.
That may means that the onRelease event just doesn’t check if the mouse click as been consumed or not.
As you suggessted, I tried to add a onClick interaction on my 'map button'.
<control id="skipButton" name="ae-button" style="bigButton" height="25px" width="200px" text="Skip" align="center" valign="bottom" >
<interact onClick="doNothing()" onRelease="skipText()" />
And strangely it worked ( As long as I click on the button and not on a panel having visibleToMouse="true" )
I thought that the onClick event and the onRelease event occur at different times and were unrelated, but it seems I was wrong :)
For now, I will just add a onClick="doNothing()" to my buttons. It may work as a temporary fix
Well… I know in some guis, when a component receives a pressed event then it will ‘capture’ the mouse so that it also receives the release even if the mouse is no longer over the control. The theory was that if you can keep those underlying controls from getting the down event (by consuming it) then they might avoid getting the release as well.
…I don’t know if that’s what’s happening, but it’s a theory that sort of fits your experiment.