2025-01-04 04:38 PM
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 :
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
2025-01-04 10:32 PM - edited 2025-01-04 10:49 PM
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 );
2025-01-05 03:35 AM
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 ?
2025-01-05 04:40 AM
"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
"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.
"Do we absolutely have to create a new class to use this function ?"
I think so, yes.
2025-01-08 02:57 AM
Hello,
You can use the functions getFirstChild and then getNextSibling to loop through all the widgets in a container :
Regards,
2025-01-08 04:01 AM
getFirstChild() returns a * Drawable which does not provide a way to change Alpha.
2025-01-08 05:20 AM
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,
2025-01-09 04:46 AM
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
2025-01-09 05:16 AM
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,