Browse Source

LookAndFeel: added method to specify a custom font for Alert Window title.

tags/2021-05-28
Timur Doumler 10 years ago
parent
commit
d46ea64aa5
5 changed files with 38 additions and 10 deletions
  1. +5
    -1
      modules/juce_graphics/fonts/juce_Font.h
  2. +6
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp
  3. +15
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h
  4. +11
    -9
      modules/juce_gui_basics/windows/juce_AlertWindow.cpp
  5. +1
    -0
      modules/juce_gui_basics/windows/juce_AlertWindow.h

+ 5
- 1
modules/juce_graphics/fonts/juce_Font.h View File

@@ -279,8 +279,12 @@ public:
//============================================================================== //==============================================================================
/** Makes the font bold or non-bold. */ /** Makes the font bold or non-bold. */
void setBold (bool shouldBeBold); void setBold (bool shouldBeBold);
/** Returns a copy of this font with the bold attribute set. */
/** Returns a copy of this font with the bold attribute set.
If the font does not have a bold version, this will return the default font.
*/
Font boldened() const; Font boldened() const;
/** Returns true if the font is bold. */ /** Returns true if the font is bold. */
bool isBold() const noexcept; bool isBold() const noexcept;


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

@@ -490,6 +490,12 @@ int LookAndFeel_V2::getAlertWindowButtonHeight()
return 28; return 28;
} }
Font LookAndFeel_V2::getAlertWindowTitleFont()
{
Font messageFont = getAlertWindowMessageFont();
return messageFont.withHeight (messageFont.getHeight() * 1.1f).boldened();
}
Font LookAndFeel_V2::getAlertWindowMessageFont() Font LookAndFeel_V2::getAlertWindowMessageFont()
{ {
return Font (15.0f); return Font (15.0f);


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

@@ -67,7 +67,22 @@ public:
void drawAlertBox (Graphics&, AlertWindow&, const Rectangle<int>& textArea, TextLayout&) override; void drawAlertBox (Graphics&, AlertWindow&, const Rectangle<int>& textArea, TextLayout&) override;
int getAlertBoxWindowFlags() override; int getAlertBoxWindowFlags() override;
int getAlertWindowButtonHeight() override; int getAlertWindowButtonHeight() override;
/** Override this function to supply a custom font for the alert window title.
This default implementation will use a boldened and slightly larger version
of the alert window message font.
@see getAlertWindowMessageFont.
*/
Font getAlertWindowTitleFont() override;
/** Override this function to supply a custom font for the alert window message.
This default implementation will use the default font with height set to 15.0f.
@see getAlertWindowTitleFont
*/
Font getAlertWindowMessageFont() override; Font getAlertWindowMessageFont() override;
Font getAlertWindowFont() override; Font getAlertWindowFont() override;
//============================================================================== //==============================================================================


+ 11
- 9
modules/juce_gui_basics/windows/juce_AlertWindow.cpp View File

@@ -343,22 +343,24 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
const int titleH = 24; const int titleH = 24;
const int iconWidth = 80; const int iconWidth = 80;
const Font font (getLookAndFeel().getAlertWindowMessageFont());
LookAndFeel& lookAndFeel = getLookAndFeel();
const int wid = jmax (font.getStringWidth (text),
font.getStringWidth (getName()));
const Font messageFont (lookAndFeel.getAlertWindowMessageFont());
const int sw = (int) std::sqrt (font.getHeight() * wid);
const int wid = jmax (messageFont.getStringWidth (text),
messageFont.getStringWidth (getName()));
const int sw = (int) std::sqrt (messageFont.getHeight() * wid);
int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f)); int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
const int edgeGap = 10; const int edgeGap = 10;
const int labelHeight = 18; const int labelHeight = 18;
int iconSpace = 0; int iconSpace = 0;
AttributedString attributedText; AttributedString attributedText;
attributedText.append (getName(), font.withHeight (font.getHeight() * 1.1f).boldened());
attributedText.append (getName(), lookAndFeel.getAlertWindowTitleFont());
if (text.isNotEmpty()) if (text.isNotEmpty())
attributedText.append ("\n\n" + text, font);
attributedText.append ("\n\n" + text, messageFont);
attributedText.setColour (findColour (textColourId)); attributedText.setColour (findColour (textColourId));
@@ -383,18 +385,18 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
int buttonW = 40; int buttonW = 40;
for (int i = 0; i < buttons.size(); ++i) for (int i = 0; i < buttons.size(); ++i)
buttonW += 16 + buttons.getUnchecked(i)->getWidth();
buttonW += 16 + buttons.getUnchecked (i)->getWidth();
w = jmax (buttonW, w); w = jmax (buttonW, w);
h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50; h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
if (buttons.size() > 0) if (buttons.size() > 0)
h += 20 + buttons.getUnchecked(0)->getHeight();
h += 20 + buttons.getUnchecked (0)->getHeight();
for (int i = customComps.size(); --i >= 0;) for (int i = customComps.size(); --i >= 0;)
{ {
Component* c = customComps.getUnchecked(i);
Component* c = customComps.getUnchecked (i);
w = jmax (w, (c->getWidth() * 100) / 80); w = jmax (w, (c->getWidth() * 100) / 80);
h += 10 + c->getHeight(); h += 10 + c->getHeight();


+ 1
- 0
modules/juce_gui_basics/windows/juce_AlertWindow.h View File

@@ -437,6 +437,7 @@ public:
virtual int getAlertWindowButtonHeight() = 0; virtual int getAlertWindowButtonHeight() = 0;
virtual Font getAlertWindowTitleFont() = 0;
virtual Font getAlertWindowMessageFont() = 0; virtual Font getAlertWindowMessageFont() = 0;
virtual Font getAlertWindowFont() = 0; virtual Font getAlertWindowFont() = 0;
}; };


Loading…
Cancel
Save