xref: /haiku/docs/user/interface/LayoutBuilder.dox (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1/*!
2	\class BLayoutBuilder::Base<>
3	\ingroup interface
4	\ingroup layout
5	\brief Base for all other layout builders in the BLayoutBuilder namespace.
6
7	This class provides the stack-like semantics for its subclasses. The
8	BLayoutBuilder::Group, BLayoutBuilder::Grid and BLayoutBuilder::Split all
9	provide methods such as AddGrid() AddGroup() and AddSplit(), which
10	make a new builder, place it on top of your builder stack and return it.
11	Now you are operating on the new builder. When you call	the End() method on
12	the new builder, you are returned the one you had previously been using. At
13	any point, you are calling methods on whatever builder currently resides on
14	the top of the stack. Here's an example of how these classes work.
15
16\code
17BLayoutBuilder::Group<>(B_HORIZONTAL)
18\endcode
19
20	At this point our stack just contains a single builder, it looks like this:
21		\li Group<>
22
23\code
24	.AddGrid()
25\endcode
26
27	Now there is a Grid builder on top of the stack, so it looks like this \li Group<>::GridBuilder
28		\li Group<>
29
30	Notice that the Grid on top of the stack is not a plain Grid<>, but a nested
31	type from the Group<> class. This is an essential part of the builder
32	classes, as this is what allows you to pop builders off the stack and get
33	the correct type in return.
34
35\code
36		.AddSplit()
37\endcode
38
39	Now our stack looks like this:
40		\li Group<>::GridBuilder::SplitBuilder
41		\li Group<>::GridBuilder
42		\li Group<>
43
44	This could continue ad. nauseam, but at some point, you may finish with a
45	builder, and you might want to continue manipulating the builder below it
46	on the stack. To do this, you simply call the End() method like so:
47
48\code
49			.End()
50\endcode
51
52	And now the stack is back to this:
53		\li Group<>::GridBuilder
54		\li Group<>
55
56	So you are again working with the grid builder. You can add more
57	BLayoutItems or BViews, or even more builders. Here's how it will all look
58	together.
59
60\code
61BLayoutBuilder::Group<>(B_HORIZONTAL)
62	// working with the Group builder
63	.AddGrid()
64		// working with the Group<>::GridBuilder
65		.AddSplit()
66			// working with the Group<>::GridBuilder::SplitBuilder
67		.End()
68		// back to the Group<>::GridBuilder
69\endcode
70*/
71
72
73/*!
74	\fn void BLayoutBuilder::Base<ParentBuilder>::SetParent(ParentBuilder*
75		parent)
76	Internal method for use by BLayoutBuilder::Base subclasses, this is
77	essential to the builder stack semantics
78*/
79
80
81/*!
82	\fn ParentBuilder& BLayoutBuilder::Base<ParentBuilder>::End()
83	\brief Returns this builder's parent.
84*/
85
86
87
88/*
89
90
91template<typename ParentBuilder>
92class Grid : public Base<ParentBuilder> {
93public:
94	typedef Grid<ParentBuilder>		ThisBuilder;
95	typedef Group<ThisBuilder>		GroupBuilder;
96	typedef Grid<ThisBuilder>		GridBuilder;
97	typedef Split<ThisBuilder>		SplitBuilder;
98
99public:
100	inline						Grid(float horizontalSpacing = 0.0f,
101									float verticalSpacing = 0.0f);
102	inline						Grid(BWindow* window,
103									float horizontalSpacing = 0.0f,
104									float verticalSpacing = 0.0f);
105	inline						Grid(BGridLayout* layout);
106	inline						Grid(BGridView* view);
107
108	inline	BGridLayout*		Layout() const;
109	inline	BView*				View() const;
110	inline	ThisBuilder&		GetLayout(BGridLayout** _layout);
111	inline	ThisBuilder&		GetView(BView** _view);
112
113	inline	ThisBuilder&		Add(BView* view, int32 column, int32 row,
114									int32 columnCount = 1, int32 rowCount = 1);
115	inline	ThisBuilder&		Add(BLayoutItem* item, int32 column, int32 row,
116									int32 columnCount = 1, int32 rowCount = 1);
117	inline	ThisBuilder&		AddMenuField(BMenuField* menuField,
118									int32 column, int32 row,
119									alignment labelAlignment
120										= B_ALIGN_HORIZONTAL_UNSET,
121									int32 columnCount = 1, int32 rowCount = 1);
122	inline	ThisBuilder&		AddTextControl(BTextControl* textControl,
123									int32 column, int32 row,
124									alignment labelAlignment
125										= B_ALIGN_HORIZONTAL_UNSET,
126									int32 columnCount = 1, int32 rowCount = 1);
127
128	inline	GroupBuilder		AddGroup(enum orientation orientation,
129									float spacing, int32 column, int32 row,
130									int32 columnCount = 1, int32 rowCount = 1);
131	inline	GroupBuilder		AddGroup(BGroupView* groupView,	int32 column,
132									int32 row, int32 columnCount = 1,
133									int32 rowCount = 1);
134	inline	GroupBuilder		AddGroup(BGroupLayout* groupLayout,
135									int32 column, int32 row,
136									int32 columnCount = 1, int32 rowCount = 1);
137
138	inline	GridBuilder			AddGrid(float horizontalSpacing,
139									float verticalSpacing, int32 column,
140									int32 row, int32 columnCount = 1,
141									int32 rowCount = 1);
142	inline	GridBuilder			AddGrid(BGridLayout* gridLayout,
143									int32 column, int32 row,
144									int32 columnCount = 1, int32 rowCount = 1);
145	inline	GridBuilder			AddGrid(BGridView* gridView,
146									int32 column, int32 row,
147									int32 columnCount = 1, int32 rowCount = 1);
148
149	inline	SplitBuilder		AddSplit(enum orientation orientation,
150									float spacing, int32 column, int32 row,
151									int32 columnCount = 1, int32 rowCount = 1);
152	inline	SplitBuilder		AddSplit(BSplitView* splitView, int32 column,
153									int32 row, int32 columnCount = 1,
154									int32 rowCount = 1);
155
156	inline	ThisBuilder&		SetColumnWeight(int32 column, float weight);
157	inline	ThisBuilder&		SetRowWeight(int32 row, float weight);
158
159	inline	ThisBuilder&		SetInsets(float left, float top, float right,
160									float bottom);
161
162	inline						operator BGridLayout*();
163
164private:
165			BGridLayout*		fLayout;
166};
167
168
169template<typename ParentBuilder>
170class Split : public Base<ParentBuilder> {
171public:
172	typedef Split<ParentBuilder>	ThisBuilder;
173	typedef Group<ThisBuilder>		GroupBuilder;
174	typedef Grid<ThisBuilder>		GridBuilder;
175	typedef Split<ThisBuilder>		SplitBuilder;
176
177public:
178	inline						Split(enum orientation orientation
179										= B_HORIZONTAL,
180									float spacing = 0.0f);
181	inline						Split(BSplitView* view);
182
183	inline	BSplitView*			View() const;
184	inline	ThisBuilder&		GetView(BView** _view);
185	inline	ThisBuilder&		GetSplitView(BSplitView** _view);
186
187	inline	ThisBuilder&		Add(BView* view);
188	inline	ThisBuilder&		Add(BView* view, float weight);
189	inline	ThisBuilder&		Add(BLayoutItem* item);
190	inline	ThisBuilder&		Add(BLayoutItem* item, float weight);
191
192	inline	GroupBuilder		AddGroup(enum orientation orientation,
193									float spacing = 0.0f, float weight = 1.0f);
194	inline	GroupBuilder		AddGroup(BGroupView* groupView,
195									float weight = 1.0f);
196	inline	GroupBuilder		AddGroup(BGroupLayout* groupLayout,
197									float weight = 1.0f);
198
199	inline	GridBuilder			AddGrid(float horizontalSpacing = 0.0f,
200									float verticalSpacing = 0.0f,
201									float weight = 1.0f);
202	inline	GridBuilder			AddGrid(BGridView* gridView,
203									float weight = 1.0f);
204	inline	GridBuilder			AddGrid(BGridLayout* gridLayout,
205									float weight = 1.0f);
206
207	inline	SplitBuilder		AddSplit(enum orientation orientation,
208									float spacing = 0.0f, float weight = 1.0f);
209	inline	SplitBuilder		AddSplit(BSplitView* splitView,
210									float weight = 1.0f);
211
212	inline	ThisBuilder&		SetCollapsible(bool collapsible);
213	inline	ThisBuilder&		SetCollapsible(int32 index, bool collapsible);
214	inline	ThisBuilder&		SetCollapsible(int32 first, int32 last,
215									bool collapsible);
216
217	inline	ThisBuilder&		SetInsets(float left, float top, float right,
218									float bottom);
219
220	inline						operator BSplitView*();
221
222private:
223			BSplitView*			fView;
224};
225