cancel
Showing results for 
Search instead for 
Did you mean: 

Array of Images

daho
Associate

Hello,

I'm working with a set of 7 images. Based on specific external input, I aim to toggle the visibility of these images - making certain images visible and others invisible.

When I manipulate the visibility of each image individually using the following code, it operates as expected:

Image_1.setVisible(true);
Image_2.setVisible(false);
// ... [and so on]
Image_7.setVisible(false);
Image_1.
invalidate();
Image_2.
invalidate();
// ... [and so on]
Image_7.
invalidate();

However, when I attempt to streamline this process by storing the images in an array and then cycling through that array using a for loop, the expected behavior isn't observed:

touchgfx::Image Images[7];

Images[0] = Image_1;
Images[1] = Image_2;
// ... [and so on]
Images[6] = Image_7;

for (int i = 0; i < 7; i++) {
if (i == numActiveImages) {
Images[i].setVisible(true);
Images[i].invalidate();
} else {
Images[i].setVisible(false);
Images[i].invalidate();
}
}

 

Could someone shed light on this behavior or provide a potential solution?

Thank you in advance.

 

 

 

 

 

 

 

2 REPLIES 2
JHERI
Senior

Hello

I too am after doing the same as you posted, I'm not sure why the designer does not allow you to create an array of objects (widgets) placed on each screen in touchgfx ??

This would be the logical and most efficent way of coding for multiple of the same widgets

I am also a little amazed that no one has replied as to how to acheive this request ??

maybe it can not be done ?? it would be a massive draw back to touchgfx if this is the case

here hoping someone replies to your post

regards

 

Hi, I would also like to have a selection of images and have just one visible at a time. I was wondering if this can be done with containers, but so far can not see how.

Its been almost a year since this was looked at. Any updates?

Lance.