Skip to main content
AWies.1
Associate III
Feb 19, 2021 2:07 AM UTC
Question

Setting state of toggle button causes click handler to trigger

I am setting the state of a toggle button with forceState(state). I also have an action set up which gets triggered when the button is clicked. Currently I am facing the issue that when I force the state of the button, then I am also getting the action as if the button was clicked. This is completely unnecessary, since I already know which state the button is in. So I have to write some extra code which checks if the action was caused by calling forceState(state) or not. Is there a way to change the behavior, so forceState(state) does not trigger the action or is there a different function for setting the state?

This topic has been closed for replies.

4 replies

Alexandre RENOUX
Visitor II
Feb 22, 2021 2:44 AM UTC

Hello AWies.1,

This is very strange because I don't reproduce your issue. Moreover, if you look at the code of the forceState() function in ToggleButton.cpp, there's nothing related to ClickEvent in the function.

I believe you didn't implement your button correctly.

Can you enclose your UI to this thread ?

/Alexandre

AWies.1
AWies.1Author
Associate III
Feb 23, 2021 3:25 AM UTC

Hello Alexandre,

I investigated further and found that the issue does not occur when calling forceState() but after calling invalidate(). I commented out the invalidate() and did not get the unwanted callback any more. However, I am using dual framebuffer, and leaving out invalidate() made the two framebuffers inconsistent. So this is no solution.

On the UI I did not do anything special. I used the TouchGfx designer for the toggle button and also for defining the click handler.

Alex

Alexandre RENOUX
Visitor II
Feb 23, 2021 3:36 AM UTC

Hello,

Even if your UI is simple (and actually that's what I'm looking for) please enclose your project.

This will save time for both of us :)

/Alexandre

ADepr.1
Associate
Jul 7, 2021 7:46 AM UTC

Any progress on this? How did you solve your issue?