mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
TextEditor: Take border size into account when calculating text bounds
This commit is contained in:
parent
963fd79e6a
commit
3fd4f7a231
2 changed files with 16 additions and 12 deletions
|
|
@ -1472,14 +1472,20 @@ Rectangle<float> TextEditor::getCaretRectangleFloat() const
|
|||
return { anchor.x, anchor.y, 2.0f, cursorHeight };
|
||||
}
|
||||
|
||||
Point<int> TextEditor::getTextOffset() const noexcept
|
||||
{
|
||||
Iterator i (*this);
|
||||
auto yOffset = i.getYOffset();
|
||||
|
||||
return { getLeftIndent() + borderSize.getLeft() - viewport->getViewPositionX(),
|
||||
roundToInt ((float) getTopIndent() + (float) borderSize.getTop() + yOffset) - viewport->getViewPositionY() };
|
||||
}
|
||||
|
||||
RectangleList<int> TextEditor::getTextBounds (Range<int> textRange)
|
||||
{
|
||||
RectangleList<int> boundingBox;
|
||||
|
||||
Iterator i (*this);
|
||||
auto yOffset = i.getYOffset();
|
||||
|
||||
for (auto lineRange : i.getLineRanges())
|
||||
for (auto lineRange : Iterator { *this }.getLineRanges())
|
||||
{
|
||||
auto intersection = lineRange.getIntersectionWith (textRange);
|
||||
|
||||
|
|
@ -1498,9 +1504,7 @@ RectangleList<int> TextEditor::getTextBounds (Range<int> textRange)
|
|||
}
|
||||
}
|
||||
|
||||
boundingBox.offsetAll (getLeftIndent() - viewport->getViewPositionX(),
|
||||
roundToInt ((float) getTopIndent() + yOffset) - viewport->getViewPositionY());
|
||||
|
||||
boundingBox.offsetAll (getTextOffset());
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
|
|
@ -1653,10 +1657,10 @@ void TextEditor::moveCaretTo (const int newPosition, const bool isSelecting)
|
|||
|
||||
int TextEditor::getTextIndexAt (const int x, const int y) const
|
||||
{
|
||||
Iterator i (*this);
|
||||
const auto offset = getTextOffset();
|
||||
|
||||
return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent - borderSize.getLeft()),
|
||||
(float) (y + viewport->getViewPositionY() - topIndent - borderSize.getTop()) - i.getYOffset());
|
||||
return indexAtPosition ((float) (x - offset.x),
|
||||
(float) (y - offset.y));
|
||||
}
|
||||
|
||||
void TextEditor::insertTextAtCaret (const String& t)
|
||||
|
|
@ -1746,8 +1750,7 @@ void TextEditor::drawContent (Graphics& g)
|
|||
g.setColour (findColour (highlightColourId).withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
|
||||
|
||||
auto boundingBox = getTextBounds (selection);
|
||||
boundingBox.offsetAll (viewport->getViewPositionX() - leftIndent,
|
||||
viewport->getViewPositionY() - roundToInt ((float) topIndent + yOffset));
|
||||
boundingBox.offsetAll (-getTextOffset());
|
||||
|
||||
g.fillPath (boundingBox.toPath(), transform);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -828,6 +828,7 @@ private:
|
|||
bool undoOrRedo (bool shouldUndo);
|
||||
UndoManager* getUndoManager() noexcept;
|
||||
void setSelection (Range<int>) noexcept;
|
||||
Point<int> getTextOffset() const noexcept;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextEditor)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue