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