2023-10-19 01:43 AM
Hello,
I read about radio buttons and also checked the tutorial and examples.
As far as it concerns my project a simple radio button is not flexible enough for what I want to do.
I have a set of flex buttons in a screen and I want them to behave as if they were a set of radio buttons.
Testwise I implemented this behaviour in the presenter class myself but I think this is not an elegant solution.
Then I tried it with custom actions and triggers in the way that the screen has an action "reset other buttons" that will be called by an interaction each flex button does have. Another interaction will be triggered the action "reset other buttons" and this interaction I thought should be able to cange the state of the other flex buttons.
I took the idea from the tutorial 5: https://support.touchgfx.com/docs/tutorials/tutorial-05
There you can set the background color of a box from the interaction. But my flex buttons do not show up in the actions drop down menu. I think I am missing the point here / havent understood the full concept?
What ist "the recommended way" to add radiobutton behavior to a set of flex buttons?
btw: it is mentioned in:
https://support.touchgfx.com/docs/development/ui-development/ui-components/buttons/radio-button
but not elaborated on - it just states:
"The Radio Button can be replicated with the Flex Button. A Flex Button is a more configurable button that takes up a bit more RAM in exchange for flexibility."
Can you please help me into the right lane?
Greetinx, Jake
oh, and I am using gfxDesigner V4.21.4 because the brand new version keeps crashing on my WIN10 HP-Elitedesk PC - but I am fine with that, no worries.
Solved! Go to Solution.
2023-10-19 09:01 AM
Hello
I'm not sure about the right way, but like this very simple example you get multiple flexbuttons act like radiobutton group.
Screen1View::Screen1View()
{
flexButton1.setPressed(1);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::flexButton1Clicked()
{
flexButton1.setPressed(1);
flexButton2.setPressed(0);
flexButton3.setPressed(0);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
void Screen1View::flexButton2Clicked()
{
flexButton1.setPressed(0);
flexButton2.setPressed(1);
flexButton3.setPressed(0);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
void Screen1View::flexButton3Clicked()
{
flexButton1.setPressed(0);
flexButton2.setPressed(0);
flexButton3.setPressed(1);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
If you need query form, It is also possible to make custom container which includes the buttons and also functions to set initial state and also set texts for each button when form is needed. Then you can use triggers when user press OK/cancel to get parent window detect that. But thats bit out of what you asked... :D
Br J.T
2023-10-19 09:01 AM
Hello
I'm not sure about the right way, but like this very simple example you get multiple flexbuttons act like radiobutton group.
Screen1View::Screen1View()
{
flexButton1.setPressed(1);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::flexButton1Clicked()
{
flexButton1.setPressed(1);
flexButton2.setPressed(0);
flexButton3.setPressed(0);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
void Screen1View::flexButton2Clicked()
{
flexButton1.setPressed(0);
flexButton2.setPressed(1);
flexButton3.setPressed(0);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
void Screen1View::flexButton3Clicked()
{
flexButton1.setPressed(0);
flexButton2.setPressed(0);
flexButton3.setPressed(1);
flexButton1.invalidate();
flexButton2.invalidate();
flexButton3.invalidate();
}
If you need query form, It is also possible to make custom container which includes the buttons and also functions to set initial state and also set texts for each button when form is needed. Then you can use triggers when user press OK/cancel to get parent window detect that. But thats bit out of what you asked... :D
Br J.T
2023-10-19 09:46 AM
Thank you for the fast reply!
In fact I did nearly the same in my first implementation which looks like:
void ParametersScreenView::Button1Clicked()
{
if (Button1.getPressed() ) {
parActiveParameter = 1;
}
else {
parActiveParameter = 0;
}
Button2.forceState(false);
Button2.invalidate();
...
ButtonN.forceState(false);
ButtonN.invalidate();
...
I was using forceState because I found it in the API.
But your solution with setPressed(0) sounds more to the point, so I changed my code an adopted your solution.
I only was hoping that I could generate the desired behaviour by using the built-in interaction system.
Anyway, nevermind. Your solution ist good and it will do the job.
Beste Greetings, Jake.