cancel
Showing results for 
Search instead for 
Did you mean: 

Add Widgets, line, etc. at run time

JPine.1
Associate II

Hello, is it possible to add for example a line on the canvas at run time? I'm managing to do a log x scale providing the decades separators with a Line object, but my plot could have more than one decade, so i think is a terrible idea to add many lines as i want, and then making each one visible as it is required. So a tried to add lines at run time but i couldn't manange to do it. I didnt expected to work because it's probable that im jumping many layers of TouchGFX.

This part of code was written from me in Screen1View.cpp - void Screen1View::DataDisplay():

touchgfx::Line line4;

touchgfx::PainterRGB565 line4Painter;

line4.setPosition(204, 0, 23, 240);

line4Painter.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));

line4.setPainter(line4Painter);

line4.setStart(0, 240);

line4.setEnd(0, 0);

line4.setLineWidth(4);

line4.setLineEndingStyle(touchgfx::Line::ROUND_CAP_ENDING);

add(line4);

Thank you very much.

1 ACCEPTED SOLUTION

Accepted Solutions
Yoann KLEIN
ST Employee

Hello @JPine.1​ ,

We don't recommend creating and adding widgets on runtime with TouchGFX, because it could result in a lot of memory issues. Something that you could do is create the widget you want to display on the canvas view in the Designer, and then uncheck the "Make visible" checkbox.

Then, in your code, you could simply call the function setVisible(true) to display it on the UI, when you want.

I know that you might sometimes prefer to create dynamically some object in your code, but that's the best option for the moment.

Hope I helped you,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX

View solution in original post

2 REPLIES 2
Yoann KLEIN
ST Employee

Hello @JPine.1​ ,

We don't recommend creating and adding widgets on runtime with TouchGFX, because it could result in a lot of memory issues. Something that you could do is create the widget you want to display on the canvas view in the Designer, and then uncheck the "Make visible" checkbox.

Then, in your code, you could simply call the function setVisible(true) to display it on the UI, when you want.

I know that you might sometimes prefer to create dynamically some object in your code, but that's the best option for the moment.

Hope I helped you,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX
JPine.1
Associate II

Ok, i have done that. Thank you very much!