cancel
Showing results for 
Search instead for 
Did you mean: 

Which type of the button can I achieve the job?

Jtron.11
Senior

I am looking for a button implementation for the Setting button way to achieve the steps:

1. At the start, the Setting button is in OFF state on screen1

2. Press once, the interaction will change to setting screen for specific settings, this screen will have 2 clicks buttons CONFIRM and CANCEL. 

a.  If the settings is done and CONFIRM button is clicked, the settings are saved and return back to screen1 the Setting button should show the ON state.

b. If the cancel button is clicked, there will be no saving and return back to screen1 with the Setting button is in OFF state

3. If the Setting was in ON state after successfully CONFIRM the setting, press one more time, the Setting button should go back to OFF state, and NO screen changing.

I am be able to use the toggle button to implement the Setting button, and by create the interaction to do the screen switch from the first press, and don't call the interaction on the second press to achieve the OFF, Switch Screen, CONFIRM, Go back to Screen1, with Setting Button On state.

However, I don't know how to handle the Setting Button State OFF when the cancel button is clicked in the Setting Screen.

3 REPLIES 3
JohanAstrup
ST Employee

Hello @Jtron.11.

The state of toggle buttons can be controlled by calling forceState(bool state). However, from your description, it seems you already have this working. You mentioned that you can return to screen1 with the setting button in the ON state - why can't you use the same approach to set it to OFF?

Could you share your project or some code snippets to help clarify the problem?


Best regards,
Johan

I have done it, but I don't know if that is the best way and if that is the logic way to use the toggle button to do it.

Basically, first clicked, go to the setup virtual function and call interaction to trigger screen transition after call virtual function, then on the screen that I jump to has buttons confirm and cancel.  All done correctly.

Second clicked, the toggle button should cancel the mode was set from the first clicked and no screen transition.

What I have done is inn the virtual function called, I just check for the button = false and don't call the interaction.

JohanAstrup
ST Employee

Okay, a better option might be to use a radio button instead of a toggle button then. At least this approach requires less code. I have attached a small example that shows how it could be implemented.

Best regards,
Johan