Add _ViewWidth(), _ViewHeight(), _TextWidth(), _TextHeight()

private convenience methods to calculate the text view width and
height with insets and the text rect width and height without
insets respectively.

Also add _ViewRect() and _TextRect() methods for completeness,
but they are not currently used.

Change-Id: I0582bc93a0a3a6820bbb2262a1d726457309ab9f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7162
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
John Scipione 2023-11-28 18:52:20 -05:00 committed by Adrien Destugues
parent 2af0f027cb
commit 64a2e73375
2 changed files with 75 additions and 10 deletions

View File

@ -418,6 +418,14 @@ private:
void _UpdateInsets(const BRect& rect);
float _ViewWidth();
float _ViewHeight();
BRect _ViewRect();
float _TextWidth();
float _TextHeight();
BRect _TextRect();
private:
BPrivate::TextGapBuffer* fText;
LineBuffer* fLines;

View File

@ -816,8 +816,7 @@ BTextView::FrameResized(float newWidth, float newHeight)
// don't recalculate line breaks,
// move text rect into position and redraw.
float dataWidth = fLayoutData->leftInset
+ fTextRect.Width() + fLayoutData->rightInset;
float dataWidth = _TextWidth();
newWidth = std::max(dataWidth, newWidth);
// align rect
@ -2810,8 +2809,7 @@ BTextView::_ValidateLayoutData()
fLayoutData->min = min;
// compute our preferred size
fLayoutData->preferred.height = fTextRect.Height()
+ fLayoutData->topInset + fLayoutData->bottomInset;
fLayoutData->preferred.height = _TextHeight();
if (fWrap)
fLayoutData->preferred.width = min.width + 5 * lineHeight;
@ -5050,8 +5048,7 @@ BTextView::_UpdateScrollbars()
// do we have a horizontal scroll bar?
if (horizontalScrollBar != NULL) {
long viewWidth = bounds.IntegerWidth();
long dataWidth = (long)ceilf(fTextRect.IntegerWidth()
+ fLayoutData->leftInset + fLayoutData->rightInset);
long dataWidth = (long)ceilf(_TextWidth());
long maxRange = dataWidth - viewWidth;
maxRange = std::max(maxRange, 0l);
@ -5066,8 +5063,7 @@ BTextView::_UpdateScrollbars()
// how about a vertical scroll bar?
if (verticalScrollBar != NULL) {
long viewHeight = bounds.IntegerHeight();
long dataHeight = (long)ceilf(fLayoutData->topInset
+ fTextRect.IntegerHeight() + fLayoutData->bottomInset);
long dataHeight = (long)ceilf(_TextHeight());
long maxRange = dataHeight - viewHeight;
maxRange = std::max(maxRange, 0l);
@ -5122,8 +5118,7 @@ BTextView::_AutoResize(bool redraw)
// NOTE: This container view thing is only used by Tracker.
// move container view if not left aligned
float oldWidth = Bounds().Width();
float newWidth = fLayoutData->leftInset + fTextRect.Width()
+ fLayoutData->rightInset;
float newWidth = _TextWidth();
float right = oldWidth - newWidth;
if (fAlignment == B_ALIGN_CENTER)
@ -6041,6 +6036,68 @@ BTextView::_UpdateInsets(const BRect& rect)
}
float
BTextView::_ViewWidth()
{
return Bounds().Width()
- fLayoutData->leftInset
- fLayoutData->rightInset;
}
float
BTextView::_ViewHeight()
{
return Bounds().Height()
- fLayoutData->topInset
- fLayoutData->bottomInset;
}
BRect
BTextView::_ViewRect()
{
BRect rect(Bounds());
rect.left += fLayoutData->leftInset;
rect.top += fLayoutData->topInset;
rect.right -= fLayoutData->rightInset;
rect.bottom -= fLayoutData->bottomInset;
return rect;
}
float
BTextView::_TextWidth()
{
return fTextRect.Width()
+ fLayoutData->leftInset
+ fLayoutData->rightInset;
}
float
BTextView::_TextHeight()
{
return fTextRect.Height()
+ fLayoutData->topInset
+ fLayoutData->bottomInset;
}
BRect
BTextView::_TextRect()
{
BRect rect(fTextRect);
rect.left -= fLayoutData->leftInset;
rect.top -= fLayoutData->topInset;
rect.right += fLayoutData->rightInset;
rect.bottom += fLayoutData->bottomInset;
return rect;
}
// #pragma mark - BTextView::TextTrackState