HaikuDepot: Let BScrollView handle resizing the scrollbar bounds.

This way, it will also resize the views properly when the scrollbars
are larger.

Fixes part of #16408.
This commit is contained in:
Augustin Cavalier 2020-07-28 21:06:03 -04:00
parent a06b52bee8
commit 494bd14713
2 changed files with 3 additions and 30 deletions

View File

@ -619,7 +619,7 @@ FeaturedPackagesView::FeaturedPackagesView()
fPackagesView = new StackedFeaturedPackagesView();
fScrollView = new BScrollView("featured packages scroll view",
fPackagesView, B_FOLLOW_ALL_SIDES, 0, false, true, B_FANCY_BORDER);
fPackagesView, 0, false, true, B_FANCY_BORDER);
BLayoutBuilder::Group<>(this)
.Add(fScrollView, 1.0f);
@ -682,37 +682,11 @@ FeaturedPackagesView::DoLayout()
}
void
FeaturedPackagesView::FrameResized(float width, float height)
{
BView::FrameResized(width, height);
_AdjustViews();
}
void
FeaturedPackagesView::_AdjustViews()
{
BScrollBar* scrollBar = fScrollView->ScrollBar(B_VERTICAL);
BSize scrollViewSize = fScrollView->Frame().Size();
float width = scrollViewSize.Width() - (B_V_SCROLL_BAR_WIDTH + 4.0f);
// +2 for border; both sides
float height = scrollViewSize.Height() - 4.0;
// +2 for border; top and bottom
fPackagesView->ResizeTo(width, height);
if (fPackagesView->IsEmpty()) {
scrollBar->SetRange(0, 0);
scrollBar->SetProportion(1);
}
else {
float packagesHeight = fPackagesView->PreferredSize().Height();
float packagesActualHeight = fmaxf(packagesHeight, height);
scrollBar->SetRange(0, packagesActualHeight - scrollViewSize.Height());
scrollBar->SetProportion(
scrollViewSize.Height() / packagesActualHeight);
}
fScrollView->FrameResized(fScrollView->Frame().Width(),
fScrollView->Frame().Height());
}

View File

@ -21,7 +21,6 @@ public:
FeaturedPackagesView();
virtual ~FeaturedPackagesView();
virtual void FrameResized(float width, float height);
virtual void DoLayout();
void AddPackage(const PackageInfoRef& package);