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(),
|
||||
glyphs,
|
||||
lineLength,
|
||||
options.getMaxWidth(),
|
||||
options.getWordWrapWidth(),
|
||||
options.getAlignmentWidth(),
|
||||
options.getTrailingWhitespacesShouldFit());
|
||||
}();
|
||||
|
|
@ -344,8 +344,8 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
|||
const auto effectiveLength = options.getTrailingWhitespacesShouldFit() ? lastLineLengths.total
|
||||
: lastLineLengths.withoutTrailingWhitespaces;
|
||||
|
||||
if (! options.getMaxWidth().has_value()
|
||||
|| effectiveLength <= *options.getMaxWidth() + maxWidthTolerance)
|
||||
if (! options.getWordWrapWidth().has_value()
|
||||
|| effectiveLength <= *options.getWordWrapWidth() + maxWidthTolerance)
|
||||
return;
|
||||
|
||||
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();
|
||||
|
||||
if (! options.getMaxWidth().has_value()
|
||||
|| *options.getMaxWidth() >= ellipsisLength + length)
|
||||
if (! options.getWordWrapWidth().has_value()
|
||||
|| *options.getWordWrapWidth() >= ellipsisLength + length)
|
||||
{
|
||||
return { (int64) std::distance (lastLineGlyphs.begin(), it) + 1,
|
||||
(int64) lastLineGlyphs.size() };
|
||||
|
|
@ -378,8 +378,8 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
|||
{
|
||||
length -= it->advance.getX();
|
||||
|
||||
if (! options.getMaxWidth().has_value()
|
||||
|| *options.getMaxWidth() >= ellipsisLength + length)
|
||||
if (! options.getWordWrapWidth().has_value()
|
||||
|| *options.getWordWrapWidth() >= ellipsisLength + length)
|
||||
{
|
||||
return { 0, (int64) std::distance (lastLineGlyphs.begin(), it) };
|
||||
}
|
||||
|
|
@ -464,7 +464,7 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
|
|||
return getMainAxisLineAlignment (options.getJustification(),
|
||||
lineWithEllipsisGlyphs,
|
||||
getMainAxisLineLength (lineWithEllipsisGlyphs),
|
||||
options.getMaxWidth(),
|
||||
options.getWordWrapWidth(),
|
||||
options.getAlignmentWidth(),
|
||||
options.getTrailingWhitespacesShouldFit());
|
||||
}();
|
||||
|
|
|
|||
|
|
@ -1279,7 +1279,7 @@ void SimpleShapedText::shape (const String& data,
|
|||
for (const auto& lineRange : getLineRanges (data))
|
||||
{
|
||||
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())
|
||||
.withTrailingWhitespaceCanExtendBeyondMargin (! options.getTrailingWhitespacesShouldFit())
|
||||
.withForceConsumeFirstWord (! options.getAllowBreakingInsideWord())
|
||||
|
|
@ -1552,7 +1552,7 @@ struct SimpleShapedTextTests : public UnitTest
|
|||
String testString { text };
|
||||
|
||||
SimpleShapedText st { &testString, ShapedTextOptions{}.withFont (FontOptions { defaultTypeface })
|
||||
.withMaxWidth (maxWidth) };
|
||||
.withWordWrapWidth (maxWidth) };
|
||||
|
||||
auto success = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ private:
|
|||
{
|
||||
return std::tie (justification,
|
||||
readingDir,
|
||||
maxWidth,
|
||||
wordWrapWidth,
|
||||
alignmentWidth,
|
||||
height,
|
||||
fontsForRange,
|
||||
|
|
@ -81,28 +81,28 @@ public:
|
|||
The alignment width can be overriden using withAlignmentWidth, but currently we only need
|
||||
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
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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.
|
||||
|
||||
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& getJustification() const { return justification; }
|
||||
const auto& getMaxWidth() const { return maxWidth; }
|
||||
const auto& getWordWrapWidth() const { return wordWrapWidth; }
|
||||
const auto& getAlignmentWidth() const { return alignmentWidth; }
|
||||
const auto& getHeight() const { return height; }
|
||||
const auto& getFontsForRange() const { return fontsForRange; }
|
||||
|
|
@ -208,7 +208,7 @@ public:
|
|||
private:
|
||||
Justification justification { Justification::topLeft };
|
||||
std::optional<TextDirection> readingDir;
|
||||
std::optional<float> maxWidth;
|
||||
std::optional<float> wordWrapWidth;
|
||||
std::optional<float> alignmentWidth;
|
||||
std::optional<float> height;
|
||||
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ void GlyphArrangement::addCurtailedLineOfText (const Font& font, const String& t
|
|||
using namespace detail;
|
||||
|
||||
auto options = ShapedText::Options{}.withMaxNumLines (1)
|
||||
.withMaxWidth (maxWidthPixels)
|
||||
.withWordWrapWidth (maxWidthPixels)
|
||||
.withFont (font)
|
||||
.withBaselineAtZero()
|
||||
.withTrailingWhitespacesShouldFit (false);
|
||||
|
|
@ -225,7 +225,7 @@ void GlyphArrangement::addJustifiedText (const Font& font, const String& text,
|
|||
{
|
||||
using namespace detail;
|
||||
|
||||
ShapedText st { text, ShapedText::Options{}.withMaxWidth (maxLineWidth)
|
||||
ShapedText st { text, ShapedText::Options{}.withWordWrapWidth (maxLineWidth)
|
||||
.withJustification (horizontalLayout)
|
||||
.withFont (font)
|
||||
.withAdditiveLineSpacing (leading)
|
||||
|
|
@ -259,7 +259,7 @@ static auto createFittedText (const Font& f,
|
|||
{
|
||||
ShapedText st { text,
|
||||
baseOptions
|
||||
.withMaxWidth (width)
|
||||
.withWordWrapWidth (width)
|
||||
.withHeight (height)
|
||||
.withJustification (layout)
|
||||
.withFont (f)
|
||||
|
|
@ -275,7 +275,7 @@ static auto createFittedText (const Font& f,
|
|||
// First attempt: try to squash the entire text on a single line
|
||||
{
|
||||
ShapedText st { trimmed, baseOptions.withFont (f)
|
||||
.withMaxWidth (width)
|
||||
.withWordWrapWidth (width)
|
||||
.withHeight (height)
|
||||
.withMaxNumLines (1)
|
||||
.withJustification (layout)
|
||||
|
|
@ -294,7 +294,7 @@ static auto createFittedText (const Font& f,
|
|||
ShapedText squashed { trimmed,
|
||||
baseOptions
|
||||
.withFont (f.withHorizontalScale (f.getHorizontalScale() * requiredRelativeScale))
|
||||
.withMaxWidth (width)
|
||||
.withWordWrapWidth (width)
|
||||
.withHeight (height)
|
||||
.withJustification (layout)
|
||||
.withTrailingWhitespacesShouldFit (false)};
|
||||
|
|
@ -310,7 +310,7 @@ static auto createFittedText (const Font& f,
|
|||
ShapedText squashed { trimmed,
|
||||
baseOptions
|
||||
.withFont (f.withHorizontalScale (minimumHorizontalScale))
|
||||
.withMaxWidth (width)
|
||||
.withWordWrapWidth (width)
|
||||
.withHeight (height)
|
||||
.withJustification (layout)
|
||||
.withMaxNumLines (1)
|
||||
|
|
@ -347,7 +347,7 @@ static auto createFittedText (const Font& f,
|
|||
ShapedText squashed { trimmed,
|
||||
baseOptions
|
||||
.withFont (font)
|
||||
.withMaxWidth (width)
|
||||
.withWordWrapWidth (width)
|
||||
.withHeight (height)
|
||||
.withMaxNumLines (numLines)
|
||||
.withJustification (layout)
|
||||
|
|
@ -376,7 +376,7 @@ static auto createFittedText (const Font& f,
|
|||
return ShapedText { trimmed,
|
||||
baseOptions
|
||||
.withFont (font.withHorizontalScale (horizontalScale))
|
||||
.withMaxWidth (width)
|
||||
.withWordWrapWidth (width)
|
||||
.withHeight (height)
|
||||
.withMaxNumLines (numLines)
|
||||
.withJustification (layout)
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ void TextLayout::createStandardLayout (const AttributedString& text)
|
|||
.withAdditiveLineSpacing (text.getLineSpacing());
|
||||
|
||||
if (text.getWordWrap() != AttributedString::none)
|
||||
shapedTextOptions = shapedTextOptions.withMaxWidth (width);
|
||||
shapedTextOptions = shapedTextOptions.withWordWrapWidth (width);
|
||||
|
||||
ShapedText st { text.getText(), shapedTextOptions };
|
||||
|
||||
|
|
|
|||
|
|
@ -950,7 +950,7 @@ void TextEditor::updateBaseShapedTextOptions()
|
|||
.withLeading (lineSpacing);
|
||||
|
||||
if (wordWrap)
|
||||
options = options.withMaxWidth ((float) getMaximumTextWidth());
|
||||
options = options.withWordWrapWidth ((float) getMaximumTextWidth());
|
||||
else
|
||||
options = options.withAlignmentWidth ((float) getMaximumTextWidth());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue