cancel
Showing results for 
Search instead for 
Did you mean: 

Array of Widgets

JVALL.1
Associate III

To customize a TouchGFX application created with the TouchGFXDesigner,

I am trying to create a screen with many circles that can be updated, for that I use an array to store the circles and the circles painters, but then when I try to access the methods of the widgets in the array doesn't seem to work.

A simple example could be:

in "screen1View.hpp" I declare an array to store the circles and the painters inside the view class:

touchgfx::Circle circleArray[] = {circle1, circle2, ...};
touchgfx::PainterRGB565 painterArray[] = {circle1Painter, circle2Painter};

Then in "screen1View.cpp" I try to access the widgets in the array to change the color:

void Screen1View::action()
{
	// ...
	painterArray[0].setColor(touchgfx::Color::getColorFromRGB(255, 0, 0));
	circleArray[0].invalidate();
}

But this doesn't work, the color is not updated.

But instead if I directly use the widget instance like this:

void Screen1View::action()
{
	// ...
	
	circle1Painter.setColor(touchgfx::Color::getColorFromRGB(255, 0, 0));
	circle1.invalidate();
}

Then the color gets updated

I am not very experienced in C++ so could this be related to the language?

or can this be achieved in some other way?

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief II

Maybe this help you c++ - Passing an array of pointers to a Class Object - Stack Overflow

and cleaner is in hpp only declare without = {}... and assign in setupscreen.

View solution in original post

2 REPLIES 2
MM..1
Chief II

Maybe this help you c++ - Passing an array of pointers to a Class Object - Stack Overflow

and cleaner is in hpp only declare without = {}... and assign in setupscreen.

Yeah, using an array of pointers to objects instead of an array of objects works.

Thanks