2022-08-04 03:43 AM
I've made some modifications to a standard widget by extending the widget class, for example to the Slider widget.
I create a class MySlider that extends the Slider and override some of the methods. To use this new created class I then modify the ViewBase.hpp file to include the new header and modify the declaration from touchgfx::Slider slider; to whatever::MySlider slider;
With this approach it works but the ViewBase.hpp it's not supposed to be modified, also it gets overwritten every time code is generated from the TouchGFX Designer.
Is there any other method to use the new class without changing the BaseView.hpp and only modifying the user files?
I've tried in the setupScreen() method to cast the slider to my new class:
void ScreenView::setupScreen()
{
slider = (MySlider) slider;
}
But this doesn't work and the methods from the standard class are still used.
2022-08-04 05:47 AM
Why you dont place it into view.hpp
and
void ScreenView::setupScreen()
{
ScreenViewBase::setupScreen();
myslider1.xxxx=...
add(myslider1);
}
2022-08-04 08:19 AM
I use the Designer with the standard Slider, for things like position select images, then my modified slider just changes some logic to update the value. With your suggestion once I make a change in the designer I would need to look at the generated code in the ViewBase.hpp and copy it to View.hpp.
Yes I guess I could write a script that took care of that but I just was wondering if there is a way to just somehow change the type of the slider to my subclass so that my modified methods are used but keep using the generated part.
2022-08-04 08:52 AM
c++ - extending an object of a basic class to an object of a complex class - Stack Overflow
by this in setup you need remove old slider ... extent to new ... add back , but ...
2022-08-05 02:10 AM
I've been doing some research and seems in c++ is not possible to change the type of an object to a subclass.
So I resorted to declare an object of my modified class in View.hpp and initialize it in the constructor in View.cpp, like you first mentioned, copying the relevant code from ViewBase.cpp, then remove the standard widget and add mine, this way works but is somewhat tedious, you have to declare new callback and callback handler because the ones in ViewBase are private, and you have to update almost everything every time a change is made in the designer.
Thanks for the help
2022-08-05 02:10 AM
-
2022-08-05 03:14 AM