cancel
Showing results for 
Search instead for 
Did you mean: 

How to use my own classes with TGFX Design Studio

GDare.1
Associate II

Hi!

I use a lot of rounded coloured boxes for my implementation and I was looking at writing custom classes to handle this. EG: My own circle class with a built in painter to remove the confusing use of the painter. Can I add this to TGFX Design Studio so that when I generate my files, it will generate with my own circle?

#ifndef MYCIRCLE_HPP
#define MYCIRCLE_HPP
#include <touchgfx/widgets/canvas/Circle.hpp>
#include <touchgfx/widgets/canvas/PainterRGB565.hpp>
 
namespace mygfx {
    class Circle : public touchgfx::Circle {
    public:
        Circle()
        {
            setPainter(_painter);
        }
        explicit Circle(touchgfx::colortype initColour)
        {
            _painter.setColor(initColour);
            setPainter(_painter);
        }
 
        void setColor(touchgfx::colortype colour)
        {
            _painter.setColor(colour);
        }
 
        touchgfx::colortype getColor() const
        {
            return _painter.getColor();
        }
 
    private:
        touchgfx::PainterRGB565 _painter;
    };
}
#endif //MYCIRCLE_HPP

The end goal is to make a box with rounded border that implements this custom class for a less polluted member access (Instead of accessing all assets when I need to change colour, I would just update the box). The issue is when we generate a change from the software, I want it to use my "cleaned up" classes.

Is this possible?

TIA :)

3 REPLIES 3
Yoann KLEIN
ST Employee

Hello @GDare.1​ ,

Unfortunately it is not possible to change the code generation in TouchGFX to generate your own Widget.

But you could modify the existing widget or even create a Custom Widget.

Then you would be easily able to use your custom Circle class.

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX

Hi Yoann, Is the suggestion here that if I write a custom widget (as you have linked), I can have the design studio generate using this class? Given my example inherits touchgfx::Circle, which in turn has an inheritance chain down to touchgfx::Widget, wouldn't this be the same as if I wrote the whole circle implementation again and inherited widget exclusively?

I have only recently started working on the tgfx side of the project and come from a more programmatic background. I just see a lot of optimisations we can make by creating custom classes to better fit our application but all of the layout and design is done from inside tougfx designer, so I am trying to find a middle ground.

Yoann KLEIN
ST Employee

Yes you are right, if you create a CustomWidget and inherit from touchgfx::Widget, your new Circle class will just be considered as a new Widget and won't be related to the base Circle class.

But I don't really understand why is that an issue for you ? You can also make your new custom Circle inherit from the basis Circle class (and then chained-inheritance from the Widget class) and only redefine the methods or attributes you want in your derived custom Circle class.

TouchGFX Designer won't know about this new class, but you can add the new widget on the screen through the code, like this.

Let me know if you have additional questions.

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX