2022-02-24 09:44 AM
Is there a way to force state for "Button with Label" so that it can behave like "toggle" switch?
Thanks
2022-03-01 01:31 AM
Hello @PPanb.1 ,
There is several ways to achieve what you want to do.
If you really want to use a LabelButton, you can do that easily using a Boolean variable and the "setBitmaps" method :
void ButtonIsPressed() override;
bool toggle = false;
void Screen1View::ButtonIsPressed()
{
toggle = !toggle;
}
void Screen1View::ButtonIsPressed()
{
toggle = !toggle;
if(toggle)
{
buttonWithLabel1.setBitmaps(Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_PRESSED_ID), Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_PRESSED_ID));
}
else
{
buttonWithLabel1.setBitmaps(Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_ID),Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_ID));
}
buttonWithLabel1.invalidate();
}
In any case, I strongly recommend you to use either a ToggleButton or a FlexButton.
With the FlexButton widget, you can add a Text on it, and you can modify the trigger to "Toggle" In TGFXDesigner.
Hope that this helped you,
/Yoann
2022-03-01 06:57 AM
Thank you for your solution and recommendation.