[Nifty1.3] Mouse click event is delivered to all of the overlapping element

If elements are overlapped and all elements are set to visibleToMouse(true),

then all elements get the mouse click event.

It seems inappropriate. Only the topmost element should get the event.

Or event can be consumed so not delivered to next element.

Can I do this?

Thank you in advance.

I’ve had a similar problem.

I spoke about it in this post :

http://hub.jmonkeyengine.org/groups/gui/forum/topic/nifty1-3-nifty-input-event-consumption-bug/



After some research, what has been have found is :


  • the attribute visibleToMouse is used to specify if Nifty consume the click or not.
  • if you want a specific panel to consume the click ( so that the panels behind doen’t see it ) you have to add a :

    [java]

    <interact onClick=“whateverNameYouWant()” />

    [/java]

    to your panel.



    It seems that what consume the click is the “interact” part and not the "visibleToMouse:

    We have also seen that

    [java]

    <interact onRelease=“method()” />

    [/java]

    doesn’t consume the click.



    You need to do something like that :

    [java]

    <interact onClick=“whateverNameYouWant()” onRelease=“method()” />

    [/java]





    On my case I have add some

    [java]

    <interact onRelease=“method()” />

    [/java]

    to my XML.



    But I will be thanksfull if I can get ride of them :slight_smile:



    I don’t know if you already had done this analysis.

    If not, I hope it can help :slight_smile:

Thank you for the answer.

I found the reason.

Nifty only consumes event by ‘onClickMethod’ return value.

It means a listener subscribed by code cannot be consumed.

I posted a patch at nifty project page.

If you use the onClick, the return value tells nifty is the event has to be consumed or not. Returning true should consume the event, while returning false should not.

ractoc said:
If you use the onClick, the return value tells nifty is the event has to be consumed or not. Returning true should consume the event, while returning false should not.

Thank you for the answer.
Yeah. I found that the return value is about the event consumption.
The matter is when I subscribe listener by code.
EventTopicSubsriber.onEvent() has void return type.

I really think that:


Only the topmost element should get the event.


might be the correct solution for this.

Is there a REAL case where you don't want this to happen at all? I mean, is there a case where you will miss the current default behaviour of "click-through" and you will later bitch about it? :D

On the other hand this was no issue up until now at all... if you really want to temporarily block interaction because you want to display some form of popup layer then, well, you could simply use the build in popup-layer mechanism :)

I’m writing UI tool so I’m adding listeners Nifty.subscribe().

Drawing box → popup menu → create elements.

When I create two overlapping panels with setVisibleToMouse(true) and subscribe it,

both panels get the event.

How can I avoid it?

just cmmited some change to svn that might resolve that issue. see the post on the nifty “general discussion” forum for details or the huge comment in svn for the change :smiley:



to summarize: mouse events should now be automatically consumed by elements that are top most (when they use some interact on* method that is). I think this is what you would expect anyways. not sure if this breaks some other use cases tho :smiley: but I think this should work better now…