2024-11-08 01:28 AM
Hello,
I just noticed that foceState and getState (for toggleButton) are not what i thought they were, until now I used to think that forceState would just simulate the press of a button for being able to press a button from the code, without physically pressing it, and that getState would just return true if the toggle state was pressed and false otherwise,
but I just noticed it's not like that, those are just for swaping the pressed and released states, which is a bit confusing,
my question is, how can i force a state of a toggle button then, imagine im using scroll list so only the elements visible right at the moment in the list exist, and we scroll down, imagine the element 20 is supossed to have a toggle toggled, how do i toggle it from the callback.
This was my best idea, simulating the press and then release of the button, but this just doesn't feel good, there should be an easier way to just press or unpress a button right?
void ProgramsListElement::Set_Favourite(bool fav)
{
m_fav = fav;
ClickEvent event(ClickEvent::PRESSED, m_fav_btn.getX(), m_fav_btn.getY(), 1);
if (m_fav)
{
if (!m_fav_btn.getState())
{
touchgfx_printf("Just forced press on Proba %i\n", m_ref);
event.setType(ClickEvent::PRESSED);
m_fav_btn.handleClickEvent(event);
event.setType(ClickEvent::RELEASED);
m_fav_btn.handleClickEvent(event);
}
}
else if (!m_fav)
{
if (m_fav_btn.getState())
{
touchgfx_printf("Just forced release on Proba %i\n", m_ref);
event.setType(ClickEvent::PRESSED);
m_fav_btn.handleClickEvent(event);
event.setType(ClickEvent::RELEASED);
m_fav_btn.handleClickEvent(event);
}
}
}
Also this code is giving me a lot of troubles.
✌
Solved! Go to Solution.
2024-11-08 01:49 AM - edited 2024-11-08 01:54 AM
Ok I found out that if you create a flexButton and you just set the trigger to toggle, we have the functions getPressed and a setPressed available, which work just as I want to, what i dont get is why this two functions don't exist for toggleButton, but it works.
✌
2024-11-08 01:49 AM - edited 2024-11-08 01:54 AM
Ok I found out that if you create a flexButton and you just set the trigger to toggle, we have the functions getPressed and a setPressed available, which work just as I want to, what i dont get is why this two functions don't exist for toggleButton, but it works.
✌