cancel
Showing results for 
Search instead for 
Did you mean: 

How can we iterate containers inside a container (i.e. nested container)

BParh.1
Senior III

Suppose I create a container called 'containers' which has further other containers called container1, container2 and container3.

Now how can I iterate the inside containers from the outer container? Is it even possible in TouchGFX?

My intention is to control whether to set particular container visible or invisible.

1 REPLY 1
Alexandre RENOUX
Principal

Hi BParh.1,

This one is a bit tricky but here is a code example :

void Screen1View::containerIterate()
{
    Drawable* d = topContainer.getFirstChild(); // get the first child inside your top container. This child is also a container.
    // Important to notice that d is a Drawable so you need to cast it to the widget type you need. See below with the Box widget
    while (d) // loop through the Drawables
    {
        // Here we just have some Box inside a (child)container that we set in Black as an example. But you can have other widgets inside your (child)container
        Box* boxChild;
        boxChild = (Box*)d->getFirstChild();
        boxChild->setColor(Color::getColorFromRGB(0x00, 0x00, 0x00));
        d = d->getNextSibling(); // This is how you can get the next child inside the top container
    }
    topContainer.invalidate(); // Do not forget to invalidate
}

For your specific request, that is to control if a container is visible or not, here is the code sample :

void Screen1View::containerIterate()
{
    Drawable* d = topContainer.getFirstChild();
    while (d)
    {
        d->setVisible(!d->isVisible());
        d = d->getNextSibling();
    }
    topContainer.invalidate();
}

Hope it helps,

/Alexandre