LayeredLayout and interactive component issue

39 views
Skip to first unread message

Thomas

unread,
Aug 7, 2018, 1:25:32 PM8/7/18
to CodenameOne Discussions
I have a Container (lets call it P1) that contains a single (for now) interactive child component (C1). This child component itself is a container using a LayeredLayout (it has 3 layers) and is interactive (it implements pointer click and drag events with override of the low level pointer events methods (pointerPressed, pointerDragged, pointerReleased...))
As long as P1 uses the default FlawLayout layout, everything is fine, my click and drag events on the child component it contains (C1) are correctly handled. But if I change the P1 layout to LayeredLayout, it stops working (my child component C1 do no longer receive the click and drag events).
I really don't understand why and how to fix it (I need P1 to use LayeredLayout as I want to add another child component on top of the previous one when the user perform some specific action)
Also, is there some debugging tool allowing to track down the CN1 events (which component currently has focus and what events have been emited)? It would be a really usefull feature to implement in the simulator.



Shai Almog

unread,
Aug 8, 2018, 12:30:10 AM8/8/18
to CodenameOne Discussions
A layered layout takes over all the space whereas flow layout will leave some areas untouched. I'm guessing you have a different component within the hierarchy that is grabbing events.
Notice you shouldn't handle events in a Container. It's problematic as most events won't deliver to a container and instead go directly to the applicable child. A better approach would be to bind an event listener on the form in initComponent() and release it in deinitialize().

Thomas

unread,
Aug 8, 2018, 12:33:55 AM8/8/18
to CodenameOne Discussions
No my hierarchy is pretty simple. Using the component inspector I have my form, that contains my parent container P1 (+ the toolbar) that itself contains the child component C1, that contains 3 components (its layer components). So I really don't get it. 

Shai Almog

unread,
Aug 9, 2018, 12:23:29 AM8/9/18
to CodenameOne Discussions
The complexity of the hierarchy has nothing to do with it. Overriding pointer events in a Container is generally problematic.

Thomas

unread,
Aug 9, 2018, 12:35:58 AM8/9/18
to CodenameOne Discussions
Yes I changed it for a control layer component and now it is working.
Container is supposed to be a component though (it extends it) so it should be able to handle pointer events like any other component...


On Thursday, August 9, 2018 at 6:23:29 AM UTC+2, Shai Almog wrote:

Shai Almog

unread,
Aug 10, 2018, 12:49:00 AM8/10/18
to CodenameOne Discussions
Please re-read my first response. It can if it's focusable but only one component in the hierarchy gets these events so it will block the functionality of the components within or be blocked by them.

We have "lead component" to enable a lot of these use cases.
Reply all
Reply to author
Forward
0 new messages