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

Removed const-ness from some return types of LookAndFeel font methods. Renamed LookAndFeel::getFontForTextButton() as getTextButtonFont() for consistency. Added LookAndFeel::getLabelFont(). Fixed a problem in Label where the label's font wasn't being correctly applied to the text editor when editing it.

This commit is contained in:
jules 2013-01-05 12:53:49 +00:00
parent 959b38a083
commit 10c73edf57
6 changed files with 45 additions and 35 deletions

View file

@ -341,7 +341,7 @@ void LookAndFeel::drawButtonBackground (Graphics& g,
button.isConnectedOnBottom()); button.isConnectedOnBottom());
} }
const Font LookAndFeel::getFontForTextButton (TextButton& button) Font LookAndFeel::getTextButtonFont (TextButton& button)
{ {
return button.getFont(); return button.getFont();
} }
@ -349,7 +349,7 @@ const Font LookAndFeel::getFontForTextButton (TextButton& button)
void LookAndFeel::drawButtonText (Graphics& g, TextButton& button, void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
bool /*isMouseOverButton*/, bool /*isButtonDown*/) bool /*isMouseOverButton*/, bool /*isButtonDown*/)
{ {
Font font (getFontForTextButton (button)); Font font (getTextButtonFont (button));
g.setFont (font); g.setFont (font);
g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
: TextButton::textColourOffId) : TextButton::textColourOffId)
@ -929,7 +929,7 @@ void LookAndFeel::drawBubble (Graphics& g, BubbleComponent& comp,
//============================================================================== //==============================================================================
const Font LookAndFeel::getPopupMenuFont() Font LookAndFeel::getPopupMenuFont()
{ {
return Font (17.0f); return Font (17.0f);
} }
@ -1131,7 +1131,7 @@ void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
} }
} }
const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/) Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
{ {
return Font (menuBar.getHeight() * 0.7f); return Font (menuBar.getHeight() * 0.7f);
} }
@ -1261,7 +1261,7 @@ void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
} }
} }
const Font LookAndFeel::getComboBoxFont (ComboBox& box) Font LookAndFeel::getComboBoxFont (ComboBox& box)
{ {
return Font (jmin (15.0f, box.getHeight() * 0.85f)); return Font (jmin (15.0f, box.getHeight() * 0.85f));
} }
@ -1281,6 +1281,11 @@ void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
} }
//============================================================================== //==============================================================================
Font LookAndFeel::getLabelFont (Label& label)
{
return label.getFont();
}
void LookAndFeel::drawLabel (Graphics& g, Label& label) void LookAndFeel::drawLabel (Graphics& g, Label& label)
{ {
g.fillAll (label.findColour (Label::backgroundColourId)); g.fillAll (label.findColour (Label::backgroundColourId));
@ -1288,26 +1293,27 @@ void LookAndFeel::drawLabel (Graphics& g, Label& label)
if (! label.isBeingEdited()) if (! label.isBeingEdited())
{ {
const float alpha = label.isEnabled() ? 1.0f : 0.5f; const float alpha = label.isEnabled() ? 1.0f : 0.5f;
const Font font (getLabelFont (label));
g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha)); g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
g.setFont (label.getFont()); g.setFont (font);
g.drawFittedText (label.getText(), g.drawFittedText (label.getText(),
label.getHorizontalBorderSize(), label.getHorizontalBorderSize(),
label.getVerticalBorderSize(), label.getVerticalBorderSize(),
label.getWidth() - 2 * label.getHorizontalBorderSize(), label.getWidth() - 2 * label.getHorizontalBorderSize(),
label.getHeight() - 2 * label.getVerticalBorderSize(), label.getHeight() - 2 * label.getVerticalBorderSize(),
label.getJustificationType(), label.getJustificationType(),
jmax (1, (int) (label.getHeight() / label.getFont().getHeight())), jmax (1, (int) (label.getHeight() / font.getHeight())),
label.getMinimumHorizontalScale()); label.getMinimumHorizontalScale());
g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha)); g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
g.drawRect (0, 0, label.getWidth(), label.getHeight());
} }
else if (label.isEnabled()) else if (label.isEnabled())
{ {
g.setColour (label.findColour (Label::outlineColourId)); g.setColour (label.findColour (Label::outlineColourId));
g.drawRect (0, 0, label.getWidth(), label.getHeight());
} }
g.drawRect (label.getLocalBounds());
} }
//============================================================================== //==============================================================================

View file

@ -159,7 +159,7 @@ public:
bool isMouseOverButton, bool isMouseOverButton,
bool isButtonDown); bool isButtonDown);
virtual const Font getFontForTextButton (TextButton& button); virtual Font getTextButtonFont (TextButton& button);
/** Draws the text for a TextButton. */ /** Draws the text for a TextButton. */
virtual void drawButtonText (Graphics& g, virtual void drawButtonText (Graphics& g,
@ -360,7 +360,7 @@ public:
const Colour* const textColour); const Colour* const textColour);
/** Returns the size and style of font to use in popup menus. */ /** Returns the size and style of font to use in popup menus. */
virtual const Font getPopupMenuFont(); virtual Font getPopupMenuFont();
virtual void drawPopupMenuUpDownArrow (Graphics& g, virtual void drawPopupMenuUpDownArrow (Graphics& g,
int width, int height, int width, int height,
@ -381,7 +381,7 @@ public:
virtual int getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText); virtual int getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText);
virtual const Font getMenuBarFont (MenuBarComponent& menuBar, int itemIndex, const String& itemText); virtual Font getMenuBarFont (MenuBarComponent& menuBar, int itemIndex, const String& itemText);
virtual void drawMenuBarItem (Graphics& g, virtual void drawMenuBarItem (Graphics& g,
int width, int height, int width, int height,
@ -399,14 +399,16 @@ public:
int buttonW, int buttonH, int buttonW, int buttonH,
ComboBox& box); ComboBox& box);
virtual const Font getComboBoxFont (ComboBox& box); virtual Font getComboBoxFont (ComboBox& box);
virtual Label* createComboBoxTextBox (ComboBox& box); virtual Label* createComboBoxTextBox (ComboBox& box);
virtual void positionComboBoxText (ComboBox& box, Label& labelToPosition); virtual void positionComboBoxText (ComboBox& box, Label& labelToPosition);
//============================================================================== //==============================================================================
virtual void drawLabel (Graphics& g, Label& label); virtual void drawLabel (Graphics&, Label&);
virtual Font getLabelFont (Label&);
//============================================================================== //==============================================================================
virtual void drawLinearSlider (Graphics& g, virtual void drawLinearSlider (Graphics& g,
@ -671,6 +673,7 @@ private:
virtual int drawTabButtonText (Graphics&, int, int, int, int, const Colour&, int, const String&, Button&, TabbedButtonBar::Orientation, bool, bool, bool) { return 0; } virtual int drawTabButtonText (Graphics&, int, int, int, int, const Colour&, int, const String&, Button&, TabbedButtonBar::Orientation, bool, bool, bool) { return 0; }
virtual int getTabButtonBestWidth (int, const String&, int, Button&) { return 0; } virtual int getTabButtonBestWidth (int, const String&, int, Button&) { return 0; }
virtual int drawBubble (Graphics&, float, float, float, float, float, float) { return 0; } virtual int drawBubble (Graphics&, float, float, float, float, float, float) { return 0; }
virtual int getFontForTextButton (TextButton&) { return 0; }
#endif #endif
class GlassWindowButton; class GlassWindowButton;

View file

@ -99,7 +99,7 @@ void Label::setFont (const Font& newFont)
} }
} }
const Font& Label::getFont() const noexcept Font Label::getFont() const noexcept
{ {
return font; return font;
} }
@ -161,9 +161,11 @@ void Label::attachToComponent (Component* owner, const bool onLeft)
void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bool /*wasResized*/) void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bool /*wasResized*/)
{ {
const Font f (getLookAndFeel().getLabelFont (*this));
if (leftOfOwnerComp) if (leftOfOwnerComp)
{ {
setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()), setSize (jmin (f.getStringWidth (textValue.toString()) + 8, component.getX()),
component.getHeight()); component.getHeight());
setTopRightPosition (component.getX(), component.getY()); setTopRightPosition (component.getX(), component.getY());
@ -171,7 +173,7 @@ void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bo
else else
{ {
setSize (component.getWidth(), setSize (component.getWidth(),
8 + roundToInt (getFont().getHeight())); 8 + roundToInt (f.getHeight()));
setTopLeftPosition (component.getX(), component.getY() - getHeight()); setTopLeftPosition (component.getX(), component.getY() - getHeight());
} }
@ -179,8 +181,8 @@ void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bo
void Label::componentParentHierarchyChanged (Component& component) void Label::componentParentHierarchyChanged (Component& component)
{ {
if (component.getParentComponent() != nullptr) if (Component* parent = component.getParentComponent())
component.getParentComponent()->addChildComponent (this); parent->addChildComponent (this);
} }
void Label::componentVisibilityChanged (Component& component) void Label::componentVisibilityChanged (Component& component)
@ -285,7 +287,7 @@ bool Label::isBeingEdited() const noexcept
TextEditor* Label::createEditorComponent() TextEditor* Label::createEditorComponent()
{ {
TextEditor* const ed = new TextEditor (getName()); TextEditor* const ed = new TextEditor (getName());
ed->setFont (font); ed->applyFontToAllText (getLookAndFeel().getLabelFont (*this));
copyAllExplicitColoursTo (*ed); copyAllExplicitColoursTo (*ed);
return ed; return ed;
} }

View file

@ -81,16 +81,15 @@ public:
//============================================================================== //==============================================================================
/** Changes the font to use to draw the text. /** Changes the font to use to draw the text.
@see getFont @see getFont
*/ */
void setFont (const Font& newFont); void setFont (const Font& newFont);
/** Returns the font currently being used. /** Returns the font currently being used.
This may be the one set by setFont(), unless it has been overridden by the current LookAndFeel
@see setFont @see setFont
*/ */
const Font& getFont() const noexcept; Font getFont() const noexcept;
//============================================================================== //==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the label. /** A set of colour IDs to use to change the colour of various aspects of the label.
@ -277,19 +276,19 @@ protected:
//============================================================================== //==============================================================================
/** @internal */ /** @internal */
void paint (Graphics& g); void paint (Graphics&);
/** @internal */ /** @internal */
void resized(); void resized();
/** @internal */ /** @internal */
void mouseUp (const MouseEvent& e); void mouseUp (const MouseEvent&);
/** @internal */ /** @internal */
void mouseDoubleClick (const MouseEvent& e); void mouseDoubleClick (const MouseEvent&);
/** @internal */ /** @internal */
void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized); void componentMovedOrResized (Component&, bool wasMoved, bool wasResized);
/** @internal */ /** @internal */
void componentParentHierarchyChanged (Component& component); void componentParentHierarchyChanged (Component&);
/** @internal */ /** @internal */
void componentVisibilityChanged (Component& component); void componentVisibilityChanged (Component&);
/** @internal */ /** @internal */
void inputAttemptWhenModal(); void inputAttemptWhenModal();
/** @internal */ /** @internal */
@ -299,13 +298,13 @@ protected:
/** @internal */ /** @internal */
KeyboardFocusTraverser* createFocusTraverser(); KeyboardFocusTraverser* createFocusTraverser();
/** @internal */ /** @internal */
void textEditorTextChanged (TextEditor& editor); void textEditorTextChanged (TextEditor&);
/** @internal */ /** @internal */
void textEditorReturnKeyPressed (TextEditor& editor); void textEditorReturnKeyPressed (TextEditor&);
/** @internal */ /** @internal */
void textEditorEscapeKeyPressed (TextEditor& editor); void textEditorEscapeKeyPressed (TextEditor&);
/** @internal */ /** @internal */
void textEditorFocusLost (TextEditor& editor); void textEditorFocusLost (TextEditor&);
/** @internal */ /** @internal */
void colourChanged(); void colourChanged();
/** @internal */ /** @internal */

View file

@ -365,7 +365,7 @@ void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
} }
} }
const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box) Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
{ {
Font f (jmin (15.0f, box.getHeight() * 0.85f)); Font f (jmin (15.0f, box.getHeight() * 0.85f));
f.setHorizontalScale (0.9f); f.setHorizontalScale (0.9f);

View file

@ -111,7 +111,7 @@ public:
int buttonW, int buttonH, int buttonW, int buttonH,
ComboBox& box); ComboBox& box);
virtual const Font getComboBoxFont (ComboBox& box); virtual Font getComboBoxFont (ComboBox& box);
//============================================================================== //==============================================================================
virtual void drawLinearSlider (Graphics& g, virtual void drawLinearSlider (Graphics& g,