A Way To Forced state for "Button with Label"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-24 9:44 AM
Is there a way to force state for "Button with Label" so that it can behave like "toggle" switch?
Thanks
- Labels:
-
TouchGFX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-03-01 1: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 :
- In TouchGFXDesigner, create an interaction for your button, which calls a virtual function every time the button is pressed.
- Override this virtual method in Screen1View.hpp.
void ButtonIsPressed() override;
- Create a Boolean variable in Screen1View.hpp.
bool toggle = false;
- In Screen1View.cpp, declare your virtual function, and toggle your Boolean variable every time the method is called.
void Screen1View::ButtonIsPressed()
{
toggle = !toggle;
}
- Then, depending on the value of your variable, display either the "pressed button" Bitmap or the "released button" one, with the setBitmap(Bitmap,Bitmap) method. Finally, don't forget to call invalidate.
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
ST Software Developer | TouchGFX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-03-01 6:57 AM
Thank you for your solution and recommendation.
