Events for children of PComposite?

14 views
Skip to first unread message

jles...@gmx.de

unread,
Apr 16, 2014, 10:30:40 AM4/16/14
to piccolo...@googlegroups.com
Hello everybody
I am new to Piccolo, but I'm very impressed about that elegant little framework. So I am going into details now and have a problem with event propagation. When I create a PComposite, it seems that the composite's children don't receive any input events. The attached source code demonstrates that with a minimal example. I would like both nodes - the composite and its child - to receive events. Clicking the composite is supposed to initiate a drag&drop operation while an exact click on the inner text component should initiate text editing (of course based on a PStyledText later - I just simplified the code here to outline the problem).

Does anybody have a good idea?

Cheers,
Jan

CompositeEventProblem.java

Michael Heuer

unread,
Apr 16, 2014, 11:21:49 AM4/16/14
to piccolo...@googlegroups.com
Hello Jan,

I am not sure why you are adding text2 to a composite node in your
example. If you add text2 as a child of text1 it receives events
fine.

mousePressed on org.piccolo2d.nodes.PText@63ce0072
mousePressed on org.piccolo2d.nodes.PText@321e4dd0

Then from the javadoc for PComposite:

PComposite is a simple node that makes a group of nodes appear to be a
single node when picking and interacting.

This means that PComposite does not forward events on to its child
node(s). If you add your input event listener to the composite node,
it will receive the events when you click on text2, e.g.

mousePressed on org.piccolo2d.nodes.PText@41096cd9
mousePressed on org.piccolo2d.extras.nodes.PComposite@1840b778

Does this help?

michael

jles...@gmx.de

unread,
Apr 16, 2014, 11:32:02 AM4/16/14
to piccolo...@googlegroups.com
Hi Michael
Oh, yes, indeed - this helps. I wasn't aware that I can stack PNodes directly. I though PComposite were the only (correct) way to build composites.

Thanks a lot,
Jan
Reply all
Reply to author
Forward
0 new messages