repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / ui_generic / ScrollableGroupView.cpp
blobf876e46e9902b75d4eb139ace84500d42fd0f856
1 /*
2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
7 #include "ScrollableGroupView.h"
9 #include <ScrollBar.h>
10 #include <SpaceLayoutItem.h>
13 ScrollableGroupView::ScrollableGroupView()
15 BGroupView(B_VERTICAL, 0.0)
17 AddChild(BSpaceLayoutItem::CreateGlue());
21 BSize
22 ScrollableGroupView::MinSize()
24 BSize minSize = BGroupView::MinSize();
25 return BSize(minSize.width, 80);
29 void
30 ScrollableGroupView::DoLayout()
32 BGroupView::DoLayout();
34 BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
36 if (scrollBar == NULL)
37 return;
39 BRect layoutArea = GroupLayout()->LayoutArea();
40 float layoutHeight = layoutArea.Height();
41 // Min size is not reliable with HasHeightForWidth() children,
42 // since it does not reflect how those children are currently
43 // laid out, but what their theoretical minimum size would be.
45 BLayoutItem* lastItem = GroupLayout()->ItemAt(
46 GroupLayout()->CountItems() - 1);
47 if (lastItem != NULL)
48 layoutHeight = lastItem->Frame().bottom;
50 float viewHeight = Bounds().Height();
52 float max = layoutHeight- viewHeight;
53 scrollBar->SetRange(0, max);
54 if (layoutHeight > 0)
55 scrollBar->SetProportion(viewHeight / layoutHeight);
56 else
57 scrollBar->SetProportion(1);