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

3 REPLIES 3
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.