Skip to main content
JVALL.1
Associate II
July 31, 2022
Solved

Array of Widgets

  • July 31, 2022
  • 2 replies
  • 1105 views

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?

This topic has been closed for replies.
Best answer by MM..1

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.

2 replies

MM..1
MM..1Best answer
Super User
July 31, 2022

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.

JVALL.1
JVALL.1Author
Associate II
July 31, 2022

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

Thanks