Browse Source

Added a LookAndFeel method to customise the options of a ComboBox's PopupMenu

tags/2021-05-28
hogliux 7 years ago
parent
commit
64be913fa2
4 changed files with 16 additions and 6 deletions
  1. +9
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp
  2. +1
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h
  3. +4
    -6
      modules/juce_gui_basics/widgets/juce_ComboBox.cpp
  4. +2
    -0
      modules/juce_gui_basics/widgets/juce_ComboBox.h

+ 9
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp View File

@@ -1199,6 +1199,15 @@ void LookAndFeel_V2::positionComboBoxText (ComboBox& box, Label& label)
label.setFont (getComboBoxFont (box)); label.setFont (getComboBoxFont (box));
} }
PopupMenu::Options LookAndFeel_V2::getOptionsForComboBoxPopupMenu (ComboBox& box, Label& label)
{
return PopupMenu::Options().withTargetComponent (&box)
.withItemThatMustBeVisible (box.getSelectedId())
.withMinimumWidth (box.getWidth())
.withMaximumNumColumns (1)
.withStandardItemHeight (label.getHeight());
}
//============================================================================== //==============================================================================
Font LookAndFeel_V2::getLabelFont (Label& label) Font LookAndFeel_V2::getLabelFont (Label& label)
{ {


+ 1
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h View File

@@ -193,6 +193,7 @@ public:
Font getComboBoxFont (ComboBox&) override; Font getComboBoxFont (ComboBox&) override;
Label* createComboBoxTextBox (ComboBox&) override; Label* createComboBoxTextBox (ComboBox&) override;
void positionComboBoxText (ComboBox&, Label&) override; void positionComboBoxText (ComboBox&, Label&) override;
PopupMenu::Options getOptionsForComboBoxPopupMenu (ComboBox&, Label&) override;
//============================================================================== //==============================================================================
void drawLabel (Graphics&, Label&) override; void drawLabel (Graphics&, Label&) override;


+ 4
- 6
modules/juce_gui_basics/widgets/juce_ComboBox.cpp View File

@@ -545,12 +545,10 @@ void ComboBox::showPopup()
menu.addItem (1, noChoicesMessage, false, false); menu.addItem (1, noChoicesMessage, false, false);
} }
menu.setLookAndFeel (&getLookAndFeel());
menu.showMenuAsync (PopupMenu::Options().withTargetComponent (this)
.withItemThatMustBeVisible (getSelectedId())
.withMinimumWidth (getWidth())
.withMaximumNumColumns (1)
.withStandardItemHeight (label->getHeight()),
auto& lookAndFeel = getLookAndFeel();
menu.setLookAndFeel (&lookAndFeel);
menu.showMenuAsync (lookAndFeel.getOptionsForComboBoxPopupMenu (*this, *label),
ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this)); ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this));
} }


+ 2
- 0
modules/juce_gui_basics/widgets/juce_ComboBox.h View File

@@ -376,6 +376,8 @@ public:
virtual Label* createComboBoxTextBox (ComboBox&) = 0; virtual Label* createComboBoxTextBox (ComboBox&) = 0;
virtual void positionComboBoxText (ComboBox&, Label& labelToPosition) = 0; virtual void positionComboBoxText (ComboBox&, Label& labelToPosition) = 0;
virtual PopupMenu::Options getOptionsForComboBoxPopupMenu (ComboBox&, Label&) = 0;
}; };
//============================================================================== //==============================================================================


Loading…
Cancel
Save