cancel
Showing results for 
Search instead for 
Did you mean: 

Change Alpha on each widgets of container

COSEBE
Senior

Hi,

I have a container with buttons, images and text (around 30).

I would like to change the alpha from 255 to 128 of each widget inside the container.

On the documentation, it says it it possible with container with FadeAnimator in Mixins :

COSEBE_0-1736037012973.png

https://support.touchgfx.com/docs/development/ui-development/ui-components/containers/container#properties

but I think it is a mistake in the documentation.

So, without this feature, what is the best way to change all the alpha value of each widget in a container ?

If the function forEachChild (https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_container#function-foreachchild) is recommended, can I have a link of an exemple program using this function or a zip file with a test program with this feature ?

Regards,

Sébastien

8 REPLIES 8
ferro
Senior III

Hi @COSEBE ,

Step 1

class DoThisToEveryChild : public GenericCallback< Drawable & >
{
	virtual void execute ( Drawable & d ) override final
	{
		// user code here e.g.
		// d.setVisible ( false );
	}
	
	virtual bool isValid () const override final
	{
		return true;
	}
};

Step 2

DoThisToEveryChild doThis {};
     
// now 'DoThisToEveryChild::execute ()' will be called for every child
ticks.forEachChild ( & doThis );
 

https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/get-each-items-in-a-container-and-change-item-attribute/m-p/155681/highlight/true#M8908

 

COSEBE
Senior

Hi ferro,

Thank you for your answer, but I already see your 2-step code in the community, but I still do not understand, because I am not professional in C++.

I do not understand where to put the step 1 code, what is "override final", what is the goal of isValid method.

In step 2 code, where ticks come from ? is it the refresh tick ? if I want to change Alpha on each widget in container, I have to call myContainer.forEachChild(& doThis); ?

Do we absolutely have to create a new class to use this function ?

 

"what is "override final", what is the goal of isValid method"

Have a look into \touchgfx\Callback.hpp 

https://stackoverflow.com/questions/29412412/does-final-imply-override

ferro_0-1736080258667.png

 

"I do not understand where to put the step 1 code."

Sorry about my previous confusing reply. Example attached using forEachChild(). But only Y position of all children of container is changing.

I see that setAlpha() is not member of Drawable. Hm.. Not sure what to do now. Seems you need to set alpha for each button individually.

ferro_1-1736080334940.png

 

"Do we absolutely have to create a new class to use this function ?"

I think so, yes.

 

GaetanGodart
ST Employee

Hello,

You can use the functions getFirstChild and then getNextSibling to loop through all the widgets in a container :

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Hi @GaetanGodart 

getFirstChild() returns a  * Drawable which does not provide a way to change Alpha.

You are right, I did not really think of this.

 

@COSEBE I have modified Ferro's example to make it so that every widget in the container is set invisible when we click on the button (find the project attached). However, as he said, since it returns a drawable, the method setAlpha is not accessible.
Could it be enough to set the whole container's alpha value instead?

 

"
I would like to change the alpha from 255 to 128 of each widget inside the container.
On the documentation, it says it it possible with container with FadeAnimator in Mixins :
"
I think it says that you can change the alpha value of the container, not that you can change the value of all the widgets by using the mixin which is the same as doing container.setAlpha(). 
The goal of the mixin is to use it in TouchGFX Designer and to enable smooth fades.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Hi @GaetanGodart ,

Thank you for you code. I have to check it to understand, even if that can solve my problem right now.

So, YES, changing the Alph of the entire container would be easiest for me. This was my first requirement.

But despite the documentation, Mixins FadeAnimator is not possible in a container. This is the reason why I also tag this post as BugReport.

 

The goal of the mixin is to use it in TouchGFX Designer and to enable smooth fades.

How do you do this. I think smooth fades with container is not possible.

Regards,

Sébastien

Hello @COSEBE ,

 

Ok, I understand what you mean now.
I will see with the team if it used to be possible or if we always had this error in the documentation and act accordingly.

If you want more information about the example, don't hesitate.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)