2022-10-14 05:38 PM
Created this function where want to pass a flex button as a parameter to the function and change it's text color.
Changing the text color directly using the object name works, but when I pass the button to the function I cannot get it work
Any help very much thankful
void scr_MainView::setButton(touchgfx::AbstractButtonContainer &button)
{
// works
// directly setting color of this button
Float2Button.setTextColors(Color::getColorFromRGB(125, 125, 45), Color::getColorFromRGB(145, 145, 145));
// error
// button passed to function
&button.setTextColors(touchgfx::Color::getColorFromRGB(145, 145, 145), touchgfx::Color::getColorFromRGB(145, 145, 145));
}
2022-10-15 02:14 AM
You miss use reference, right is
// button passed to function
button.setTextColors(touchgfx::Color::getColorFromRGB(145, 145, 145), touchgfx::Color::getColorFromRGB(145, 145, 145));
2022-10-15 02:44 AM
Hi @MM..1
// button passed to function
button.setTextColors(touchgfx::Color::getColorFromRGB(145, 145, 145), touchgfx::Color::getColorFromRGB(145, 145, 145));
It makes not difference whether I have "&" or not. There doesn't seems to be any reference to setTextColors method
The button parameter is AbstractButtonContainer and a flexbutton on the screen
F3 shows me this
touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::ClickButtonTrigger > > Float2Button;
void scr_MainView::setButton(touchgfx::AbstractButtonContainer &button)
2022-10-15 03:27 AM
Simple use same types or change type online
2022-10-24 04:46 AM
Hello WhyIsThisSo,
I think you'll need to const cast your flexButton to be able to call the setTextColors() function with it. Something like this would work :
void Screen1View::changeColor(touchgfx::TextButtonStyle< touchgfx::BoxWithBorderButtonStyle< touchgfx::ClickButtonTrigger>> &button)
{
button.setTextColors(touchgfx::Color::getColorFromRGB(255, 0, 0), touchgfx::Color::getColorFromRGB(0, 255, 0));
}
void Screen1View::clickFlexButton() // function to be declared on designer and triggered when clicked on the flexButton
{
changeColor(const_cast <touchgfx::TextButtonStyle< touchgfx::BoxWithBorderButtonStyle< touchgfx::ClickButtonTrigger > >&> (myFlexButton));
}
/Osman