mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added a drawComboBoxTextWhenNothingSelected() method to ComboBox::LookAndFeelMethods and made the drawing code consistent with drawLabel()
This commit is contained in:
parent
33fb0e9d60
commit
fcecf67ab3
4 changed files with 20 additions and 10 deletions
|
|
@ -1210,6 +1210,21 @@ PopupMenu::Options LookAndFeel_V2::getOptionsForComboBoxPopupMenu (ComboBox& box
|
|||
.withStandardItemHeight (label.getHeight());
|
||||
}
|
||||
|
||||
void LookAndFeel_V2::drawComboBoxTextWhenNothingSelected (Graphics& g, ComboBox& box, Label& label)
|
||||
{
|
||||
g.setColour (findColour (ComboBox::textColourId).withMultipliedAlpha (0.5f));
|
||||
|
||||
auto font = label.getLookAndFeel().getLabelFont (label);
|
||||
|
||||
g.setFont (font);
|
||||
|
||||
auto textArea = label.getBorderSize().subtractedFrom (label.getLocalBounds());
|
||||
|
||||
g.drawFittedText (box.getTextWhenNothingSelected(), textArea, label.getJustificationType(),
|
||||
jmax (1, (int) (textArea.getHeight() / font.getHeight())),
|
||||
label.getMinimumHorizontalScale());
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
Font LookAndFeel_V2::getLabelFont (Label& label)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ public:
|
|||
Label* createComboBoxTextBox (ComboBox&) override;
|
||||
void positionComboBoxText (ComboBox&, Label&) override;
|
||||
PopupMenu::Options getOptionsForComboBoxPopupMenu (ComboBox&, Label&) override;
|
||||
void drawComboBoxTextWhenNothingSelected (Graphics&, ComboBox&, Label&) override;
|
||||
|
||||
//==============================================================================
|
||||
void drawLabel (Graphics&, Label&) override;
|
||||
|
|
|
|||
|
|
@ -369,16 +369,8 @@ void ComboBox::paint (Graphics& g)
|
|||
label->getRight(), 0, getWidth() - label->getRight(), getHeight(),
|
||||
*this);
|
||||
|
||||
if (textWhenNothingSelected.isNotEmpty()
|
||||
&& label->getText().isEmpty()
|
||||
&& ! label->isBeingEdited())
|
||||
{
|
||||
g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
|
||||
g.setFont (label->getLookAndFeel().getLabelFont (*label));
|
||||
g.drawFittedText (textWhenNothingSelected, label->getBounds().reduced (2, 1),
|
||||
label->getJustificationType(),
|
||||
jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
|
||||
}
|
||||
if (textWhenNothingSelected.isNotEmpty() && label->getText().isEmpty() && ! label->isBeingEdited())
|
||||
getLookAndFeel().drawComboBoxTextWhenNothingSelected (g, *this, *label);
|
||||
}
|
||||
|
||||
void ComboBox::resized()
|
||||
|
|
|
|||
|
|
@ -378,6 +378,8 @@ public:
|
|||
virtual void positionComboBoxText (ComboBox&, Label& labelToPosition) = 0;
|
||||
|
||||
virtual PopupMenu::Options getOptionsForComboBoxPopupMenu (ComboBox&, Label&) = 0;
|
||||
|
||||
virtual void drawComboBoxTextWhenNothingSelected (Graphics&, ComboBox&, Label&) = 0;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue