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());
}
const Font LookAndFeel::getFontForTextButton (TextButton& button)
Font LookAndFeel::getTextButtonFont (TextButton& button)
{
return button.getFont();
}
@ -349,7 +349,7 @@ const Font LookAndFeel::getFontForTextButton (TextButton& button)
void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
bool /*isMouseOverButton*/, bool /*isButtonDown*/)
{
Font font (getFontForTextButton (button));
Font font (getTextButtonFont (button));
g.setFont (font);
g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
: TextButton::textColourOffId)
@ -929,7 +929,7 @@ void LookAndFeel::drawBubble (Graphics& g, BubbleComponent& comp,
//==============================================================================
const Font LookAndFeel::getPopupMenuFont()
Font LookAndFeel::getPopupMenuFont()
{
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);
}
@ -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));
}
@ -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)
{
g.fillAll (label.findColour (Label::backgroundColourId));
@ -1288,26 +1293,27 @@ void LookAndFeel::drawLabel (Graphics& g, Label& label)
if (! label.isBeingEdited())
{
const float alpha = label.isEnabled() ? 1.0f : 0.5f;
const Font font (getLabelFont (label));
g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
g.setFont (label.getFont());
g.setFont (font);
g.drawFittedText (label.getText(),
label.getHorizontalBorderSize(),
label.getVerticalBorderSize(),
label.getWidth() - 2 * label.getHorizontalBorderSize(),
label.getHeight() - 2 * label.getVerticalBorderSize(),
label.getJustificationType(),
jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
jmax (1, (int) (label.getHeight() / font.getHeight())),
label.getMinimumHorizontalScale());
g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
g.drawRect (0, 0, label.getWidth(), label.getHeight());
}
else if (label.isEnabled())
{
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 isButtonDown);
virtual const Font getFontForTextButton (TextButton& button);
virtual Font getTextButtonFont (TextButton& button);
/** Draws the text for a TextButton. */
virtual void drawButtonText (Graphics& g,
@ -360,7 +360,7 @@ public:
const Colour* const textColour);
/** Returns the size and style of font to use in popup menus. */
virtual const Font getPopupMenuFont();
virtual Font getPopupMenuFont();
virtual void drawPopupMenuUpDownArrow (Graphics& g,
int width, int height,
@ -381,7 +381,7 @@ public:
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,
int width, int height,
@ -399,14 +399,16 @@ public:
int buttonW, int buttonH,
ComboBox& box);
virtual const Font getComboBoxFont (ComboBox& box);
virtual Font getComboBoxFont (ComboBox& box);
virtual Label* createComboBoxTextBox (ComboBox& box);
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,
@ -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 getTabButtonBestWidth (int, const String&, int, Button&) { return 0; }
virtual int drawBubble (Graphics&, float, float, float, float, float, float) { return 0; }
virtual int getFontForTextButton (TextButton&) { return 0; }
#endif
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;
}
@ -161,9 +161,11 @@ void Label::attachToComponent (Component* owner, const bool onLeft)
void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bool /*wasResized*/)
{
const Font f (getLookAndFeel().getLabelFont (*this));
if (leftOfOwnerComp)
{
setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
setSize (jmin (f.getStringWidth (textValue.toString()) + 8, component.getX()),
component.getHeight());
setTopRightPosition (component.getX(), component.getY());
@ -171,7 +173,7 @@ void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bo
else
{
setSize (component.getWidth(),
8 + roundToInt (getFont().getHeight()));
8 + roundToInt (f.getHeight()));
setTopLeftPosition (component.getX(), component.getY() - getHeight());
}
@ -179,8 +181,8 @@ void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bo
void Label::componentParentHierarchyChanged (Component& component)
{
if (component.getParentComponent() != nullptr)
component.getParentComponent()->addChildComponent (this);
if (Component* parent = component.getParentComponent())
parent->addChildComponent (this);
}
void Label::componentVisibilityChanged (Component& component)
@ -285,7 +287,7 @@ bool Label::isBeingEdited() const noexcept
TextEditor* Label::createEditorComponent()
{
TextEditor* const ed = new TextEditor (getName());
ed->setFont (font);
ed->applyFontToAllText (getLookAndFeel().getLabelFont (*this));
copyAllExplicitColoursTo (*ed);
return ed;
}

View file

@ -81,16 +81,15 @@ public:
//==============================================================================
/** Changes the font to use to draw the text.
@see getFont
*/
void setFont (const Font& newFont);
/** 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
*/
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.
@ -277,19 +276,19 @@ protected:
//==============================================================================
/** @internal */
void paint (Graphics& g);
void paint (Graphics&);
/** @internal */
void resized();
/** @internal */
void mouseUp (const MouseEvent& e);
void mouseUp (const MouseEvent&);
/** @internal */
void mouseDoubleClick (const MouseEvent& e);
void mouseDoubleClick (const MouseEvent&);
/** @internal */
void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
void componentMovedOrResized (Component&, bool wasMoved, bool wasResized);
/** @internal */
void componentParentHierarchyChanged (Component& component);
void componentParentHierarchyChanged (Component&);
/** @internal */
void componentVisibilityChanged (Component& component);
void componentVisibilityChanged (Component&);
/** @internal */
void inputAttemptWhenModal();
/** @internal */
@ -299,13 +298,13 @@ protected:
/** @internal */
KeyboardFocusTraverser* createFocusTraverser();
/** @internal */
void textEditorTextChanged (TextEditor& editor);
void textEditorTextChanged (TextEditor&);
/** @internal */
void textEditorReturnKeyPressed (TextEditor& editor);
void textEditorReturnKeyPressed (TextEditor&);
/** @internal */
void textEditorEscapeKeyPressed (TextEditor& editor);
void textEditorEscapeKeyPressed (TextEditor&);
/** @internal */
void textEditorFocusLost (TextEditor& editor);
void textEditorFocusLost (TextEditor&);
/** @internal */
void colourChanged();
/** @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));
f.setHorizontalScale (0.9f);

View file

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