From ee373af944585664e42ca6e16dec02499b398ddc Mon Sep 17 00:00:00 2001 From: hogliux Date: Mon, 21 Nov 2016 10:07:20 +0000 Subject: [PATCH] Added AlertWindow LookAndFeel methods to offer more control on button widths --- .../lookandfeel/juce_LookAndFeel_V2.cpp | 12 ++++++++++-- .../lookandfeel/juce_LookAndFeel_V2.h | 2 +- .../juce_gui_basics/windows/juce_AlertWindow.cpp | 13 +++++++++++-- modules/juce_gui_basics/windows/juce_AlertWindow.h | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 437c2484ef..426b672b07 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -489,9 +489,17 @@ int LookAndFeel_V2::getAlertBoxWindowFlags() | ComponentPeer::windowHasDropShadow; } -int LookAndFeel_V2::getAlertWindowButtonWidth (TextButton& b) +Array LookAndFeel_V2::getWidthsForTextButtons (AlertWindow&, const Array& buttons) { - return getTextButtonWidthToFitText (b, getAlertWindowButtonHeight()); + const int n = buttons.size(); + Array 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() diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h index 6fe70e50a2..f1f7e26936 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h @@ -67,7 +67,7 @@ public: void drawAlertBox (Graphics&, AlertWindow&, const Rectangle& textArea, TextLayout&) override; int getAlertBoxWindowFlags() override; - int getAlertWindowButtonWidth (TextButton&) override; + Array getWidthsForTextButtons (AlertWindow&, const Array&) override; int getAlertWindowButtonHeight() override; /** Override this function to supply a custom font for the alert window title. diff --git a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp index 5388de00aa..821229f9e7 100644 --- a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp @@ -99,8 +99,17 @@ void AlertWindow::addButton (const String& name, b->addShortcut (shortcutKey2); b->addListener (this); - b->setSize (getLookAndFeel().getAlertWindowButtonWidth (*b), - getLookAndFeel().getAlertWindowButtonHeight()); + Array buttonsArray (buttons.begin(), buttons.size()); + + const int buttonHeight = getLookAndFeel().getAlertWindowButtonHeight(); + const Array 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); diff --git a/modules/juce_gui_basics/windows/juce_AlertWindow.h b/modules/juce_gui_basics/windows/juce_AlertWindow.h index 0e85a6b3a1..cf1a06f166 100644 --- a/modules/juce_gui_basics/windows/juce_AlertWindow.h +++ b/modules/juce_gui_basics/windows/juce_AlertWindow.h @@ -435,7 +435,7 @@ public: virtual int getAlertBoxWindowFlags() = 0; - virtual int getAlertWindowButtonWidth (TextButton&) = 0; + virtual Array getWidthsForTextButtons (AlertWindow&, const Array&) = 0; virtual int getAlertWindowButtonHeight() = 0; virtual Font getAlertWindowTitleFont() = 0;