2025-01-30 07:44 AM
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.
2025-02-06 02:32 AM
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,
2025-02-06 05:34 AM
"I have made a project where I try this and it compiles"
Please share that project @JG_UNI