BScrollView: Ask the BScrollBars what their preferred sizes are.

This replaces the use of the hard-coded scroll bar size constants
and instead asks the scrollbars for their preferred sizes directly.

Right now, this is a giant no-op since BScrollBar just returns
the same hard-coded size when asked. The next commit will, however,
change that.
This commit is contained in:
Augustin Cavalier
2020-07-05 18:37:48 -04:00
parent 9481a1ec39
commit b022a5e224
2 changed files with 32 additions and 27 deletions
+4 -4
View File
@@ -106,11 +106,11 @@ private:
void _AlignScrollBars(bool horizontal, void _AlignScrollBars(bool horizontal,
bool vertical, BRect targetFrame); bool vertical, BRect targetFrame);
static BRect _ComputeFrame(BRect frame, bool horizontal, static BRect _ComputeFrame(BRect frame, BScrollBar* horizontal,
bool vertical, border_style border, BScrollBar* vertical, border_style border,
uint32 borders); uint32 borders);
static BRect _ComputeFrame(BView* target, bool horizontal, static BRect _ComputeFrame(BView* target, BScrollBar* horizontal,
bool vertical, border_style border, BScrollBar* vertical, border_style border,
uint32 borders); uint32 borders);
static float _BorderSize(border_style border); static float _BorderSize(border_style border);
static uint32 _ModifyFlags(uint32 flags, BView* target, static uint32 _ModifyFlags(uint32 flags, BView* target,
+28 -23
View File
@@ -29,9 +29,7 @@ static const float kPlainBorderSize = 1;
BScrollView::BScrollView(const char* name, BView* target, uint32 resizingMode, BScrollView::BScrollView(const char* name, BView* target, uint32 resizingMode,
uint32 flags, bool horizontal, bool vertical, border_style border) uint32 flags, bool horizontal, bool vertical, border_style border)
: :
BView(_ComputeFrame(target, horizontal, vertical, border, BView(BRect(), name, resizingMode, _ModifyFlags(flags, target, border)),
BControlLook::B_ALL_BORDERS), name, resizingMode,
_ModifyFlags(flags, target, border)),
fTarget(target), fTarget(target),
fBorder(border) fBorder(border)
{ {
@@ -208,9 +206,9 @@ BScrollView::AttachedToWindow()
} }
if (fHorizontalScrollBar != NULL) if (fHorizontalScrollBar != NULL)
fHorizontalScrollBar->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0); fHorizontalScrollBar->ResizeBy(-fHorizontalScrollBar->Frame().Width(), 0);
else if (fVerticalScrollBar != NULL) else if (fVerticalScrollBar != NULL)
fVerticalScrollBar->ResizeBy(0, -B_H_SCROLL_BAR_HEIGHT); fVerticalScrollBar->ResizeBy(0, -fHorizontalScrollBar->Frame().Height());
} }
@@ -780,6 +778,13 @@ BScrollView::_Init(bool horizontal, bool vertical)
AddChild(fVerticalScrollBar); AddChild(fVerticalScrollBar);
} }
if ((Flags() & B_SUPPORTS_LAYOUT) == 0) {
BRect frame = _ComputeFrame(fTarget, fHorizontalScrollBar,
fVerticalScrollBar, fBorder, BControlLook::B_ALL_BORDERS);
MoveTo(frame.LeftTop());
ResizeTo(frame.Size());
}
BRect targetFrame; BRect targetFrame;
if (fTarget) { if (fTarget) {
// layout target and add it // layout target and add it
@@ -795,9 +800,9 @@ BScrollView::_Init(bool horizontal, bool vertical)
// no target specified // no target specified
targetFrame = Bounds(); targetFrame = Bounds();
if (horizontal) if (horizontal)
targetFrame.bottom -= B_H_SCROLL_BAR_HEIGHT + 1; targetFrame.bottom -= fHorizontalScrollBar->PreferredSize().Height() + 1;
if (vertical) if (vertical)
targetFrame.right -= B_V_SCROLL_BAR_WIDTH + 1; targetFrame.right -= fVerticalScrollBar->PreferredSize().Width() + 1;
if (fBorder == B_FANCY_BORDER) { if (fBorder == B_FANCY_BORDER) {
targetFrame.bottom--; targetFrame.bottom--;
targetFrame.right--; targetFrame.right--;
@@ -827,12 +832,12 @@ BScrollView::_InnerFrame() const
float borderSize = _BorderSize(); float borderSize = _BorderSize();
if (fHorizontalScrollBar != NULL) { if (fHorizontalScrollBar != NULL) {
frame.bottom -= B_H_SCROLL_BAR_HEIGHT; frame.bottom -= fHorizontalScrollBar->PreferredSize().Height();
if (borderSize == 0) if (borderSize == 0)
frame.bottom--; frame.bottom--;
} }
if (fVerticalScrollBar != NULL) { if (fVerticalScrollBar != NULL) {
frame.right -= B_V_SCROLL_BAR_WIDTH; frame.right -= fVerticalScrollBar->PreferredSize().Width();
if (borderSize == 0) if (borderSize == 0)
frame.right--; frame.right--;
} }
@@ -854,8 +859,8 @@ BScrollView::_ComputeSize(BSize targetSize) const
BRect BRect
BScrollView::_ComputeFrame(BRect targetRect) const BScrollView::_ComputeFrame(BRect targetRect) const
{ {
return _ComputeFrame(targetRect, fHorizontalScrollBar != NULL, return _ComputeFrame(targetRect, fHorizontalScrollBar,
fVerticalScrollBar != NULL, fBorder, fBorders); fVerticalScrollBar, fBorder, fBorders);
} }
@@ -865,7 +870,7 @@ BScrollView::_AlignScrollBars(bool horizontal, bool vertical, BRect targetFrame)
if (horizontal) { if (horizontal) {
BRect rect = targetFrame; BRect rect = targetFrame;
rect.top = rect.bottom + 1; rect.top = rect.bottom + 1;
rect.bottom = rect.top + B_H_SCROLL_BAR_HEIGHT; rect.bottom = rect.top + fHorizontalScrollBar->PreferredSize().Height();
if (fBorder != B_NO_BORDER || vertical) { if (fBorder != B_NO_BORDER || vertical) {
// extend scrollbar so that it overlaps one pixel with vertical // extend scrollbar so that it overlaps one pixel with vertical
// scrollbar // scrollbar
@@ -884,7 +889,7 @@ BScrollView::_AlignScrollBars(bool horizontal, bool vertical, BRect targetFrame)
if (vertical) { if (vertical) {
BRect rect = targetFrame; BRect rect = targetFrame;
rect.left = rect.right + 1; rect.left = rect.right + 1;
rect.right = rect.left + B_V_SCROLL_BAR_WIDTH; rect.right = rect.left + fVerticalScrollBar->PreferredSize().Width();
if (fBorder != B_NO_BORDER || horizontal) { if (fBorder != B_NO_BORDER || horizontal) {
// extend scrollbar so that it overlaps one pixel with vertical // extend scrollbar so that it overlaps one pixel with vertical
// scrollbar // scrollbar
@@ -908,20 +913,20 @@ BScrollView::_AlignScrollBars(bool horizontal, bool vertical, BRect targetFrame)
It is used in the constructor and at other places. It is used in the constructor and at other places.
*/ */
/*static*/ BRect /*static*/ BRect
BScrollView::_ComputeFrame(BRect frame, bool horizontal, bool vertical, BScrollView::_ComputeFrame(BRect frame, BScrollBar* horizontal,
border_style border, uint32 borders) BScrollBar* vertical, border_style border, uint32 borders)
{ {
if (vertical) if (vertical != NULL)
frame.right += B_V_SCROLL_BAR_WIDTH; frame.right += vertical->PreferredSize().Width();
if (horizontal) if (horizontal != NULL)
frame.bottom += B_H_SCROLL_BAR_HEIGHT; frame.bottom += horizontal->PreferredSize().Height();
_InsetBorders(frame, border, borders, true); _InsetBorders(frame, border, borders, true);
if (_BorderSize(border) == 0) { if (_BorderSize(border) == 0) {
if (vertical) if (vertical != NULL)
frame.right++; frame.right++;
if (horizontal) if (horizontal != NULL)
frame.bottom++; frame.bottom++;
} }
@@ -930,8 +935,8 @@ BScrollView::_ComputeFrame(BRect frame, bool horizontal, bool vertical,
/*static*/ BRect /*static*/ BRect
BScrollView::_ComputeFrame(BView *target, bool horizontal, bool vertical, BScrollView::_ComputeFrame(BView *target, BScrollBar* horizontal,
border_style border, uint32 borders) BScrollBar* vertical, border_style border, uint32 borders)
{ {
return _ComputeFrame(target != NULL ? target->Frame() return _ComputeFrame(target != NULL ? target->Frame()
: BRect(0, 0, 16, 16), horizontal, vertical, border, borders); : BRect(0, 0, 16, 16), horizontal, vertical, border, borders);