cancel
Showing results for 
Search instead for 
Did you mean: 

Using inheritance to add functionallity of custom container to multiple screens?

JG_UNI
Associate

In the following post the question is asked to add the same functionality to multiple screens: https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/how-to-display-the-same-content-in-different-screen-of-touchgfx/td-p/723711

 

I run into the same issue. Where I want to add the same custom containers to multiple screens. Since there is some interaction with these custom containers (updates for the clock and status bar, but also button interaction with a popup window) I now have to copy the code for this interaction to each corresponding view and presenter.

Would it be possible to make a sort of base class which contains this functionality so that all the screens which need to implement the functions can inherit from this base class?

This would greatly reduce maintenance efforts since the code would not have to be replicated for each screen.

I have made a project where I try this and it compiles however the software crashes when I try load a screen which adds the container to the view.

2 REPLIES 2
LouisB
ST Employee

Hello @JG_UNI ,

There's no out of the box solution for this but you can draw inspiration from the post you mention .

In the baseView add the common container, and add a callback that callback you need . To know how to create callback from the code, you can create an interaction on a screen, generate the code and readapt it (here for a simple button):

// In BaseView.hpp
private:

    /*
     * Callback Declarations
     */
    touchgfx::Callback<BaseView, const touchgfx::AbstractButton&> buttonCallback;

    /*
     * Callback Handler Declarations
     */
    void buttonCallbackHandler(const touchgfx::AbstractButton& src);

 

//
BaseView::BaseView() :
    buttonCallback(this, &BaseView::buttonCallbackHandler)
{
    [...]
    button1.setXY(211, 152);
    button1.setBitmaps(touchgfx::Bitmap(BITMAP_ALTERNATE_THEME_IMAGES_WIDGETS_BUTTON_REGULAR_HEIGHT_50_MEDIUM_ROUNDED_NORMAL_ID), touchgfx::Bitmap(BITMAP_ALTERNATE_THEME_IMAGES_WIDGETS_BUTTON_REGULAR_HEIGHT_50_MEDIUM_ROUNDED_PRESSED_ID));
    button1.setAction(buttonCallback);
    add(button1);
}

void BaseView::buttonCallbackHandler(const touchgfx::AbstractButton& src)
{
    if (&src== &button1)
    {
        //When button1 clicked call virtual function
        //Call function1
        function1();
    }
}

 

Best regards,

 

Louis BOUDO
ST Software Developer | TouchGFX
ferro
Senior III

"I have made a project where I try this and it compiles"

Please share that project @JG_UNI