diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index f4212595c6..c01c8f7575 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -1183,13 +1183,11 @@ void LookAndFeel_V2::drawLabel (Graphics& g, Label& label) g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha)); 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() / font.getHeight())), + + Rectangle textArea (label.getBorderSize().subtractedFrom (label.getLocalBounds())); + + g.drawFittedText (label.getText(), textArea, label.getJustificationType(), + jmax (1, (int) (textArea.getHeight() / font.getHeight())), label.getMinimumHorizontalScale()); g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha)); diff --git a/modules/juce_gui_basics/widgets/juce_Label.cpp b/modules/juce_gui_basics/widgets/juce_Label.cpp index ce13d87c6b..682c209ba6 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.cpp +++ b/modules/juce_gui_basics/widgets/juce_Label.cpp @@ -28,8 +28,7 @@ Label::Label (const String& name, const String& labelText) lastTextValue (labelText), font (15.0f), justification (Justification::centredLeft), - horizontalBorderSize (5), - verticalBorderSize (1), + border (1, 5, 1, 5), minimumHorizontalScale (0.7f), editSingleClick (false), editDoubleClick (false), @@ -123,12 +122,11 @@ void Label::setJustificationType (Justification newJustification) } } -void Label::setBorderSize (int h, int v) +void Label::setBorderSize (BorderSize newBorder) { - if (horizontalBorderSize != h || verticalBorderSize != v) + if (border != newBorder) { - horizontalBorderSize = h; - verticalBorderSize = v; + border = newBorder; repaint(); } } @@ -325,7 +323,7 @@ void Label::mouseDoubleClick (const MouseEvent& e) void Label::resized() { if (editor != nullptr) - editor->setBoundsInset (BorderSize (0)); + editor->setBounds (getLocalBounds()); } void Label::focusGained (FocusChangeType cause) diff --git a/modules/juce_gui_basics/widgets/juce_Label.h b/modules/juce_gui_basics/widgets/juce_Label.h index 9094746241..7e7fcb21b5 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.h +++ b/modules/juce_gui_basics/widgets/juce_Label.h @@ -117,17 +117,14 @@ public: /** Returns the type of justification, as set in setJustificationType(). */ Justification getJustificationType() const noexcept { return justification; } - /** Changes the gap that is left between the edge of the component and the text. + /** Changes the border that is left between the edge of the component and the text. By default there's a small gap left at the sides of the component to allow for the drawing of the border, but you can change this if necessary. */ - void setBorderSize (int horizontalBorder, int verticalBorder); + void setBorderSize (BorderSize newBorderSize); - /** Returns the size of the horizontal gap being left around the text. */ - int getHorizontalBorderSize() const noexcept { return horizontalBorderSize; } - - /** Returns the size of the vertical gap being left around the text. */ - int getVerticalBorderSize() const noexcept { return verticalBorderSize; } + /** Returns the size of the border to be left around the text. */ + BorderSize getBorderSize() const noexcept { return border; } /** Makes this label "stick to" another component. @@ -327,7 +324,7 @@ private: ScopedPointer editor; ListenerList listeners; WeakReference ownerComponent; - int horizontalBorderSize, verticalBorderSize; + BorderSize border; float minimumHorizontalScale; bool editSingleClick; bool editDoubleClick;