Browse Source

Fixed small inaccuracy in text editor width.

tags/2021-05-28
jules 12 years ago
parent
commit
1ff5fb6ee6
1 changed files with 18 additions and 10 deletions
  1. +18
    -10
      modules/juce_gui_basics/widgets/juce_TextEditor.cpp

+ 18
- 10
modules/juce_gui_basics/widgets/juce_TextEditor.cpp View File

@@ -39,19 +39,20 @@ struct TextAtom
{
if (passwordCharacter == 0)
return atomText;
else
return String::repeatedString (String::charToString (passwordCharacter),
atomText.length());
return String::repeatedString (String::charToString (passwordCharacter),
atomText.length());
}
String getTrimmedText (const juce_wchar passwordCharacter) const
{
if (passwordCharacter == 0)
return atomText.substring (0, numChars);
else if (isNewLine())
if (isNewLine())
return String::empty;
else
return String::repeatedString (String::charToString (passwordCharacter), numChars);
return String::repeatedString (String::charToString (passwordCharacter), numChars);
}
};
@@ -647,10 +648,15 @@ public:
atom->getText (passwordCharacter),
atomX, 0.0f);
const int numGlyphs = g.getNumGlyphs();
int j;
for (j = 0; j < g.getNumGlyphs(); ++j)
if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
for (j = 0; j < numGlyphs; ++j)
{
const PositionedGlyph& pg = g.getGlyph(j);
if ((pg.getLeft() + pg.getRight()) / 2 > xToFind)
break;
}
return indexInText + j;
}
@@ -1384,9 +1390,11 @@ Rectangle<int> TextEditor::getCaretRectangle()
}
//==============================================================================
enum { rightEdgeSpace = 2 };
float TextEditor::getWordWrapWidth() const
{
return wordWrap ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
return wordWrap ? (float) (viewport->getMaximumVisibleWidth() - (leftIndent + rightEdgeSpace + 1))
: std::numeric_limits<float>::max();
}
@@ -1407,7 +1415,7 @@ void TextEditor::updateTextHolderSize()
const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
currentFont.getHeight()));
textHolder->setSize (w + 2, h + 1); // (the +2 allows a bit of space for the cursor to be at the right-hand-edge)
textHolder->setSize (w + rightEdgeSpace, h + 1); // (allows a bit of space for the cursor to be at the right-hand-edge)
}
}


Loading…
Cancel
Save