cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Container setTouchable not working

PPete
Associate III

I build a custom Numpad Container. Iam setting it Visible when a textarea is clicked. And it is the top layer on the Screen. Trying to set other containers on a lower layer not touchable is not working.
I can still click the slide menu button und some other buttons on my Background container.

Is it a bug?

scrollableContainer.setTouchable(false);

slideMenuContainer.setTouchable(false);

backGroundContainer.setTouchable(false);

13 REPLIES 13
PPete
Associate III

Hello thanks for the fast response.
the solution with the clicklistener is working for me. But it feels like a Workaround.

Set the background container to "not touchable" and back to "touchable" is not activating the touch Event to all of my four buttons in the Background Container. I think something is slumbering there.

Greats Peter

Hello

Yes, seems to be that 'setTouchable(0)' doesn't do anything with custom containers, but with widgets it works fine.

Maybe easiest way is to add implementation of 'setTouchable' function to custom container and list all widgets in that container there, like:

 

void CustomContainer1::setTouchable(bool touch)
{
        button1.setTouchable(touch);
		button2.setTouchable(touch);
}

 

Other way to solve it is to add implementation of setTouchable to the 'Container.hpp' at '\touchgfx\framework\include\touchgfx\containers' folder:

 

	virtual void setTouchable(bool touch)
	{
		// find first child
		Drawable* child = firstChild;
		
		// child found (!=0)
		while (child)
		{
			// set the touchable property of that child
			child->setTouchable(touch);
			
			// find next sibling
			child = child->nextSibling;
		}
	} 

 

What says @GaetanGodart ,is this proper correction ?

Br JTP

Hello @JTP1 and @PPete 

 

SETTING ELEMENT AS TOUCHABLE

When clicking on a pixel, TouchGFX will check if the first layer is touchable or not, if it isn't, it will check the layer below until he finds the first touchable layer.

Therefore, as @JTP1 said in the post that is marked as best solution, by simply setting a custom container as touchable, you won't be able to click on a button bellow that custom container.

There are many ways of setting an element (custom container or widget) as touchable.

1)
You can do so within the screen.cpp file it is in such as :

 

 

myCustomContainer.setTouchable(true);
button1.setTouchable(true);

 

 

2)
You can also set a custom container directly touchable from his own cpp file (ex. myCustomContainer.cpp) from the initialize function such as:

 

 

void myCustomContainer::initialize()
{
    myCustomContainerBase::initialize();
     setTouchable(true);
}

 

 

3)
You can set an element as touchable by activating the mixin "clickListener" active

GaetanGodart_0-1708598350588.png
This is possible in Designer from within the screen and also from within the custom container if you have a background buy setting the background as ClickListener (or setting all the elements of your custom container that you don't want to be able to click through as clickListener).

4)
Finally, you can set an element as touchable during runtime by calling setTouchable(true) as previously.
Find an example of that in the file attached.

 

SETTING CHILD OF CUSTOM CONTAINER AS TOUCHABLE

If on the other hand you do not want to set the whole container as touchable but you want to set all the elements of the custom container as touchable, @JTP1 's implementation to set all child touchable is great.
Please find an example of this implementation in the same example attached.
The code setting children touchable is directly inside the interaction in the custom container.

I had to change nextSibling by getNextSibling() because the nextSibling attribute is protected.
Other than that it works great!
Thank you for your response.

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)
JTP1
Lead

Hello

Thank you very much for your answer Gaetan.

I must say that my opinion is that if somebody disables Touchable- property from any container (customContainer, Container or even scrollList), all the widgets inside of that container should be disabled also.

But my quick idea of overwriting setTouchable at 'Container.hpp' and set it to affect all of its child seems to be bit problematic with some containers. (for example with scrollList which is based container- class).

So maybe it would be good addtion to add new function to container class (container.hpp) like

 

	virtual void setContainerTouchable(bool touch)
	{	
		// set also the container own Touchable- property
		touchable=touch;
		
		// find first child
		Drawable* child = firstChild;
		
		// child found (!=0)
		while (child)
		{
			// set the touchable property of that child
			child->setTouchable(touch);
			
			// find next sibling
			child = child->nextSibling;
		}
	}  

 

Then setTouchable works like before and with this new function its possible enable or disable container and its child widget with one function call. In same cases it might be useful.

Br JTP