1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-15 00:24:19 +00:00

Added AlertWindow LookAndFeel methods to offer more control on button widths

This commit is contained in:
hogliux 2016-11-21 10:07:20 +00:00
parent 388251b1e2
commit ee373af944
4 changed files with 23 additions and 6 deletions

View file

@ -489,9 +489,17 @@ int LookAndFeel_V2::getAlertBoxWindowFlags()
| ComponentPeer::windowHasDropShadow;
}
int LookAndFeel_V2::getAlertWindowButtonWidth (TextButton& b)
Array<int> LookAndFeel_V2::getWidthsForTextButtons (AlertWindow&, const Array<TextButton*>& buttons)
{
return getTextButtonWidthToFitText (b, getAlertWindowButtonHeight());
const int n = buttons.size();
Array<int> buttonWidths;
const int buttonHeight = getAlertWindowButtonHeight();
for (int i = 0; i < n; ++i)
buttonWidths.add (getTextButtonWidthToFitText (*buttons.getReference (i), buttonHeight));
return buttonWidths;
}
int LookAndFeel_V2::getAlertWindowButtonHeight()

View file

@ -67,7 +67,7 @@ public:
void drawAlertBox (Graphics&, AlertWindow&, const Rectangle<int>& textArea, TextLayout&) override;
int getAlertBoxWindowFlags() override;
int getAlertWindowButtonWidth (TextButton&) override;
Array<int> getWidthsForTextButtons (AlertWindow&, const Array<TextButton*>&) override;
int getAlertWindowButtonHeight() override;
/** Override this function to supply a custom font for the alert window title.

View file

@ -99,8 +99,17 @@ void AlertWindow::addButton (const String& name,
b->addShortcut (shortcutKey2);
b->addListener (this);
b->setSize (getLookAndFeel().getAlertWindowButtonWidth (*b),
getLookAndFeel().getAlertWindowButtonHeight());
Array<TextButton*> buttonsArray (buttons.begin(), buttons.size());
const int buttonHeight = getLookAndFeel().getAlertWindowButtonHeight();
const Array<int> buttonWidths = getLookAndFeel().getWidthsForTextButtons (*this, buttonsArray);
jassert (buttonWidths.size() == buttons.size());
const int n = buttonWidths.size();
for (int i = 0; i < n; ++i)
buttons.getUnchecked (i)->setSize (buttonWidths.getReference (i), buttonHeight);
addAndMakeVisible (b, 0);

View file

@ -435,7 +435,7 @@ public:
virtual int getAlertBoxWindowFlags() = 0;
virtual int getAlertWindowButtonWidth (TextButton&) = 0;
virtual Array<int> getWidthsForTextButtons (AlertWindow&, const Array<TextButton*>&) = 0;
virtual int getAlertWindowButtonHeight() = 0;
virtual Font getAlertWindowTitleFont() = 0;