BScrollView: Resize scrollbars dynamically based on target's B_SUPPORTS_LAYOUT...

...instead of the BScrollView itself's layout flag. Thanks to Adrien and
Kacper for discussion on the mailing list.
This commit is contained in:
Augustin Cavalier
2019-01-27 14:35:32 -05:00
parent b2d62af35a
commit 4854630d29
2 changed files with 13 additions and 10 deletions
+2 -1
View File
@@ -113,7 +113,8 @@ private:
bool vertical, border_style border, bool vertical, border_style border,
uint32 borders); uint32 borders);
static float _BorderSize(border_style border); static float _BorderSize(border_style border);
static int32 _ModifyFlags(int32 flags, border_style border); static uint32 _ModifyFlags(uint32 flags, BView* target,
border_style border);
static void _InsetBorders(BRect& frame, border_style border, static void _InsetBorders(BRect& frame, border_style border,
uint32 borders, bool expand = false); uint32 borders, bool expand = false);
private: private:
+11 -9
View File
@@ -31,7 +31,7 @@ BScrollView::BScrollView(const char* name, BView* target, uint32 resizingMode,
: :
BView(_ComputeFrame(target, horizontal, vertical, border, BView(_ComputeFrame(target, horizontal, vertical, border,
BControlLook::B_ALL_BORDERS), name, resizingMode, BControlLook::B_ALL_BORDERS), name, resizingMode,
_ModifyFlags(flags, border)), _ModifyFlags(flags, target, border)),
fTarget(target), fTarget(target),
fBorder(border) fBorder(border)
{ {
@@ -42,7 +42,7 @@ BScrollView::BScrollView(const char* name, BView* target, uint32 resizingMode,
BScrollView::BScrollView(const char* name, BView* target, uint32 flags, BScrollView::BScrollView(const char* name, BView* target, uint32 flags,
bool horizontal, bool vertical, border_style border) bool horizontal, bool vertical, border_style border)
: :
BView(name, _ModifyFlags(flags | B_SUPPORTS_LAYOUT, border)), BView(name, _ModifyFlags(flags, target, border)),
fTarget(target), fTarget(target),
fBorder(border) fBorder(border)
{ {
@@ -273,8 +273,8 @@ BScrollView::FrameResized(float newWidth, float newHeight)
const BRect bounds = Bounds(); const BRect bounds = Bounds();
if ((Flags() & B_SUPPORTS_LAYOUT) != 0) { if (fTarget != NULL && (fTarget->Flags() & B_SUPPORTS_LAYOUT) != 0) {
BSize size = fTarget != NULL ? fTarget->PreferredSize() : BSize(); BSize size = fTarget->PreferredSize();
if (fHorizontalScrollBar != NULL) { if (fHorizontalScrollBar != NULL) {
float delta = size.Width() - bounds.Width(), float delta = size.Width() - bounds.Width(),
proportion = bounds.Width() / size.Width(); proportion = bounds.Width() / size.Width();
@@ -472,7 +472,7 @@ BScrollView::SetBorder(border_style border)
if ((Flags() & B_SUPPORTS_LAYOUT) != 0) { if ((Flags() & B_SUPPORTS_LAYOUT) != 0) {
fBorder = border; fBorder = border;
SetFlags(_ModifyFlags(Flags(), border)); SetFlags(_ModifyFlags(Flags(), fTarget, border));
DoLayout(); DoLayout();
Invalidate(); Invalidate();
@@ -520,7 +520,7 @@ BScrollView::SetBorder(border_style border)
fVerticalScrollBar->ResizeBy(0, resize + verticalGap - change); fVerticalScrollBar->ResizeBy(0, resize + verticalGap - change);
} }
SetFlags(_ModifyFlags(Flags(), border)); SetFlags(_ModifyFlags(Flags(), fTarget, border));
} }
@@ -621,6 +621,8 @@ BScrollView::SetTarget(BView* target)
// be added top most in the list (which is important // be added top most in the list (which is important
// for unarchiving) // for unarchiving)
} }
SetFlags(_ModifyFlags(Flags(), fTarget, fBorder));
} }
@@ -952,10 +954,10 @@ BScrollView::_BorderSize(border_style border)
/*! This method changes the "flags" argument as passed on to /*! This method changes the "flags" argument as passed on to
the BView constructor. the BView constructor.
*/ */
/*static*/ int32 /*static*/ uint32
BScrollView::_ModifyFlags(int32 flags, border_style border) BScrollView::_ModifyFlags(uint32 flags, BView* target, border_style border)
{ {
if ((flags & B_SUPPORTS_LAYOUT) != 0) if (target != NULL && (target->Flags() & B_SUPPORTS_LAYOUT) != 0)
flags |= B_FRAME_EVENTS; flags |= B_FRAME_EVENTS;
// We either need B_FULL_UPDATE_ON_RESIZE or B_FRAME_EVENTS if we have // We either need B_FULL_UPDATE_ON_RESIZE or B_FRAME_EVENTS if we have