Browse Source

Fixed a bug where ComboBoxes with no itmes wouldn't show the "no choices" entry

tags/2021-05-28
hogliux 8 years ago
parent
commit
3bb8dbe3ac
1 changed files with 24 additions and 13 deletions
  1. +24
    -13
      modules/juce_gui_basics/widgets/juce_ComboBox.cpp

+ 24
- 13
modules/juce_gui_basics/widgets/juce_ComboBox.cpp View File

@@ -530,24 +530,35 @@ static void comboBoxPopupMenuFinishedCallback (int result, ComboBox* combo)
void ComboBox::showPopup()
{
PopupMenu::MenuItemIterator iterator (currentMenu, true);
const int selectedId = getSelectedId();
PopupMenu noChoicesMenu;
const bool hasItems = (currentMenu.getNumItems() > 0);
while (iterator.next())
if (hasItems)
{
PopupMenu::Item &item = iterator.getItem();
PopupMenu::MenuItemIterator iterator (currentMenu, true);
const int selectedId = getSelectedId();
if (item.itemID != 0)
item.isTicked = (item.itemID == selectedId);
while (iterator.next())
{
PopupMenu::Item &item = iterator.getItem();
if (item.itemID != 0)
item.isTicked = (item.itemID == selectedId);
}
}
else
{
noChoicesMenu.addItem (1, noChoicesMessage, false, false);
}
currentMenu.setLookAndFeel(&getLookAndFeel());
currentMenu.showMenuAsync (PopupMenu::Options().withTargetComponent (this)
.withItemThatMustBeVisible (getSelectedId())
.withMinimumWidth (getWidth())
.withMaximumNumColumns (1)
.withStandardItemHeight (label->getHeight()),
ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this));
PopupMenu& menuToShow = (hasItems ? currentMenu : noChoicesMenu);
menuToShow.setLookAndFeel (&getLookAndFeel());
menuToShow.showMenuAsync (PopupMenu::Options().withTargetComponent (this)
.withItemThatMustBeVisible (getSelectedId())
.withMinimumWidth (getWidth())
.withMaximumNumColumns (1)
.withStandardItemHeight (label->getHeight()),
ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this));
}
//==============================================================================


Loading…
Cancel
Save