ComboBoxes flicker when you open a ComboBox while a first ComboBox is already opened. The reason for this is that the PopupMenu is opened async, then dismissed in HidePopup, and then opened again in the mouseUp of the ComboBox. Showing the ComboBox in sync fixed the flickering problem, but might cause other problems?
Use case:
1 - Mouse down a ComboBox -> showPopup() causes async popup menu show.
2 - Mouse down another ComboBox -> showPopup() causes async popup menu show.
3 - The first ComboBox closes and calls comboBoxPopupMenuFinishedCallback -> hidePopup() is called and all
PopupMenus are dismissed (which should only be the first one).
4 - Mouse up on the second ComboBox -> Opens the second ComboBox again causing the flickering.
JUCE CODE:
void ComboBox::showPopup()
{
PopupMenu menu;
menu.setLookAndFeel (&getLookAndFeel());
addItemsToMenu (menu);
menu.showMenuAsync (PopupMenu::Options().withTargetComponent (this)
.withItemThatMustBeVisible (getSelectedId())
.withMinimumWidth (getWidth())
.withMaximumNumColumns (1)
.withStandardItemHeight (label->getHeight()),
ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this));
}
void ComboBox::hidePopup()
{
if (menuActive)
{
menuActive = false;
PopupMenu::dismissAllActiveMenus();
repaint();
}
}
static void comboBoxPopupMenuFinishedCallback (int result, ComboBox* combo)
{
if (combo != nullptr)
{
combo->hidePopup();
if (result != 0)
combo->setSelectedId (result);
}
}
Video: