Update LayoutTest1.cpp to use the templatized layout builders, and compile while I'm at it.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42346 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alex Wilson
2011-06-30 20:09:27 +00:00
parent 9879c0bc8b
commit b0b8840701
+123 -159
View File
@@ -7,17 +7,12 @@
#include <Application.h> #include <Application.h>
#include <Button.h> #include <Button.h>
#include <CardLayout.h> #include <CardLayout.h>
#include <GridLayoutBuilder.h> #include <LayoutBuilder.h>
#include <GridView.h>
#include <GroupLayoutBuilder.h>
#include <GroupView.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <ListView.h> #include <ListView.h>
#include <MenuField.h> #include <MenuField.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <SpaceLayoutItem.h>
#include <SplitLayoutBuilder.h>
#include <String.h> #include <String.h>
#include <StringView.h> #include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
@@ -298,10 +293,10 @@ struct Test : BHandler {
BView* rootView; BView* rootView;
BString description; BString description;
Test(const char* name, BView* view, const char* description) Test(const char* name, const char* description)
: BHandler(name), : BHandler(name),
name(name), name(name),
rootView(view), rootView(new BView(name, 0)),
description(description) description(description)
{ {
} }
@@ -319,42 +314,41 @@ struct Test : BHandler {
// GroupLayoutTest1 // GroupLayoutTest1
struct GroupLayoutTest1 : public Test { struct GroupLayoutTest1 : public Test {
GroupLayoutTest1() GroupLayoutTest1()
: Test("Group", NULL, "Simple BGroupLayout.") :
Test("Group", "Simple BGroupLayout.")
{ {
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10) .AddGroup(B_VERTICAL)
.Add(toggleRowButton = new BButton("Toggle Row", .Add(toggleRowButton = new BButton("Toggle Row",
new BMessage(MSG_TOGGLE_1))) new BMessage(MSG_TOGGLE_1)))
.Add(toggleViewButton = new BButton("Toggle View", .Add(toggleViewButton = new BButton("Toggle View",
new BMessage(MSG_TOGGLE_2))) new BMessage(MSG_TOGGLE_2)))
.AddGlue() .AddGlue()
.End() .End()
// test views // test views
.AddGroup(B_VERTICAL, 10) .AddGroup(B_VERTICAL)
// row 1 // row 1
.AddGroup(B_HORIZONTAL, 10, 1) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1)
.Add(new TestView(), 1) .Add(new TestView(), 1)
.Add(toggledView = new TestView(), 2) .Add(toggledView = new TestView(), 2)
.Add(new TestView(), 3) .Add(new TestView(), 3)
.End() .End()
// row 2 // row 2
.AddGroup(B_HORIZONTAL, 10, 2).GetTopView(&toggledRow) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 2)
.GetView(&toggledRow)
.Add(new TestView()) .Add(new TestView())
.Add(new TestView()) .Add(new TestView())
.Add(new TestView()) .Add(new TestView())
.End() .End()
// row 3 // row 3
.AddGroup(B_HORIZONTAL, 10, 3) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 3)
.Add(new TestView(), 3) .Add(new TestView(), 3)
.Add(new TestView(), 2) .Add(new TestView(), 2)
.Add(new TestView(), 1) .Add(new TestView(), 1);
.End()
.End()
;
} }
virtual void RegisterListeners() virtual void RegisterListeners()
@@ -401,8 +395,7 @@ private:
// GroupAlignedLayoutTest1 // GroupAlignedLayoutTest1
struct GroupAlignedLayoutTest1 : public Test { struct GroupAlignedLayoutTest1 : public Test {
GroupAlignedLayoutTest1() GroupAlignedLayoutTest1()
: Test("Group aligned", NULL, : Test("Group aligned", "Simple BGroupLayout, rows 1 and 3 aligned.")
"Simple BGroupLayout, rows 1 and 3 aligned.")
{ {
BGroupView* rootView = new BGroupView(B_HORIZONTAL, 10); BGroupView* rootView = new BGroupView(B_HORIZONTAL, 10);
this->rootView = rootView; this->rootView = rootView;
@@ -503,20 +496,20 @@ private:
// GridLayoutTest1 // GridLayoutTest1
struct GridLayoutTest1 : public Test { struct GridLayoutTest1 : public Test {
GridLayoutTest1() GridLayoutTest1()
: Test("Grid", NULL, "Simple BGridLayout.") : Test("Grid", "Simple BGridLayout.")
{ {
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10) .AddGroup(B_VERTICAL)
.Add(toggleView1Button = new BButton("Toggle View 1", .Add(toggleView1Button = new BButton("Toggle View 1",
new BMessage(MSG_TOGGLE_1))) new BMessage(MSG_TOGGLE_1)))
.Add(toggleView2Button = new BButton("Toggle View 2", .Add(toggleView2Button = new BButton("Toggle View 2",
new BMessage(MSG_TOGGLE_2))) new BMessage(MSG_TOGGLE_2)))
.AddGlue() .AddGlue()
.End() .End()
// test views // test views
.Add(BGridLayoutBuilder(10, 10) .AddGrid()
// row 1 // row 1
.Add(toggledView1 = new TestView(), 0, 0, 3, 1) .Add(toggledView1 = new TestView(), 0, 0, 3, 1)
.Add(new TestView(), 3, 0) .Add(new TestView(), 3, 0)
@@ -550,9 +543,7 @@ struct GridLayoutTest1 : public Test {
.SetRowWeight(0, 1) .SetRowWeight(0, 1)
.SetRowWeight(1, 2) .SetRowWeight(1, 2)
.SetRowWeight(2, 3) .SetRowWeight(2, 3)
.SetRowWeight(3, 4) .SetRowWeight(3, 4);
)
;
} }
virtual void RegisterListeners() virtual void RegisterListeners()
@@ -599,46 +590,45 @@ private:
// SplitterGroupLayoutTest1 // SplitterGroupLayoutTest1
struct SplitterGroupLayoutTest1 : public Test { struct SplitterGroupLayoutTest1 : public Test {
SplitterGroupLayoutTest1() SplitterGroupLayoutTest1()
: Test("Group, splitters 1", NULL, "BGroupLayout with BSplitters.") : Test("Group, splitters 1", "BGroupLayout with BSplitters.")
{ {
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10) .AddGroup(B_VERTICAL)
.Add(toggleRowButton = new BButton("Toggle Row", .Add(toggleRowButton = new BButton("Toggle Row",
new BMessage(MSG_TOGGLE_1))) new BMessage(MSG_TOGGLE_1)))
.Add(toggleViewButton = new BButton("Toggle View", .Add(toggleViewButton = new BButton("Toggle View",
new BMessage(MSG_TOGGLE_2))) new BMessage(MSG_TOGGLE_2)))
.AddGlue() .AddGlue()
.End() .End()
// test views // test views
.Add(BSplitLayoutBuilder(B_VERTICAL, 10) .AddSplit(B_VERTICAL)
// row 1 // row 1
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1)
.Add(new TestView(), 1) .Add(new TestView(), 1)
.Add(toggledView = new TestView(), 2) .Add(toggledView = new TestView(), 2)
.Add(new TestView(), 3) .Add(new TestView(), 3)
, 1) .End()
// make the row uncollapsible // make the row uncollapsible
.SetCollapsible(false) .SetCollapsible(false)
// row 2 // row 2
.Add(toggledRow = BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 2)
.GetView(&toggledRow)
.Add(new TestView()) .Add(new TestView())
.Add(new TestView()) .Add(new TestView())
.Add(new TestView()) .Add(new TestView())
, 2) .End()
// row 3 // row 3
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 3)
.Add(new TestView(), 3) .Add(new TestView(), 3)
.Add(toggledView = new TestView(), 2) .Add(toggledView = new TestView(), 2)
.Add(new TestView(), 1) .Add(new TestView(), 1)
, 3) .End()
// make the row uncollapsible // make the row uncollapsible
.SetCollapsible(false) .SetCollapsible(false);
)
;
} }
virtual void RegisterListeners() virtual void RegisterListeners()
@@ -685,24 +675,21 @@ private:
// SplitterGroupLayoutTest2 // SplitterGroupLayoutTest2
struct SplitterGroupLayoutTest2 : public Test { struct SplitterGroupLayoutTest2 : public Test {
SplitterGroupLayoutTest2() SplitterGroupLayoutTest2()
: Test("Group, splitters 2", NULL, : Test("Group, splitters 2",
"BGroupLayout with BSplitters. Restricted maximum widths.") "BGroupLayout with BSplitters. Restricted maximum widths.")
{ {
TestView* testView1 = new TestView(); TestView* testView1 = new TestView();
TestView* testView2 = new TestView(); TestView* testView2 = new TestView();
TestView* testView3 = new TestView(); TestView* testView3 = new TestView();
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// test views // test views
.AddGroup(B_VERTICAL, 10) .AddGroup(B_VERTICAL)
// split view // split view
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL)
.Add(testView1, 0) .Add(testView1, 0)
.Add(testView2, 1) .Add(testView2, 1)
.Add(testView3, 2) .Add(testView3, 2);
)
.End()
;
// set maximal width on the test views // set maximal width on the test views
testView1->SetExplicitMaxSize(BSize(100, B_SIZE_UNSET)); testView1->SetExplicitMaxSize(BSize(100, B_SIZE_UNSET));
@@ -715,26 +702,25 @@ struct SplitterGroupLayoutTest2 : public Test {
// SplitterGridLayoutTest1 // SplitterGridLayoutTest1
struct SplitterGridLayoutTest1 : public Test { struct SplitterGridLayoutTest1 : public Test {
SplitterGridLayoutTest1() SplitterGridLayoutTest1()
: Test("Grid, h splitters", NULL, : Test("Grid, h splitters", "BGridLayout with horizontal BSplitters.")
"BGridLayout with horizontal BSplitters.")
{ {
BGridLayout* layouts[3]; BGridLayout* layouts[3];
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10) .AddGroup(B_VERTICAL)
.Add(toggleView1Button = new BButton("Toggle View 1", .Add(toggleView1Button = new BButton("Toggle View 1",
new BMessage(MSG_TOGGLE_1))) new BMessage(MSG_TOGGLE_1)))
.Add(toggleView2Button = new BButton("Toggle View 2", .Add(toggleView2Button = new BButton("Toggle View 2",
new BMessage(MSG_TOGGLE_2))) new BMessage(MSG_TOGGLE_2)))
.AddGlue() .AddGlue()
.End() .End()
// test views // test views
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL)
// splitter element 1 // splitter element 1
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 6)
.GetGridLayout(&layouts[0]) .GetLayout(&layouts[0])
// row 1 // row 1
.Add(toggledView1 = new TestView(), 0, 0, 3, 1) .Add(toggledView1 = new TestView(), 0, 0, 3, 1)
// row 2 // row 2
@@ -751,11 +737,11 @@ struct SplitterGridLayoutTest1 : public Test {
.SetColumnWeight(0, 1) .SetColumnWeight(0, 1)
.SetColumnWeight(1, 2) .SetColumnWeight(1, 2)
.SetColumnWeight(2, 3) .SetColumnWeight(2, 3)
, 6) .End()
// splitter element 2 // splitter element 2
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 4)
.GetGridLayout(&layouts[1]) .GetLayout(&layouts[1])
// row 1 // row 1
.Add(new TestView(), 0, 0) .Add(new TestView(), 0, 0)
// row 2 // row 2
@@ -764,11 +750,11 @@ struct SplitterGridLayoutTest1 : public Test {
.Add(new TestView(), 0, 2) .Add(new TestView(), 0, 2)
// row 4 // row 4
.Add(new TestView(), 0, 3) .Add(new TestView(), 0, 3)
, 4) .End()
// splitter element 3 // splitter element 3
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 5)
.GetGridLayout(&layouts[2]) .GetLayout(&layouts[2])
// row 1 // row 1
.Add(new TestView(), 0, 0) .Add(new TestView(), 0, 0)
// row 2 // row 2
@@ -776,10 +762,7 @@ struct SplitterGridLayoutTest1 : public Test {
// row 3 // row 3
.Add(new TestView(), 0, 2) .Add(new TestView(), 0, 2)
// row 4 // row 4
.Add(new TestView(), 0, 3) .Add(new TestView(), 0, 3);
, 5)
)
;
// set row weights // set row weights
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@@ -842,14 +825,13 @@ private:
// SplitterGridLayoutTest2 // SplitterGridLayoutTest2
struct SplitterGridLayoutTest2 : public Test { struct SplitterGridLayoutTest2 : public Test {
SplitterGridLayoutTest2() SplitterGridLayoutTest2()
: Test("Grid, v splitters", NULL, : Test("Grid, v splitters", "BGridLayout with vertical BSplitters.")
"BGridLayout with vertical BSplitters.")
{ {
BGridLayout* layouts[3]; BGridLayout* layouts[3];
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10) .AddGroup(B_VERTICAL)
.Add(toggleView1Button = new BButton("Toggle View 1", .Add(toggleView1Button = new BButton("Toggle View 1",
new BMessage(MSG_TOGGLE_1))) new BMessage(MSG_TOGGLE_1)))
.Add(toggleView2Button = new BButton("Toggle View 2", .Add(toggleView2Button = new BButton("Toggle View 2",
@@ -858,30 +840,30 @@ struct SplitterGridLayoutTest2 : public Test {
.End() .End()
// test views // test views
.Add(BSplitLayoutBuilder(B_VERTICAL, 10) .AddSplit(B_VERTICAL)
// splitter element 1 // splitter element 1
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 1)
.GetGridLayout(&layouts[0]) .GetLayout(&layouts[0])
// row 1 // row 1
.Add(toggledView1 = new TestView(), 0, 0, 3, 1) .Add(toggledView1 = new TestView(), 0, 0, 3, 1)
.Add(new TestView(), 3, 0) .Add(new TestView(), 3, 0)
.Add(new TestView(), 4, 0) .Add(new TestView(), 4, 0)
, 1) .End()
// splitter element 2 // splitter element 2
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 2)
.GetGridLayout(&layouts[1]) .GetLayout(&layouts[1])
// row 2 // row 2
.Add(new TestView(), 0, 0) .Add(new TestView(), 0, 0)
.Add(new TestView(), 1, 0) .Add(new TestView(), 1, 0)
.Add(new TestView(), 2, 0) .Add(new TestView(), 2, 0)
.Add(new TestView(), 3, 0) .Add(new TestView(), 3, 0)
.Add(new TestView(), 4, 0) .Add(new TestView(), 4, 0)
, 2) .End()
// splitter element 3 // splitter element 3
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 7)
.GetGridLayout(&layouts[2]) .GetLayout(&layouts[2])
// row 3 // row 3
.Add(new TestView(), 0, 0) .Add(new TestView(), 0, 0)
.Add(toggledView2 = new TestView(), 1, 0, 2, 2) .Add(toggledView2 = new TestView(), 1, 0, 2, 2)
@@ -894,10 +876,7 @@ struct SplitterGridLayoutTest2 : public Test {
// row weights // row weights
.SetRowWeight(0, 3) .SetRowWeight(0, 3)
.SetRowWeight(1, 4) .SetRowWeight(1, 4);
, 7)
)
;
// set column weights // set column weights
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@@ -957,10 +936,10 @@ private:
// GroupLayoutHeightForWidthTestHorizontal1 // GroupLayoutHeightForWidthTestHorizontal1
struct GroupLayoutHeightForWidthTestHorizontal1 : public Test { struct GroupLayoutHeightForWidthTestHorizontal1 : public Test {
GroupLayoutHeightForWidthTestHorizontal1() GroupLayoutHeightForWidthTestHorizontal1()
: Test("Group, height for width, h", NULL, : Test("Group, height for width, h",
"Horizontal BGroupLayout with height for width view.") "Horizontal BGroupLayout with height for width view.")
{ {
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10, 0) .AddGroup(B_VERTICAL, 10, 0)
.Add(aspectRatioButton = new BRadioButton("fixed aspect ratio", .Add(aspectRatioButton = new BRadioButton("fixed aspect ratio",
@@ -1046,10 +1025,10 @@ private:
// GroupLayoutHeightForWidthTestVertical1 // GroupLayoutHeightForWidthTestVertical1
struct GroupLayoutHeightForWidthTestVertical1 : public Test { struct GroupLayoutHeightForWidthTestVertical1 : public Test {
GroupLayoutHeightForWidthTestVertical1() GroupLayoutHeightForWidthTestVertical1()
: Test("Group, height for width, v", NULL, : Test("Group, height for width, v",
"Vertical BGroupLayout with height for width view.") "Vertical BGroupLayout with height for width view.")
{ {
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10, 0) .AddGroup(B_VERTICAL, 10, 0)
.Add(aspectRatioButton = new BRadioButton("fixed aspect ratio", .Add(aspectRatioButton = new BRadioButton("fixed aspect ratio",
@@ -1135,12 +1114,12 @@ private:
// GridLayoutHeightForWidthTest1 // GridLayoutHeightForWidthTest1
struct GridLayoutHeightForWidthTest1 : public Test { struct GridLayoutHeightForWidthTest1 : public Test {
GridLayoutHeightForWidthTest1() GridLayoutHeightForWidthTest1()
: Test("Grid, height for width", NULL, : Test("Grid, height for width",
"BGridLayout with height for width view.") "BGridLayout with height for width view.")
{ {
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10, 0) .AddGroup(B_VERTICAL, B_USE_DEFAULT_SPACING, 0)
.Add(aspectRatioButton = new BRadioButton("fixed aspect ratio", .Add(aspectRatioButton = new BRadioButton("fixed aspect ratio",
new BMessage(MSG_FIXED_ASPECT_RATIO))) new BMessage(MSG_FIXED_ASPECT_RATIO)))
.Add(sumButton = new BRadioButton("fixed sum", .Add(sumButton = new BRadioButton("fixed sum",
@@ -1151,7 +1130,7 @@ struct GridLayoutHeightForWidthTest1 : public Test {
.End() .End()
// test views // test views
.Add(BGridLayoutBuilder(10, 10) .AddGrid()
// row 1 // row 1
.Add(new TestView(), 0, 0, 3, 1) .Add(new TestView(), 0, 0, 3, 1)
.Add(new TestView(), 3, 0) .Add(new TestView(), 3, 0)
@@ -1186,9 +1165,7 @@ struct GridLayoutHeightForWidthTest1 : public Test {
.SetRowWeight(0, 1) .SetRowWeight(0, 1)
.SetRowWeight(1, 2) .SetRowWeight(1, 2)
.SetRowWeight(2, 3) .SetRowWeight(2, 3)
.SetRowWeight(3, 4) .SetRowWeight(3, 4);
)
;
aspectRatioButton->SetValue(1); aspectRatioButton->SetValue(1);
} }
@@ -1238,13 +1215,13 @@ private:
// SplitterGroupLayoutHeightForWidthTest1 // SplitterGroupLayoutHeightForWidthTest1
struct SplitterGroupLayoutHeightForWidthTest1 : public Test { struct SplitterGroupLayoutHeightForWidthTest1 : public Test {
SplitterGroupLayoutHeightForWidthTest1() SplitterGroupLayoutHeightForWidthTest1()
: Test("Group, splitters, height for width", NULL, : Test("Group, splitters, height for width",
"Horizontal BGroupLayout with height for width view and " "Horizontal BGroupLayout with height for width view and "
"BSplitters.") "BSplitters.")
{ {
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL)
// controls // controls
.AddGroup(B_VERTICAL, 10, 0) .AddGroup(B_VERTICAL, B_USE_DEFAULT_SPACING, 0)
.Add(aspectRatioButton = new BRadioButton("fixed aspect ratio", .Add(aspectRatioButton = new BRadioButton("fixed aspect ratio",
new BMessage(MSG_FIXED_ASPECT_RATIO))) new BMessage(MSG_FIXED_ASPECT_RATIO)))
.Add(sumButton = new BRadioButton("fixed sum", .Add(sumButton = new BRadioButton("fixed sum",
@@ -1255,34 +1232,32 @@ struct SplitterGroupLayoutHeightForWidthTest1 : public Test {
.End() .End()
// test views // test views
.Add(BSplitLayoutBuilder(B_VERTICAL, 10) .AddSplit(B_VERTICAL, B_USE_DEFAULT_SPACING, 1)
// row 1 // row 1
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1)
.Add(new TestView(), 1) .Add(new TestView(), 1)
.Add(new TestView(), 2) .Add(new TestView(), 2)
.Add(new TestView(), 3) .Add(new TestView(), 3)
, 1) .End()
// make the row uncollapsible // make the row uncollapsible
.SetCollapsible(false) .SetCollapsible(false)
// row 2 // row 2
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 2)
.Add(new TestView()) .Add(new TestView())
.Add(heightForWidthView = new HeightForWidthTestView(kRed, .Add(heightForWidthView = new HeightForWidthTestView(kRed,
FIXED_ASPECT_RATIO, 0.5f)) FIXED_ASPECT_RATIO, 0.5f))
.Add(new TestView()) .Add(new TestView())
, 2) .End()
// row 3 // row 3
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 3)
.Add(new TestView(), 3) .Add(new TestView(), 3)
.Add(new TestView(), 2) .Add(new TestView(), 2)
.Add(new TestView(), 1) .Add(new TestView(), 1)
, 3) .End()
// make the row uncollapsible // make the row uncollapsible
.SetCollapsible(false) .SetCollapsible(false);
)
;
aspectRatioButton->SetValue(1); aspectRatioButton->SetValue(1);
} }
@@ -1332,14 +1307,14 @@ private:
// SplitterGridLayoutHeightForWidthTest1 // SplitterGridLayoutHeightForWidthTest1
struct SplitterGridLayoutHeightForWidthTest1 : public Test { struct SplitterGridLayoutHeightForWidthTest1 : public Test {
SplitterGridLayoutHeightForWidthTest1() SplitterGridLayoutHeightForWidthTest1()
: Test("Grid, splitters, height for width", NULL, : Test("Grid, splitters, height for width",
"BGridLayout with height for width view and horizontal BSplitters.") "BGridLayout with height for width view and horizontal BSplitters.")
{ {
BGridLayout* layouts[3]; BGridLayout* layouts[3];
rootView = BGroupLayoutBuilder(B_HORIZONTAL, 10) BLayoutBuilder::Group<>(rootView, B_HORIZONTAL, B_USE_DEFAULT_SPACING)
// controls // controls
.AddGroup(B_VERTICAL, 10, 0) .AddGroup(B_VERTICAL, B_USE_DEFAULT_SPACING, 0)
.Add(aspectRatioButton = new BRadioButton("fixed aspect ratio", .Add(aspectRatioButton = new BRadioButton("fixed aspect ratio",
new BMessage(MSG_FIXED_ASPECT_RATIO))) new BMessage(MSG_FIXED_ASPECT_RATIO)))
.Add(sumButton = new BRadioButton("fixed sum", .Add(sumButton = new BRadioButton("fixed sum",
@@ -1350,10 +1325,10 @@ struct SplitterGridLayoutHeightForWidthTest1 : public Test {
.End() .End()
// test views // test views
.Add(BSplitLayoutBuilder(B_HORIZONTAL, 10) .AddSplit(B_HORIZONTAL)
// splitter element 1 // splitter element 1
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 6)
.GetGridLayout(&layouts[0]) .GetLayout(&layouts[0])
// row 1 // row 1
.Add(new TestView(), 0, 0, 3, 1) .Add(new TestView(), 0, 0, 3, 1)
// row 2 // row 2
@@ -1371,11 +1346,11 @@ struct SplitterGridLayoutHeightForWidthTest1 : public Test {
.SetColumnWeight(0, 1) .SetColumnWeight(0, 1)
.SetColumnWeight(1, 2) .SetColumnWeight(1, 2)
.SetColumnWeight(2, 3) .SetColumnWeight(2, 3)
, 6) .End()
// splitter element 2 // splitter element 2
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 4)
.GetGridLayout(&layouts[1]) .GetLayout(&layouts[1])
// row 1 // row 1
.Add(new TestView(), 0, 0) .Add(new TestView(), 0, 0)
// row 2 // row 2
@@ -1384,11 +1359,11 @@ struct SplitterGridLayoutHeightForWidthTest1 : public Test {
.Add(new TestView(), 0, 2) .Add(new TestView(), 0, 2)
// row 4 // row 4
.Add(new TestView(), 0, 3) .Add(new TestView(), 0, 3)
, 4) .End()
// splitter element 3 // splitter element 3
.Add(BGridLayoutBuilder(10, 10) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, 5)
.GetGridLayout(&layouts[2]) .GetLayout(&layouts[2])
// row 1 // row 1
.Add(new TestView(), 0, 0) .Add(new TestView(), 0, 0)
// row 2 // row 2
@@ -1396,10 +1371,7 @@ struct SplitterGridLayoutHeightForWidthTest1 : public Test {
// row 3 // row 3
.Add(new TestView(), 0, 2) .Add(new TestView(), 0, 2)
// row 4 // row 4
.Add(new TestView(), 0, 3) .Add(new TestView(), 0, 3);
, 5)
)
;
// set row weights // set row weights
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@@ -1461,7 +1433,7 @@ private:
// LabelTest1 // LabelTest1
struct LabelTest1 : public Test { struct LabelTest1 : public Test {
LabelTest1() LabelTest1()
: Test("BTextControl, BMenuField, grid", NULL, : Test("BTextControl, BMenuField, grid",
"Aligning BTextControl/BMenuField labels using a 2 column " "Aligning BTextControl/BMenuField labels using a 2 column "
"BGridLayout.") "BGridLayout.")
{ {
@@ -1469,24 +1441,24 @@ struct LabelTest1 : public Test {
textControl2 = new BTextControl("Long Label", NULL, NULL); textControl2 = new BTextControl("Long Label", NULL, NULL);
textControl3 = new BTextControl("Very Long Label", NULL, NULL); textControl3 = new BTextControl("Very Long Label", NULL, NULL);
menuField1 = new BMenuField("Label", new BMenu("Options"), NULL); menuField1 = new BMenuField("Label", new BMenu("Options"));
menuField2 = new BMenuField("Long Label", menuField2 = new BMenuField("Long Label",
new BMenu("More Options"), NULL); new BMenu("More Options"));
menuField3 = new BMenuField("Very Long Label", menuField3 = new BMenuField("Very Long Label",
new BMenu("Obscure Options"), NULL); new BMenu("Obscure Options"));
rootView = BGroupLayoutBuilder(B_VERTICAL, 10) BLayoutBuilder::Group<>(rootView, B_VERTICAL)
// controls // controls
.AddGroup(B_HORIZONTAL, 10) .AddGroup(B_HORIZONTAL)
.Add(changeLabelsButton = new BButton("Random Labels", .Add(changeLabelsButton = new BButton("Random Labels",
new BMessage(MSG_TOGGLE_1))) new BMessage(MSG_TOGGLE_1)))
.AddGlue() .AddGlue()
.End() .End()
.AddGlue() .AddGlue()
// test views // test views
.Add(BGridLayoutBuilder(10, 10) .AddGrid()
// padding // padding
.Add(BSpaceLayoutItem::CreateGlue(), 0, 0) .Add(BSpaceLayoutItem::CreateGlue(), 0, 0)
.Add(BSpaceLayoutItem::CreateGlue(), 1, 0) .Add(BSpaceLayoutItem::CreateGlue(), 1, 0)
@@ -1518,10 +1490,8 @@ struct LabelTest1 : public Test {
// padding // padding
.Add(BSpaceLayoutItem::CreateGlue(), 0, 7) .Add(BSpaceLayoutItem::CreateGlue(), 0, 7)
.Add(BSpaceLayoutItem::CreateGlue(), 1, 7) .Add(BSpaceLayoutItem::CreateGlue(), 1, 7)
) .End()
.AddGlue();
.AddGlue()
;
} }
virtual void RegisterListeners() virtual void RegisterListeners()
@@ -1589,22 +1559,18 @@ public:
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE
| B_AUTO_UPDATE_SIZE_LIMITS) | B_AUTO_UPDATE_SIZE_LIMITS)
{ {
SetLayout(new BGroupLayout(B_HORIZONTAL));
BGroupView* rootView = new BGroupView(B_HORIZONTAL, 10);
BGroupLayout* layout = rootView->GroupLayout();
AddChild(rootView);
layout->SetInsets(5, 5, 5, 5);
fTestList = new BListView(BRect(0, 0, 10, 10), "test list", fTestList = new BListView(BRect(0, 0, 10, 10), "test list",
B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL); B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL);
BView* scrollView = new BScrollView("test scroll view", fTestList); BView* scrollView = new BScrollView("test scroll view", fTestList);
scrollView->SetExplicitMaxSize(BSize(190, B_SIZE_UNLIMITED)); scrollView->SetExplicitMaxSize(BSize(190, B_SIZE_UNLIMITED));
layout->AddView(scrollView);
fTestCardLayout = new BCardLayout(); fTestCardLayout = new BCardLayout();
BView* cardView = new BView("card view", 0, fTestCardLayout); BView* cardView = new BView("card view", 0, fTestCardLayout);
layout->AddView(cardView);
BLayoutBuilder::Group<>(this, B_HORIZONTAL)
.SetInsets(B_USE_WINDOW_INSETS)
.Add(scrollView)
.Add(cardView);
// add the tests // add the tests
_AddTest(new GroupLayoutTest1()); _AddTest(new GroupLayoutTest1());
@@ -1622,7 +1588,7 @@ B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL);
_AddTest(new LabelTest1()); _AddTest(new LabelTest1());
fTestList->SetSelectionMessage(new BMessage(MSG_TEST_SELECTED)); fTestList->SetSelectionMessage(new BMessage(MSG_TEST_SELECTED));
_DumpViewHierarchy(rootView); _DumpViewHierarchy(GetLayout()->Owner());
} }
virtual void MessageReceived(BMessage* message) virtual void MessageReceived(BMessage* message)
@@ -1641,24 +1607,22 @@ private:
void _AddTest(Test* test) { void _AddTest(Test* test) {
fTestList->AddItem(new BStringItem(test->name.String())); fTestList->AddItem(new BStringItem(test->name.String()));
BGroupView* containerView = new BGroupView(B_VERTICAL); BGroupView* containerView = new BGroupView(B_VERTICAL, 0);
// description BStringView* descriptionView = new BStringView("test description",
// BStringView* descriptionView = new BStringView(test->description.String()); test->description.String());
BStringView* descriptionView = new BStringView(BRect(0, 0, 0, 0),
"test description", test->description.String());
descriptionView->SetExplicitMinSize(BSize(0, B_SIZE_UNSET)); descriptionView->SetExplicitMinSize(BSize(0, B_SIZE_UNSET));
containerView->AddChild(descriptionView); containerView->AddChild(descriptionView);
// spacing/glue // spacing/glue
containerView->GroupLayout()->AddItem( containerView->GroupLayout()->AddItem(
BSpaceLayoutItem::CreateVerticalStrut(10), 0); BSpaceLayoutItem::CreateVerticalStrut(10));
containerView->GroupLayout()->AddItem( containerView->GroupLayout()->AddItem(
BSpaceLayoutItem::CreateGlue(), 0); BSpaceLayoutItem::CreateGlue(), 0);
// the test view: wrap it, so we can have unlimited size // the test view: wrap it, so we can have unlimited size
BGroupView* wrapperView = new BGroupView(B_HORIZONTAL); BGroupView* wrapperView = new BGroupView(B_HORIZONTAL, 0);
containerView->AddChild(wrapperView); containerView->AddChild(wrapperView);
wrapperView->AddChild(test->rootView); wrapperView->AddChild(test->rootView);