From 0e4287df5202ecd89f396edce4556e6b0066b21d Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 21 May 2025 13:13:27 +0200 Subject: [PATCH] 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. --- .../detail/juce_JustifiedText.cpp | 16 +++++++-------- .../detail/juce_SimpleShapedText.cpp | 4 ++-- .../detail/juce_SimpleShapedText.h | 20 +++++++++---------- .../fonts/juce_GlyphArrangement.cpp | 16 +++++++-------- .../juce_graphics/fonts/juce_TextLayout.cpp | 2 +- .../widgets/juce_TextEditor.cpp | 2 +- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/modules/juce_graphics/detail/juce_JustifiedText.cpp b/modules/juce_graphics/detail/juce_JustifiedText.cpp index 124c28716c..c828351e14 100644 --- a/modules/juce_graphics/detail/juce_JustifiedText.cpp +++ b/modules/juce_graphics/detail/juce_JustifiedText.cpp @@ -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()); }(); diff --git a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp index 5aadd377e9..e321349c91 100644 --- a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp +++ b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp @@ -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; diff --git a/modules/juce_graphics/detail/juce_SimpleShapedText.h b/modules/juce_graphics/detail/juce_SimpleShapedText.h index 8c9f057aee..1e5de9614d 100644 --- a/modules/juce_graphics/detail/juce_SimpleShapedText.h +++ b/modules/juce_graphics/detail/juce_SimpleShapedText.h @@ -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 readingDir; - std::optional maxWidth; + std::optional wordWrapWidth; std::optional alignmentWidth; std::optional height; diff --git a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp index 6bf8572a0f..9178456a2e 100644 --- a/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp +++ b/modules/juce_graphics/fonts/juce_GlyphArrangement.cpp @@ -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) diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index c38751420e..573430e0fc 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -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 }; diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index 1414c1383e..a79b86ff6c 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -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());