Help! Button is so sloooooow to react :(

I’m looking for any way to solve a GUI niggle.

So I have two groups of buttons (16 each) that are placed on top of each other so that I can switch between which group to show when I click a button.

The show/hide button is a DrawableButton so that it renders several different images for on, down, over etc.

Functionally everything works great but man the operation is so slow that the show/hide button doesn’t appear like it is being clicked - the images are not rendered quick enough. This seems like such a simple task but I cannot find a way to improve the responsiveness.

here is the offending code that causes life for the show/hide button to be slow:

void ButtonAttachmentUpdaterService::ShowEncoderSelectButtons()
{
	stepButtons->setVisible(false);
	selectorButtons->setVisible(true);
}

void ButtonAttachmentUpdaterService::ShowGateButtons()
{
	stepButtons->setVisible(true);
	selectorButtons->setVisible(false);
}

As soon as I comment out the above calls to setVisible the button responds like lightning and all is well. Is there any way I can optimize this behaviour so that it does not impact the buttons painting tasks?

UPDATE

void ButtonAttachmentUpdaterService::ShowEncoderSelectButtons()
{
    for(auto& button: stepButtons->stepButtons)
    {
        button->setVisible(false);
    }

    for (auto& button : selectorButtons->stepButtons)
    {
        button->setVisible(true);
    }
}

void ButtonAttachmentUpdaterService::ShowGateButtons()
{
    for (auto& button : stepButtons->stepButtons)
    {
        button->setVisible(true);
    }

    for (auto& button : selectorButtons->stepButtons)
    {
        button->setVisible(false);
    }
}

I tried the above and was surprised to discover that it made things quite a bit snappier! I would not have guessed that. It’s an improvement but I would welcome any further optimization strategies :wink:

UPDATE 2

Ok, amazingly this improved things even more - to the point that i’m pretty satisfied

void ButtonAttachmentUpdaterService::ShowEncoderSelectButtons()
{
	for(auto i = 0; i < 16; ++i)
	{
		selectorButtons->stepButtons[i]->setVisible(true);
		stepButtons->stepButtons[i]->setVisible(false);
	}
}

void ButtonAttachmentUpdaterService::ShowGateButtons()
{
	for (auto i = 0; i < 16; ++i)
	{
		selectorButtons->stepButtons[i]->setVisible(false);
		stepButtons->stepButtons[i]->setVisible(false);
	}
}