2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
7 #include "ScrollableGroupView.h"
10 #include <SpaceLayoutItem.h>
13 ScrollableGroupView::ScrollableGroupView()
15 BGroupView(B_VERTICAL
, 0.0)
17 AddChild(BSpaceLayoutItem::CreateGlue());
22 ScrollableGroupView::MinSize()
24 BSize minSize
= BGroupView::MinSize();
25 return BSize(minSize
.width
, 80);
30 ScrollableGroupView::DoLayout()
32 BGroupView::DoLayout();
34 BScrollBar
* scrollBar
= ScrollBar(B_VERTICAL
);
36 if (scrollBar
== NULL
)
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);
48 layoutHeight
= lastItem
->Frame().bottom
;
50 float viewHeight
= Bounds().Height();
52 float max
= layoutHeight
- viewHeight
;
53 scrollBar
->SetRange(0, max
);
55 scrollBar
->SetProportion(viewHeight
/ layoutHeight
);
57 scrollBar
->SetProportion(1);