mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
ShapedTextOptions: Rename maxWidth to wordWrapWidth
The old name didn't communicate it clearly enough what the parameter was used for. This started to show when alignmentWidth was added.
This commit is contained in:
parent
6ad121a408
commit
0e4287df52
6 changed files with 30 additions and 30 deletions
|
|
@ -259,7 +259,7 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
||||||
return getMainAxisLineAlignment (options.getJustification(),
|
return getMainAxisLineAlignment (options.getJustification(),
|
||||||
glyphs,
|
glyphs,
|
||||||
lineLength,
|
lineLength,
|
||||||
options.getMaxWidth(),
|
options.getWordWrapWidth(),
|
||||||
options.getAlignmentWidth(),
|
options.getAlignmentWidth(),
|
||||||
options.getTrailingWhitespacesShouldFit());
|
options.getTrailingWhitespacesShouldFit());
|
||||||
}();
|
}();
|
||||||
|
|
@ -344,8 +344,8 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
||||||
const auto effectiveLength = options.getTrailingWhitespacesShouldFit() ? lastLineLengths.total
|
const auto effectiveLength = options.getTrailingWhitespacesShouldFit() ? lastLineLengths.total
|
||||||
: lastLineLengths.withoutTrailingWhitespaces;
|
: lastLineLengths.withoutTrailingWhitespaces;
|
||||||
|
|
||||||
if (! options.getMaxWidth().has_value()
|
if (! options.getWordWrapWidth().has_value()
|
||||||
|| effectiveLength <= *options.getMaxWidth() + maxWidthTolerance)
|
|| effectiveLength <= *options.getWordWrapWidth() + maxWidthTolerance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto cutoffAtFront = lastLineMetrics.value.anchor.getX() < 0.0f - maxWidthTolerance;
|
const auto cutoffAtFront = lastLineMetrics.value.anchor.getX() < 0.0f - maxWidthTolerance;
|
||||||
|
|
@ -362,8 +362,8 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
||||||
{
|
{
|
||||||
length -= it->advance.getX();
|
length -= it->advance.getX();
|
||||||
|
|
||||||
if (! options.getMaxWidth().has_value()
|
if (! options.getWordWrapWidth().has_value()
|
||||||
|| *options.getMaxWidth() >= ellipsisLength + length)
|
|| *options.getWordWrapWidth() >= ellipsisLength + length)
|
||||||
{
|
{
|
||||||
return { (int64) std::distance (lastLineGlyphs.begin(), it) + 1,
|
return { (int64) std::distance (lastLineGlyphs.begin(), it) + 1,
|
||||||
(int64) lastLineGlyphs.size() };
|
(int64) lastLineGlyphs.size() };
|
||||||
|
|
@ -378,8 +378,8 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
||||||
{
|
{
|
||||||
length -= it->advance.getX();
|
length -= it->advance.getX();
|
||||||
|
|
||||||
if (! options.getMaxWidth().has_value()
|
if (! options.getWordWrapWidth().has_value()
|
||||||
|| *options.getMaxWidth() >= ellipsisLength + length)
|
|| *options.getWordWrapWidth() >= ellipsisLength + length)
|
||||||
{
|
{
|
||||||
return { 0, (int64) std::distance (lastLineGlyphs.begin(), it) };
|
return { 0, (int64) std::distance (lastLineGlyphs.begin(), it) };
|
||||||
}
|
}
|
||||||
|
|
@ -464,7 +464,7 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
||||||
return getMainAxisLineAlignment (options.getJustification(),
|
return getMainAxisLineAlignment (options.getJustification(),
|
||||||
lineWithEllipsisGlyphs,
|
lineWithEllipsisGlyphs,
|
||||||
getMainAxisLineLength (lineWithEllipsisGlyphs),
|
getMainAxisLineLength (lineWithEllipsisGlyphs),
|
||||||
options.getMaxWidth(),
|
options.getWordWrapWidth(),
|
||||||
options.getAlignmentWidth(),
|
options.getAlignmentWidth(),
|
||||||
options.getTrailingWhitespacesShouldFit());
|
options.getTrailingWhitespacesShouldFit());
|
||||||
}();
|
}();
|
||||||
|
|
|
||||||
|
|
@ -1279,7 +1279,7 @@ void SimpleShapedText::shape (const String& data,
|
||||||
for (const auto& lineRange : getLineRanges (data))
|
for (const auto& lineRange : getLineRanges (data))
|
||||||
{
|
{
|
||||||
Shaper shaper { data, lineRange, options };
|
Shaper shaper { data, lineRange, options };
|
||||||
auto lineDataAndStorage = FillLinesOptions{}.withWidth (options.getMaxWidth().value_or ((float) 1e6))
|
auto lineDataAndStorage = FillLinesOptions{}.withWidth (options.getWordWrapWidth().value_or ((float) 1e6))
|
||||||
.withFirstLinePadding (options.getFirstLineIndent())
|
.withFirstLinePadding (options.getFirstLineIndent())
|
||||||
.withTrailingWhitespaceCanExtendBeyondMargin (! options.getTrailingWhitespacesShouldFit())
|
.withTrailingWhitespaceCanExtendBeyondMargin (! options.getTrailingWhitespacesShouldFit())
|
||||||
.withForceConsumeFirstWord (! options.getAllowBreakingInsideWord())
|
.withForceConsumeFirstWord (! options.getAllowBreakingInsideWord())
|
||||||
|
|
@ -1552,7 +1552,7 @@ struct SimpleShapedTextTests : public UnitTest
|
||||||
String testString { text };
|
String testString { text };
|
||||||
|
|
||||||
SimpleShapedText st { &testString, ShapedTextOptions{}.withFont (FontOptions { defaultTypeface })
|
SimpleShapedText st { &testString, ShapedTextOptions{}.withFont (FontOptions { defaultTypeface })
|
||||||
.withMaxWidth (maxWidth) };
|
.withWordWrapWidth (maxWidth) };
|
||||||
|
|
||||||
auto success = true;
|
auto success = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ private:
|
||||||
{
|
{
|
||||||
return std::tie (justification,
|
return std::tie (justification,
|
||||||
readingDir,
|
readingDir,
|
||||||
maxWidth,
|
wordWrapWidth,
|
||||||
alignmentWidth,
|
alignmentWidth,
|
||||||
height,
|
height,
|
||||||
fontsForRange,
|
fontsForRange,
|
||||||
|
|
@ -81,28 +81,28 @@ public:
|
||||||
The alignment width can be overriden using withAlignmentWidth, but currently we only need
|
The alignment width can be overriden using withAlignmentWidth, but currently we only need
|
||||||
to do this for the TextEditor.
|
to do this for the TextEditor.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] ShapedTextOptions withMaxWidth (float x) const
|
[[nodiscard]] ShapedTextOptions withWordWrapWidth (float x) const
|
||||||
{
|
{
|
||||||
return withMember (*this, &ShapedTextOptions::maxWidth, x);
|
return withMember (*this, &ShapedTextOptions::wordWrapWidth, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* With this option each line will be aligned only if it's shorter or equal to the alignment
|
/* With this option each line will be aligned only if it's shorter or equal to the alignment
|
||||||
width. Otherwise, the line's x anchor will be 0.0f. This is in contrast to using
|
width. Otherwise, the line's x anchor will be 0.0f. This is in contrast to using
|
||||||
withMaxWidth only, which will modify the x anchor of RTL lines that are too long, to ensure
|
withWordWrapWidth only, which will modify the x anchor of RTL lines that are too long, to ensure
|
||||||
that it's the logical end of the text that falls outside the visible bounds.
|
that it's the logical end of the text that falls outside the visible bounds.
|
||||||
|
|
||||||
The alignment width is also a distinct value from the value used for soft wrapping which is
|
The alignment width is also a distinct value from the value used for soft wrapping which is
|
||||||
specified using withMaxWidth.
|
specified using withWordWrapWidth.
|
||||||
|
|
||||||
This option is specifically meant to support an existing TextEditor behaviour, where text
|
This option is specifically meant to support an existing TextEditor behaviour, where text
|
||||||
can be aligned even when word wrapping is off. You probably don't need to use this function,
|
can be aligned even when word wrapping is off. You probably don't need to use this function,
|
||||||
unless you want to reproduce the particular behaviour seen in the TextEditor, and should
|
unless you want to reproduce the particular behaviour seen in the TextEditor, and should
|
||||||
only use withMaxWidth, if alignment is required.
|
only use withWordWrapWidth, if alignment is required.
|
||||||
|
|
||||||
With this option off, text is either not aligned, or aligned to the width specified using
|
With this option off, text is either not aligned, or aligned to the width specified using
|
||||||
withMaxWidth.
|
withWordWrapWidth.
|
||||||
|
|
||||||
When this option is in use, it overrides the width specified in withMaxWidth for alignment
|
When this option is in use, it overrides the width specified in withWordWrapWidth for alignment
|
||||||
purposes, but not for line wrapping purposes.
|
purposes, but not for line wrapping purposes.
|
||||||
|
|
||||||
It also accommodates the fact that the TextEditor has a scrolling feature and text never
|
It also accommodates the fact that the TextEditor has a scrolling feature and text never
|
||||||
|
|
@ -191,7 +191,7 @@ public:
|
||||||
|
|
||||||
const auto& getReadingDirection() const { return readingDir; }
|
const auto& getReadingDirection() const { return readingDir; }
|
||||||
const auto& getJustification() const { return justification; }
|
const auto& getJustification() const { return justification; }
|
||||||
const auto& getMaxWidth() const { return maxWidth; }
|
const auto& getWordWrapWidth() const { return wordWrapWidth; }
|
||||||
const auto& getAlignmentWidth() const { return alignmentWidth; }
|
const auto& getAlignmentWidth() const { return alignmentWidth; }
|
||||||
const auto& getHeight() const { return height; }
|
const auto& getHeight() const { return height; }
|
||||||
const auto& getFontsForRange() const { return fontsForRange; }
|
const auto& getFontsForRange() const { return fontsForRange; }
|
||||||
|
|
@ -208,7 +208,7 @@ public:
|
||||||
private:
|
private:
|
||||||
Justification justification { Justification::topLeft };
|
Justification justification { Justification::topLeft };
|
||||||
std::optional<TextDirection> readingDir;
|
std::optional<TextDirection> readingDir;
|
||||||
std::optional<float> maxWidth;
|
std::optional<float> wordWrapWidth;
|
||||||
std::optional<float> alignmentWidth;
|
std::optional<float> alignmentWidth;
|
||||||
std::optional<float> height;
|
std::optional<float> height;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,7 @@ void GlyphArrangement::addCurtailedLineOfText (const Font& font, const String& t
|
||||||
using namespace detail;
|
using namespace detail;
|
||||||
|
|
||||||
auto options = ShapedText::Options{}.withMaxNumLines (1)
|
auto options = ShapedText::Options{}.withMaxNumLines (1)
|
||||||
.withMaxWidth (maxWidthPixels)
|
.withWordWrapWidth (maxWidthPixels)
|
||||||
.withFont (font)
|
.withFont (font)
|
||||||
.withBaselineAtZero()
|
.withBaselineAtZero()
|
||||||
.withTrailingWhitespacesShouldFit (false);
|
.withTrailingWhitespacesShouldFit (false);
|
||||||
|
|
@ -225,7 +225,7 @@ void GlyphArrangement::addJustifiedText (const Font& font, const String& text,
|
||||||
{
|
{
|
||||||
using namespace detail;
|
using namespace detail;
|
||||||
|
|
||||||
ShapedText st { text, ShapedText::Options{}.withMaxWidth (maxLineWidth)
|
ShapedText st { text, ShapedText::Options{}.withWordWrapWidth (maxLineWidth)
|
||||||
.withJustification (horizontalLayout)
|
.withJustification (horizontalLayout)
|
||||||
.withFont (font)
|
.withFont (font)
|
||||||
.withAdditiveLineSpacing (leading)
|
.withAdditiveLineSpacing (leading)
|
||||||
|
|
@ -259,7 +259,7 @@ static auto createFittedText (const Font& f,
|
||||||
{
|
{
|
||||||
ShapedText st { text,
|
ShapedText st { text,
|
||||||
baseOptions
|
baseOptions
|
||||||
.withMaxWidth (width)
|
.withWordWrapWidth (width)
|
||||||
.withHeight (height)
|
.withHeight (height)
|
||||||
.withJustification (layout)
|
.withJustification (layout)
|
||||||
.withFont (f)
|
.withFont (f)
|
||||||
|
|
@ -275,7 +275,7 @@ static auto createFittedText (const Font& f,
|
||||||
// First attempt: try to squash the entire text on a single line
|
// First attempt: try to squash the entire text on a single line
|
||||||
{
|
{
|
||||||
ShapedText st { trimmed, baseOptions.withFont (f)
|
ShapedText st { trimmed, baseOptions.withFont (f)
|
||||||
.withMaxWidth (width)
|
.withWordWrapWidth (width)
|
||||||
.withHeight (height)
|
.withHeight (height)
|
||||||
.withMaxNumLines (1)
|
.withMaxNumLines (1)
|
||||||
.withJustification (layout)
|
.withJustification (layout)
|
||||||
|
|
@ -294,7 +294,7 @@ static auto createFittedText (const Font& f,
|
||||||
ShapedText squashed { trimmed,
|
ShapedText squashed { trimmed,
|
||||||
baseOptions
|
baseOptions
|
||||||
.withFont (f.withHorizontalScale (f.getHorizontalScale() * requiredRelativeScale))
|
.withFont (f.withHorizontalScale (f.getHorizontalScale() * requiredRelativeScale))
|
||||||
.withMaxWidth (width)
|
.withWordWrapWidth (width)
|
||||||
.withHeight (height)
|
.withHeight (height)
|
||||||
.withJustification (layout)
|
.withJustification (layout)
|
||||||
.withTrailingWhitespacesShouldFit (false)};
|
.withTrailingWhitespacesShouldFit (false)};
|
||||||
|
|
@ -310,7 +310,7 @@ static auto createFittedText (const Font& f,
|
||||||
ShapedText squashed { trimmed,
|
ShapedText squashed { trimmed,
|
||||||
baseOptions
|
baseOptions
|
||||||
.withFont (f.withHorizontalScale (minimumHorizontalScale))
|
.withFont (f.withHorizontalScale (minimumHorizontalScale))
|
||||||
.withMaxWidth (width)
|
.withWordWrapWidth (width)
|
||||||
.withHeight (height)
|
.withHeight (height)
|
||||||
.withJustification (layout)
|
.withJustification (layout)
|
||||||
.withMaxNumLines (1)
|
.withMaxNumLines (1)
|
||||||
|
|
@ -347,7 +347,7 @@ static auto createFittedText (const Font& f,
|
||||||
ShapedText squashed { trimmed,
|
ShapedText squashed { trimmed,
|
||||||
baseOptions
|
baseOptions
|
||||||
.withFont (font)
|
.withFont (font)
|
||||||
.withMaxWidth (width)
|
.withWordWrapWidth (width)
|
||||||
.withHeight (height)
|
.withHeight (height)
|
||||||
.withMaxNumLines (numLines)
|
.withMaxNumLines (numLines)
|
||||||
.withJustification (layout)
|
.withJustification (layout)
|
||||||
|
|
@ -376,7 +376,7 @@ static auto createFittedText (const Font& f,
|
||||||
return ShapedText { trimmed,
|
return ShapedText { trimmed,
|
||||||
baseOptions
|
baseOptions
|
||||||
.withFont (font.withHorizontalScale (horizontalScale))
|
.withFont (font.withHorizontalScale (horizontalScale))
|
||||||
.withMaxWidth (width)
|
.withWordWrapWidth (width)
|
||||||
.withHeight (height)
|
.withHeight (height)
|
||||||
.withMaxNumLines (numLines)
|
.withMaxNumLines (numLines)
|
||||||
.withJustification (layout)
|
.withJustification (layout)
|
||||||
|
|
|
||||||
|
|
@ -419,7 +419,7 @@ void TextLayout::createStandardLayout (const AttributedString& text)
|
||||||
.withAdditiveLineSpacing (text.getLineSpacing());
|
.withAdditiveLineSpacing (text.getLineSpacing());
|
||||||
|
|
||||||
if (text.getWordWrap() != AttributedString::none)
|
if (text.getWordWrap() != AttributedString::none)
|
||||||
shapedTextOptions = shapedTextOptions.withMaxWidth (width);
|
shapedTextOptions = shapedTextOptions.withWordWrapWidth (width);
|
||||||
|
|
||||||
ShapedText st { text.getText(), shapedTextOptions };
|
ShapedText st { text.getText(), shapedTextOptions };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -950,7 +950,7 @@ void TextEditor::updateBaseShapedTextOptions()
|
||||||
.withLeading (lineSpacing);
|
.withLeading (lineSpacing);
|
||||||
|
|
||||||
if (wordWrap)
|
if (wordWrap)
|
||||||
options = options.withMaxWidth ((float) getMaximumTextWidth());
|
options = options.withWordWrapWidth ((float) getMaximumTextWidth());
|
||||||
else
|
else
|
||||||
options = options.withAlignmentWidth ((float) getMaximumTextWidth());
|
options = options.withAlignmentWidth ((float) getMaximumTextWidth());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue