2024-05-06 11:21 PM - last edited on 2024-05-08 12:20 AM by LouisB
I am not very experienced with CPP or TouchGFX. I have created a Custom Container with a TextArea, a ToggleButton, and a couple of ScrollWheels. I have created a list layout, and used .add() to add two new instances of the Custom Container to my list at run time. The purpose is to create a list of alarms with a title, and some settable parameters for the User to set and save. I have figured out how to load the saved values into the ToggleButton and ScrollWheels from the values saved in the Model in setupScreen.
listLayoutAlarmList.setWidthHeight(0,0); //Compensates for the list height that is set to 200 by the designer
listLayoutAlarmList.setDirection(touchgfx::SOUTH);
for(int i=0;i<2;i++)
{
CustomContainerAlarm *ac = new CustomContainerAlarm();
ac->setListElements(i, (int)!presenter->getAlarmEnable(i), presenter->getAlarmPriority(i), presenter->getLimitF(i), presenter->getAlarmRelay(i));
listLayoutAlarmList.add(*ac);
}
listLayoutAlarmList.invalidate();
But now I need to save the current settings from each alarm (Custom Container) back to the Model during tearDownScreen.
I thought I could get the first Child of the ListLayout, and step through to the last Child by incrementing the pointer. But getFirstChild returns a Drawable *. How do I use this to get the TextArea (so I can tell which alarm I have) from inside the CustomContainer it must be pointing to, then each of the other elements in the CustomContainer so I can for example save whether the ToggleButton is on or off.
Then how do I move to the next list layout element, and how do I tell when I am at the end?
Solved! Go to Solution.
2024-05-07 08:58 PM
Brilliant thanks.
2024-05-07 07:21 AM
Hello @CYBR,
When you add code to your post, please format your code for better readability by clicking on this icon:
You can scroll through your list by calling the first item with listLayout1.getFirstChild(). Then you need to use a while loop while the nextSibling is not NULL( = end of the childs list).
Inside the while loop, to access to your container data/function, you will need to cast your current element to your CustomContainer.
Drawable * next = (listLayout1.getFirstChild());
TypedText* containerText;
CustomContainer* current;
while (next != NULL)
{
current = (CustomContainer*) next;
containerText = current->getTextArea();
doMyfunction(containerText);
next = next->getNextSibling();
}
To get the customContainer's text area content, you will need to add a new function to your custom container:
const TypedText& getTextArea() const{
return textArea1.getTypedText();
}
with textArea1 the name of your text area.
I hope it helps,
Regards.
2024-05-07 08:58 PM
Brilliant thanks.