cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-DISCO, Button

AD�?b
Senior

How can I disable the TRIGGER / Click button by switching the TRIGGER / Toggle button?

13 REPLIES 13
Karl Yamashita
Lead II

I believe it's setTouchable() for a regular button

For example to disable the touch on a toggle button

toggleButton1.setTouchable(false);

If you find my answers useful, click the accept button so that way others can see the solution.

Hello thank you!

I have a "ButtonOffOn" toggle button. I have a "ButtonNext" button that changes the screen. I want the button "ButtonNext" to be locked while the "ButtonOffOn" button is switched on until the "ButtonOffOn" button is switched again.

I checked your suggestion but disables the "ButtonOffOn" button.

"ButtonOffOn" = On -> "ButtonNext" closed

"ButtonOffOn" = Off -> "ButtonNext" is active

How to do it?

I suppose you could do something like this: in Designer you create 2 interactions. The first one calls a new function when the button "ButtonNext" is clicked. The other interaction changes the screen when an hardware button is clicked. This is a fake button we use in order to generate the go to screen 2 transition function and use it in our code.0690X00000DC603QAD.png

Then I added this in Screen1View.cpp

void Screen1View::functionNextOrStay()
{
    if (ButtonOnOff.getState() == TRUE)         // getState returns TRUE when On 
    {
        application().gotoScreen2ScreenNoTransition();
    }
}

Tell me if this enough for what you need, I did not need to use setTouchable() since it does not influence the result.

0690X00000DC63qQAD.gif

/Romain

Thank you for the offer. This is not what I mean but I will finally answer when I try.

I got that I deactivate another button with the button but I stopped to return to the active one

Karl Yamashita
Lead II

I made a quick tutorial for what you want now that i know exactly what you're trying to do. https://youtu.be/CSQkVLIN22k

There is a link to another video i made before for those who are interested. The toggle button on screen1 disables a button on screen2.

If you find my answers useful, click the accept button so that way others can see the solution.

Hi Karl!

Yes, this is it. I still have to check how it will work when the OFF / ON button is Flex Button.

Well a flex button doesn't have a on/off state but you can still trigger off that button. So for that flex button, the C++ code will check the current touchable state of the buttonNext and toggle the touchable state to the opposite.

if(buttonNext.isTouchable() == true)
{
    buttonNext.setTouchable(false);
    buttonNext.setLabelColor(touchgfx::Color::getColorFrom24BitRGB(255,0,0));
    buttonNext.setLabelColorPressed(touchgfx::Color::getColorFrom24BitRGB(255,0,0));
    buttonNext.invalidate();
}
else
{
    buttonNext.setTouchable(true);
    buttonNext.setLabelColor(touchgfx::Color::getColorFrom24BitRGB(255,255,255));
    buttonNext.setLabelColorPressed(touchgfx::Color::getColorFrom24BitRGB(255,255,255));
    buttonNext.invalidate();
}

If you find my answers useful, click the accept button so that way others can see the solution.

Thank you Karl!

Everything works as you wrote. Toggle Button has the function APPERANCE / Pressed. If I didn't choose it, it didn't work as I wanted. As I chose it worked correctly. For aesthetic reasons, I wanted to use the Flex Button. Although I set up TRIGGER / Togle did not work as I wanted. With the last sent code it works as I wanted. Thank you very much.

You're welcome! I'm glad I was able to help.

If you find my answers useful, click the accept button so that way others can see the solution.