mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
DrawableText: Add option to avoid trimming the start text
This commit is contained in:
parent
50b51f512a
commit
b03a23503a
2 changed files with 40 additions and 6 deletions
|
|
@ -75,6 +75,12 @@ void DrawableText::setText (const String& newText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawableText::setPreserveWhitespace (bool shouldPreserveWhitespace)
|
||||||
|
{
|
||||||
|
if (std::exchange (preserveWhitespace, shouldPreserveWhitespace) != shouldPreserveWhitespace)
|
||||||
|
refreshBounds();
|
||||||
|
}
|
||||||
|
|
||||||
void DrawableText::setColour (Colour newColour)
|
void DrawableText::setColour (Colour newColour)
|
||||||
{
|
{
|
||||||
if (colour != newColour)
|
if (colour != newColour)
|
||||||
|
|
@ -173,7 +179,11 @@ void DrawableText::paint (Graphics& g)
|
||||||
g.setFont (scaledFont);
|
g.setFont (scaledFont);
|
||||||
g.setColour (colour);
|
g.setColour (colour);
|
||||||
|
|
||||||
g.drawFittedText (text, getTextArea (w, h), justification, 0x100000);
|
if (preserveWhitespace)
|
||||||
|
g.drawText (text, getTextArea (w, h), justification, false);
|
||||||
|
else
|
||||||
|
g.drawFittedText (text, getTextArea (w, h), justification, 0x100000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle<float> DrawableText::getDrawableBounds() const
|
Rectangle<float> DrawableText::getDrawableBounds() const
|
||||||
|
|
@ -188,11 +198,27 @@ Path DrawableText::getOutlineAsPath() const
|
||||||
auto area = getTextArea (w, h).toFloat();
|
auto area = getTextArea (w, h).toFloat();
|
||||||
|
|
||||||
GlyphArrangement arr;
|
GlyphArrangement arr;
|
||||||
arr.addFittedText (scaledFont, text,
|
|
||||||
area.getX(), area.getY(),
|
if (preserveWhitespace)
|
||||||
area.getWidth(), area.getHeight(),
|
{
|
||||||
justification,
|
arr.addJustifiedText (scaledFont,
|
||||||
0x100000);
|
text,
|
||||||
|
area.getX(),
|
||||||
|
area.getY() + scaledFont.getAscent(),
|
||||||
|
area.getWidth(),
|
||||||
|
justification);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arr.addFittedText (scaledFont,
|
||||||
|
text,
|
||||||
|
area.getX(),
|
||||||
|
area.getY(),
|
||||||
|
area.getWidth(),
|
||||||
|
area.getHeight(),
|
||||||
|
justification,
|
||||||
|
0x100000);
|
||||||
|
}
|
||||||
|
|
||||||
Path pathOfAllGlyphs;
|
Path pathOfAllGlyphs;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,13 @@ public:
|
||||||
/** Sets the text to display.*/
|
/** Sets the text to display.*/
|
||||||
void setText (const String& newText);
|
void setText (const String& newText);
|
||||||
|
|
||||||
|
/** Sets whether whitespace should always be preserved when drawing. The default value is false.
|
||||||
|
|
||||||
|
Historically, DrawableText would sometimes trim the provided text during drawing based on
|
||||||
|
its contents. With this value set to true, trimming will never occur.
|
||||||
|
*/
|
||||||
|
void setPreserveWhitespace (bool shouldPreserveWhitespace);
|
||||||
|
|
||||||
/** Returns the currently displayed text */
|
/** Returns the currently displayed text */
|
||||||
const String& getText() const noexcept { return text;}
|
const String& getText() const noexcept { return text;}
|
||||||
|
|
||||||
|
|
@ -116,6 +123,7 @@ private:
|
||||||
float fontHeight, fontHScale;
|
float fontHeight, fontHScale;
|
||||||
Font font { withDefaultMetrics (FontOptions{}) }, scaledFont { withDefaultMetrics (FontOptions{}) };
|
Font font { withDefaultMetrics (FontOptions{}) }, scaledFont { withDefaultMetrics (FontOptions{}) };
|
||||||
String text;
|
String text;
|
||||||
|
bool preserveWhitespace = false;
|
||||||
Colour colour;
|
Colour colour;
|
||||||
Justification justification;
|
Justification justification;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue