cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a widget manually and iterating through the container

Mayank1
Associate II

Hi there,

I am working on touchGFX for some application. There are some common widgets that need to be added on every screen (Let say there are 10 screens). In this case, I have to add the common widgets on every screen through touchGFX designer. But I don't want that. What I want instead, that there should be one common class which contains all the common widgets. This class may contain functions like setUpScreen(), handleTickEvent(), tearDownScreen() etc.

Now, setUpScreen() does the set up part such as setting up the widgets properties and adding this to the corresponding screen's container. and other methods implemented likewise. E.g :-

class commonWidget

{

void setUpScreen()

{

 xyz.setBitmap(touchgfx::Bitmap(BITMAP_MIN_ICON_ID));

 xyz.setPosition(26, 8, 32, 32);

 xyz.setVisible(false);

add(xyz);

}

};

The problem here is, add(xyz) adds the widget to the commonWidget class container.

But instead this should be added to the current screen container from where this ( setUpScreen() ) method is called/accessed. so that that widget can be drawn on the respective screen.

How I thought to implement this, is as below :

void setupScreen(Container &container)

{

/**** get the first child ****/

 Drawable *widget = container.getFirstChild();

 Drawable *prev = widget;

/*** iterate till the last child ****/

while (widget != nullptr)

{

  prev = widget;

  widget = widget->getNextSibling();

 }

 container.insert(prev, xyz);

}

void ShowWidget(Container &container)

{

while (widget != nullptr)

{

   prev = widget;

   widget = widget->getNextSibling();

 }

prev->setVisible(true);

prev->invalidate();

}

I iterated though the root container of the class, and widget added to the last. and while drawing did the same.

But this also seems to be problematic, as let say we have 10 different common to be added. its difficult to iterate to the exact widget. Also suppose we have some Box type widgets, whose color to be changed at run time, then we cant do that because

Drawable *widget = container.getFirstChild();

this line gives the parent class's pointer, which does not contain properties like setColor(colorType) for example.

Is there any other soultion that can be opted seamlessly.

Thanks in Advance.

2 REPLIES 2
Romain DIELEMAN
ST Employee

Hi,

Did you improve your process or found a better way ?

/Romain

Hi Romain,

No, not improved. try some solutions but failed.