cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to dynamically add GUI-Objects?

t.albrecht
Associate II

Hi folks,

I'm trying to add a set of objects (in this case: a circle) to the GUI, as soon as the user presses a button. Therefore, I'm trying to execute the following code on the button press:

touchgfx::Circle circle2;
touchgfx::PainterRGB565 circle2Painter;
 
circle2.setPosition(309, 136, 90, 90);
circle2.setCenter(45, 45);
circle2.setRadius(40);
circle2.setLineWidth(10);
circle2.setArc(0, 280);
circle2.setCapPrecision(180);
 
circle2Painter.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
circle2.setPainter(circle1Painter);
 
add(circle2);
circle2.invalidate();

As soon as the button is pressed, the system won't react anymore. The "clicked_button" bitmap is displayed, nothing else happens.

What am I missing out? Is it actually possible to add GUI-objects at runtime? Is the buffer to small?

Thanks for your help!

13 REPLIES 13

@Martin KJELDSEN​ 

I just discovered that we can't dynamically allocate space for a screen object (using new). The compiler does notcode aborts on the new.

This is unfortunate for us because we will not always know what will be on our screens prior to runtime. Looks like we may just need to statically declare all possible objects.

I noticed that your comment says "it's possible to add objects at runtime as long as they are statically allocated (default)"

What do you mean "(default)"?

Is there a way to set it up for true dynamic allocation?

ari_v2
Senior

Hi,

I'm using TouchGFX 4.17. Since 3 years passed from this discussion I would like to ask again:

Is it possible to to add objects at runtime, dynamically using the heap, or they must be statically allocated at compile time?

Thank you,

Ari

Hi,

They still must be statically allocated at compile time so you must know/guess the max amount of element you could add at runtime.

/Romain

ari_v2
Senior

Thanks