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

Changed the Label class to use BorderSize to define its border instead of raw values.

This commit is contained in:
jules 2014-04-24 14:38:13 +01:00
parent 95699451b5
commit 8cad74a22a
3 changed files with 15 additions and 22 deletions

View file

@ -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<int> 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));

View file

@ -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<int> 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<int> (0));
editor->setBounds (getLocalBounds());
}
void Label::focusGained (FocusChangeType cause)

View file

@ -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<int> 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<int> getBorderSize() const noexcept { return border; }
/** Makes this label "stick to" another component.
@ -327,7 +324,7 @@ private:
ScopedPointer<TextEditor> editor;
ListenerList<Listener> listeners;
WeakReference<Component> ownerComponent;
int horizontalBorderSize, verticalBorderSize;
BorderSize<int> border;
float minimumHorizontalScale;
bool editSingleClick;
bool editDoubleClick;