Skip to content

Commit a272b35

Browse files
committed
TextEditor: Fix lines being invisible beyond the word wrap width
1 parent 0e4287d commit a272b35

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

modules/juce_graphics/detail/juce_JustifiedText.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions
327327

328328
rangesToDraw.set ({ 0, (int64) shapedText.getGlyphs().size() }, DrawType::normal, ops);
329329

330+
if (options.getDrawLinesInFull())
331+
return;
332+
330333
//==============================================================================
331334
// Everything above this line should work well given none of the lines were too
332335
// long. When Options::getMaxNumLines() == 0 this is guaranteed by SimpleShapedText.

modules/juce_graphics/detail/juce_SimpleShapedText.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ class ShapedTextOptions
179179
return withMember (*this, &ShapedTextOptions::ellipsis, std::move (x));
180180
}
181181

182+
/* Draw each line in its entirety even if it goes beyond wordWrapWidth. This means that even
183+
if configured, an ellipsis will never be inserted.
184+
185+
This is used by the TextEditor where the Viewport guarantees that all text will be viewable
186+
even beyond the word wrap width.
187+
*/
188+
[[nodiscard]] ShapedTextOptions withDrawLinesInFull (bool x = true) const
189+
{
190+
return withMember (*this, &ShapedTextOptions::drawLinesInFull, std::move (x));
191+
}
192+
182193
[[nodiscard]] ShapedTextOptions withReadingDirection (std::optional<TextDirection> x) const
183194
{
184195
return withMember (*this, &ShapedTextOptions::readingDir, x);
@@ -203,6 +214,7 @@ class ShapedTextOptions
203214
const auto& getTrailingWhitespacesShouldFit() const { return trailingWhitespacesShouldFit; }
204215
const auto& getMaxNumLines() const { return maxNumLines; }
205216
const auto& getEllipsis() const { return ellipsis; }
217+
const auto& getDrawLinesInFull() const { return drawLinesInFull; }
206218
const auto& getAllowBreakingInsideWord() const { return allowBreakingInsideWord; }
207219

208220
private:
@@ -227,6 +239,7 @@ class ShapedTextOptions
227239
bool baselineAtZero = false;
228240
bool allowBreakingInsideWord = false;
229241
bool trailingWhitespacesShouldFit = true;
242+
bool drawLinesInFull = false;
230243
int64 maxNumLines = std::numeric_limits<int64>::max();
231244
String ellipsis;
232245
};

modules/juce_gui_basics/widgets/juce_TextEditor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ void TextEditor::updateBaseShapedTextOptions()
947947
{
948948
auto options = detail::ShapedText::Options{}.withTrailingWhitespacesShouldFit (true)
949949
.withJustification (getJustificationType().getOnlyHorizontalFlags())
950+
.withDrawLinesInFull()
950951
.withLeading (lineSpacing);
951952

952953
if (wordWrap)

0 commit comments

Comments
 (0)