1 /* 2 * Copyright 2009-2010, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _LAYOUT_BUILDER_H 6 #define _LAYOUT_BUILDER_H 7 8 9 #include <GridLayout.h> 10 #include <GridView.h> 11 #include <GroupLayout.h> 12 #include <GroupView.h> 13 #include <MenuField.h> 14 #include <SpaceLayoutItem.h> 15 #include <SplitView.h> 16 #include <TextControl.h> 17 #include <Window.h> 18 19 20 namespace BLayoutBuilder { 21 22 template<typename ParentBuilder> class Base; 23 template<typename ParentBuilder = void*> class Group; 24 template<typename ParentBuilder = void*> class Grid; 25 template<typename ParentBuilder = void*> class Split; 26 27 28 template<typename ParentBuilder> 29 class Base { 30 protected: 31 inline Base(); 32 33 public: 34 inline void SetParent(ParentBuilder* parent); 35 // conceptually private 36 inline ParentBuilder& End(); 37 38 protected: 39 ParentBuilder* fParent; 40 }; 41 42 43 template<typename ParentBuilder> 44 class Group : public Base<ParentBuilder> { 45 public: 46 typedef Group<ParentBuilder> ThisBuilder; 47 typedef Group<ThisBuilder> GroupBuilder; 48 typedef Grid<ThisBuilder> GridBuilder; 49 typedef Split<ThisBuilder> SplitBuilder; 50 51 public: 52 inline Group(enum orientation orientation 53 = B_HORIZONTAL, 54 float spacing = 0.0f); 55 inline Group(BWindow* window, 56 enum orientation orientation = B_HORIZONTAL, 57 float spacing = 0.0f); 58 inline Group(BGroupLayout* layout); 59 inline Group(BGroupView* view); 60 61 inline BGroupLayout* Layout() const; 62 inline BView* View() const; 63 inline ThisBuilder& GetLayout(BGroupLayout** _layout); 64 inline ThisBuilder& GetView(BView** _view); 65 66 inline ThisBuilder& Add(BView* view); 67 inline ThisBuilder& Add(BView* view, float weight); 68 inline ThisBuilder& Add(BLayoutItem* item); 69 inline ThisBuilder& Add(BLayoutItem* item, float weight); 70 71 inline GroupBuilder AddGroup(enum orientation orientation, 72 float spacing = 0.0f, float weight = 1.0f); 73 inline GroupBuilder AddGroup(BGroupView* groupView, 74 float weight = 1.0f); 75 inline GroupBuilder AddGroup(BGroupLayout* groupLayout, 76 float weight = 1.0f); 77 78 inline GridBuilder AddGrid(float horizontalSpacing = 0.0f, 79 float verticalSpacing = 0.0f, 80 float weight = 1.0f); 81 inline GridBuilder AddGrid(BGridLayout* gridLayout, 82 float weight = 1.0f); 83 inline GridBuilder AddGrid(BGridView* gridView, 84 float weight = 1.0f); 85 86 inline SplitBuilder AddSplit(enum orientation orientation, 87 float spacing = 0.0f, float weight = 1.0f); 88 inline SplitBuilder AddSplit(BSplitView* splitView, 89 float weight = 1.0f); 90 91 inline ThisBuilder& AddGlue(float weight = 1.0f); 92 inline ThisBuilder& AddStrut(float size); 93 94 inline ThisBuilder& SetInsets(float left, float top, float right, 95 float bottom); 96 97 inline operator BGroupLayout*(); 98 99 private: 100 BGroupLayout* fLayout; 101 }; 102 103 104 template<typename ParentBuilder> 105 class Grid : public Base<ParentBuilder> { 106 public: 107 typedef Grid<ParentBuilder> ThisBuilder; 108 typedef Group<ThisBuilder> GroupBuilder; 109 typedef Grid<ThisBuilder> GridBuilder; 110 typedef Split<ThisBuilder> SplitBuilder; 111 112 public: 113 inline Grid(float horizontalSpacing = 0.0f, 114 float verticalSpacing = 0.0f); 115 inline Grid(BWindow* window, 116 float horizontalSpacing = 0.0f, 117 float verticalSpacing = 0.0f); 118 inline Grid(BGridLayout* layout); 119 inline Grid(BGridView* view); 120 121 inline BGridLayout* Layout() const; 122 inline BView* View() const; 123 inline ThisBuilder& GetLayout(BGridLayout** _layout); 124 inline ThisBuilder& GetView(BView** _view); 125 126 inline ThisBuilder& Add(BView* view, int32 column, int32 row, 127 int32 columnCount = 1, int32 rowCount = 1); 128 inline ThisBuilder& Add(BLayoutItem* item, int32 column, int32 row, 129 int32 columnCount = 1, int32 rowCount = 1); 130 inline ThisBuilder& AddMenuField(BMenuField* menuField, 131 int32 column, int32 row, 132 alignment labelAlignment 133 = B_ALIGN_HORIZONTAL_UNSET, 134 int32 columnCount = 1, int32 rowCount = 1); 135 inline ThisBuilder& AddTextControl(BTextControl* textControl, 136 int32 column, int32 row, 137 alignment labelAlignment 138 = B_ALIGN_HORIZONTAL_UNSET, 139 int32 columnCount = 1, int32 rowCount = 1); 140 141 inline GroupBuilder AddGroup(enum orientation orientation, 142 float spacing, int32 column, int32 row, 143 int32 columnCount = 1, int32 rowCount = 1); 144 inline GroupBuilder AddGroup(BGroupView* groupView, int32 column, 145 int32 row, int32 columnCount = 1, 146 int32 rowCount = 1); 147 inline GroupBuilder AddGroup(BGroupLayout* groupLayout, 148 int32 column, int32 row, 149 int32 columnCount = 1, int32 rowCount = 1); 150 151 inline GridBuilder AddGrid(float horizontalSpacing, 152 float verticalSpacing, int32 column, 153 int32 row, int32 columnCount = 1, 154 int32 rowCount = 1); 155 inline GridBuilder AddGrid(BGridLayout* gridLayout, 156 int32 column, int32 row, 157 int32 columnCount = 1, int32 rowCount = 1); 158 inline GridBuilder AddGrid(BGridView* gridView, 159 int32 column, int32 row, 160 int32 columnCount = 1, int32 rowCount = 1); 161 162 inline SplitBuilder AddSplit(enum orientation orientation, 163 float spacing, int32 column, int32 row, 164 int32 columnCount = 1, int32 rowCount = 1); 165 inline SplitBuilder AddSplit(BSplitView* splitView, int32 column, 166 int32 row, int32 columnCount = 1, 167 int32 rowCount = 1); 168 169 inline ThisBuilder& SetColumnWeight(int32 column, float weight); 170 inline ThisBuilder& SetRowWeight(int32 row, float weight); 171 172 inline ThisBuilder& SetInsets(float left, float top, float right, 173 float bottom); 174 175 inline operator BGridLayout*(); 176 177 private: 178 BGridLayout* fLayout; 179 }; 180 181 182 template<typename ParentBuilder> 183 class Split : public Base<ParentBuilder> { 184 public: 185 typedef Split<ParentBuilder> ThisBuilder; 186 typedef Group<ThisBuilder> GroupBuilder; 187 typedef Grid<ThisBuilder> GridBuilder; 188 typedef Split<ThisBuilder> SplitBuilder; 189 190 public: 191 inline Split(enum orientation orientation 192 = B_HORIZONTAL, 193 float spacing = 0.0f); 194 inline Split(BSplitView* view); 195 196 inline BSplitView* View() const; 197 inline ThisBuilder& GetView(BView** _view); 198 inline ThisBuilder& GetSplitView(BSplitView** _view); 199 200 inline ThisBuilder& Add(BView* view); 201 inline ThisBuilder& Add(BView* view, float weight); 202 inline ThisBuilder& Add(BLayoutItem* item); 203 inline ThisBuilder& Add(BLayoutItem* item, float weight); 204 205 inline GroupBuilder AddGroup(enum orientation orientation, 206 float spacing = 0.0f, float weight = 1.0f); 207 inline GroupBuilder AddGroup(BGroupView* groupView, 208 float weight = 1.0f); 209 inline GroupBuilder AddGroup(BGroupLayout* groupLayout, 210 float weight = 1.0f); 211 212 inline GridBuilder AddGrid(float horizontalSpacing = 0.0f, 213 float verticalSpacing = 0.0f, 214 float weight = 1.0f); 215 inline GridBuilder AddGrid(BGridView* gridView, 216 float weight = 1.0f); 217 inline GridBuilder AddGrid(BGridLayout* gridLayout, 218 float weight = 1.0f); 219 220 inline SplitBuilder AddSplit(enum orientation orientation, 221 float spacing = 0.0f, float weight = 1.0f); 222 inline SplitBuilder AddSplit(BSplitView* splitView, 223 float weight = 1.0f); 224 225 inline ThisBuilder& SetCollapsible(bool collapsible); 226 inline ThisBuilder& SetCollapsible(int32 index, bool collapsible); 227 inline ThisBuilder& SetCollapsible(int32 first, int32 last, 228 bool collapsible); 229 230 inline ThisBuilder& SetInsets(float left, float top, float right, 231 float bottom); 232 233 inline operator BSplitView*(); 234 235 private: 236 BSplitView* fView; 237 }; 238 239 240 // #pragma mark - Base 241 242 243 template<typename ParentBuilder> 244 Base<ParentBuilder>::Base() 245 : 246 fParent(NULL) 247 { 248 } 249 250 251 template<typename ParentBuilder> 252 void 253 Base<ParentBuilder>::SetParent(ParentBuilder* parent) 254 { 255 fParent = parent; 256 } 257 258 259 template<typename ParentBuilder> 260 ParentBuilder& 261 Base<ParentBuilder>::End() 262 { 263 return *fParent; 264 } 265 266 267 // #pragma mark - Group 268 269 270 template<typename ParentBuilder> 271 Group<ParentBuilder>::Group(enum orientation orientation, float spacing) 272 : 273 fLayout((new BGroupView(orientation, spacing))->GroupLayout()) 274 { 275 } 276 277 278 template<typename ParentBuilder> 279 Group<ParentBuilder>::Group(BWindow* window, enum orientation orientation, 280 float spacing) 281 : 282 fLayout(new BGroupLayout(orientation, spacing)) 283 { 284 window->SetLayout(fLayout); 285 286 fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 287 // TODO: we get a white background if we don't do this 288 } 289 290 291 template<typename ParentBuilder> 292 Group<ParentBuilder>::Group(BGroupLayout* layout) 293 : 294 fLayout(layout) 295 { 296 } 297 298 299 template<typename ParentBuilder> 300 Group<ParentBuilder>::Group(BGroupView* view) 301 : 302 fLayout(view->GroupLayout()) 303 { 304 } 305 306 307 template<typename ParentBuilder> 308 BGroupLayout* 309 Group<ParentBuilder>::Layout() const 310 { 311 return fLayout; 312 } 313 314 315 template<typename ParentBuilder> 316 BView* 317 Group<ParentBuilder>::View() const 318 { 319 return fLayout->Owner(); 320 } 321 322 323 template<typename ParentBuilder> 324 typename Group<ParentBuilder>::ThisBuilder& 325 Group<ParentBuilder>::GetLayout(BGroupLayout** _layout) 326 { 327 *_layout = fLayout; 328 return *this; 329 } 330 331 332 template<typename ParentBuilder> 333 typename Group<ParentBuilder>::ThisBuilder& 334 Group<ParentBuilder>::GetView(BView** _view) 335 { 336 *_view = fLayout->Owner(); 337 return *this; 338 } 339 340 341 template<typename ParentBuilder> 342 typename Group<ParentBuilder>::ThisBuilder& 343 Group<ParentBuilder>::Add(BView* view) 344 { 345 fLayout->AddView(view); 346 return *this; 347 } 348 349 350 template<typename ParentBuilder> 351 typename Group<ParentBuilder>::ThisBuilder& 352 Group<ParentBuilder>::Add(BView* view, float weight) 353 { 354 fLayout->AddView(view, weight); 355 return *this; 356 } 357 358 359 template<typename ParentBuilder> 360 typename Group<ParentBuilder>::ThisBuilder& 361 Group<ParentBuilder>::Add(BLayoutItem* item) 362 { 363 fLayout->AddItem(item); 364 return *this; 365 } 366 367 368 template<typename ParentBuilder> 369 typename Group<ParentBuilder>::ThisBuilder& 370 Group<ParentBuilder>::Add(BLayoutItem* item, float weight) 371 { 372 fLayout->AddItem(item, weight); 373 return *this; 374 } 375 376 377 template<typename ParentBuilder> 378 typename Group<ParentBuilder>::GroupBuilder 379 Group<ParentBuilder>::AddGroup(enum orientation orientation, float spacing, 380 float weight) 381 { 382 GroupBuilder builder(new BGroupLayout(orientation, spacing)); 383 builder.SetParent(this); 384 fLayout->AddItem(builder.Layout(), weight); 385 return builder; 386 } 387 388 389 template<typename ParentBuilder> 390 typename Group<ParentBuilder>::GroupBuilder 391 Group<ParentBuilder>::AddGroup(BGroupView* groupView, float weight) 392 { 393 GroupBuilder builder(groupView); 394 builder.SetParent(this); 395 fLayout->AddItem(builder.Layout(), weight); 396 return builder; 397 } 398 399 400 template<typename ParentBuilder> 401 typename Group<ParentBuilder>::GroupBuilder 402 Group<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight) 403 { 404 GroupBuilder builder(groupLayout); 405 builder.SetParent(this); 406 fLayout->AddItem(builder.Layout(), weight); 407 return builder; 408 } 409 410 411 template<typename ParentBuilder> 412 typename Group<ParentBuilder>::GridBuilder 413 Group<ParentBuilder>::AddGrid(float horizontalSpacing, 414 float verticalSpacing, float weight) 415 { 416 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); 417 builder.SetParent(this); 418 fLayout->AddItem(builder.Layout(), weight); 419 return builder; 420 } 421 422 423 template<typename ParentBuilder> 424 typename Group<ParentBuilder>::GridBuilder 425 Group<ParentBuilder>::AddGrid(BGridLayout* gridLayout, float weight) 426 { 427 GridBuilder builder(gridLayout); 428 builder.SetParent(this); 429 fLayout->AddItem(builder.Layout(), weight); 430 return builder; 431 } 432 433 434 template<typename ParentBuilder> 435 typename Group<ParentBuilder>::GridBuilder 436 Group<ParentBuilder>::AddGrid(BGridView* gridView, float weight) 437 { 438 GridBuilder builder(gridView); 439 builder.SetParent(this); 440 fLayout->AddItem(builder.Layout(), weight); 441 return builder; 442 } 443 444 445 template<typename ParentBuilder> 446 typename Group<ParentBuilder>::SplitBuilder 447 Group<ParentBuilder>::AddSplit(enum orientation orientation, float spacing, 448 float weight) 449 { 450 SplitBuilder builder(orientation, spacing); 451 builder.SetParent(this); 452 fLayout->AddView(builder.View(), weight); 453 return builder; 454 } 455 456 457 template<typename ParentBuilder> 458 typename Group<ParentBuilder>::SplitBuilder 459 Group<ParentBuilder>::AddSplit(BSplitView* splitView, float weight) 460 { 461 SplitBuilder builder(splitView); 462 builder.SetParent(this); 463 fLayout->AddView(builder.View(), weight); 464 return builder; 465 } 466 467 468 template<typename ParentBuilder> 469 typename Group<ParentBuilder>::ThisBuilder& 470 Group<ParentBuilder>::AddGlue(float weight) 471 { 472 fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), weight); 473 return *this; 474 } 475 476 477 template<typename ParentBuilder> 478 typename Group<ParentBuilder>::ThisBuilder& 479 Group<ParentBuilder>::AddStrut(float size) 480 { 481 if (fLayout->Orientation() == B_HORIZONTAL) 482 fLayout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(size)); 483 else 484 fLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(size)); 485 486 return *this; 487 } 488 489 490 template<typename ParentBuilder> 491 typename Group<ParentBuilder>::ThisBuilder& 492 Group<ParentBuilder>::SetInsets(float left, float top, float right, 493 float bottom) 494 { 495 fLayout->SetInsets(left, top, right, bottom); 496 return *this; 497 } 498 499 500 template<typename ParentBuilder> 501 Group<ParentBuilder>::operator BGroupLayout*() 502 { 503 return fLayout; 504 } 505 506 507 // #pragma mark - Grid 508 509 510 template<typename ParentBuilder> 511 Grid<ParentBuilder>::Grid(float horizontalSpacing, float verticalSpacing) 512 : 513 fLayout((new BGridView(horizontalSpacing, verticalSpacing))->GridLayout()) 514 { 515 } 516 517 518 template<typename ParentBuilder> 519 Grid<ParentBuilder>::Grid(BWindow* window, float horizontalSpacing, 520 float verticalSpacing) 521 : 522 fLayout(new BGridLayout(horizontalSpacing, verticalSpacing)) 523 { 524 window->SetLayout(fLayout); 525 526 fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 527 // TODO: we get a white background if we don't do this 528 } 529 530 531 template<typename ParentBuilder> 532 Grid<ParentBuilder>::Grid(BGridLayout* layout) 533 : 534 fLayout(layout) 535 { 536 } 537 538 539 template<typename ParentBuilder> 540 Grid<ParentBuilder>::Grid(BGridView* view) 541 : 542 fLayout(view->GridLayout()) 543 { 544 } 545 546 547 template<typename ParentBuilder> 548 BGridLayout* 549 Grid<ParentBuilder>::Layout() const 550 { 551 return fLayout; 552 } 553 554 555 template<typename ParentBuilder> 556 BView* 557 Grid<ParentBuilder>::View() const 558 { 559 return fLayout->Owner(); 560 } 561 562 563 template<typename ParentBuilder> 564 typename Grid<ParentBuilder>::ThisBuilder& 565 Grid<ParentBuilder>::GetLayout(BGridLayout** _layout) 566 { 567 *_layout = fLayout; 568 return *this; 569 } 570 571 572 template<typename ParentBuilder> 573 typename Grid<ParentBuilder>::ThisBuilder& 574 Grid<ParentBuilder>::GetView(BView** _view) 575 { 576 *_view = fLayout->Owner(); 577 return *this; 578 } 579 580 581 template<typename ParentBuilder> 582 typename Grid<ParentBuilder>::ThisBuilder& 583 Grid<ParentBuilder>::Add(BView* view, int32 column, int32 row, 584 int32 columnCount, int32 rowCount) 585 { 586 fLayout->AddView(view, column, row, columnCount, rowCount); 587 return *this; 588 } 589 590 591 template<typename ParentBuilder> 592 typename Grid<ParentBuilder>::ThisBuilder& 593 Grid<ParentBuilder>::Add(BLayoutItem* item, int32 column, int32 row, 594 int32 columnCount, int32 rowCount) 595 { 596 fLayout->AddItem(item, column, row, columnCount, rowCount); 597 return *this; 598 } 599 600 601 template<typename ParentBuilder> 602 typename Grid<ParentBuilder>::ThisBuilder& 603 Grid<ParentBuilder>::AddMenuField(BMenuField* menuField, int32 column, 604 int32 row, alignment labelAlignment, int32 columnCount, int32 rowCount) 605 { 606 BLayoutItem* item = menuField->CreateLabelLayoutItem(); 607 item->SetExplicitAlignment( 608 BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET)); 609 fLayout->AddItem(item, column, row, columnCount, rowCount); 610 fLayout->AddItem(menuField->CreateMenuBarLayoutItem(), column + columnCount, 611 row, columnCount, rowCount); 612 return *this; 613 } 614 615 616 template<typename ParentBuilder> 617 typename Grid<ParentBuilder>::ThisBuilder& 618 Grid<ParentBuilder>::AddTextControl(BTextControl* textControl, int32 column, 619 int32 row, alignment labelAlignment, int32 columnCount, int32 rowCount) 620 { 621 BLayoutItem* item = textControl->CreateLabelLayoutItem(); 622 item->SetExplicitAlignment( 623 BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET)); 624 fLayout->AddItem(item, column, row, columnCount, rowCount); 625 fLayout->AddItem(textControl->CreateTextViewLayoutItem(), 626 column + columnCount, row, columnCount, rowCount); 627 return *this; 628 } 629 630 631 template<typename ParentBuilder> 632 typename Grid<ParentBuilder>::GroupBuilder 633 Grid<ParentBuilder>::AddGroup(enum orientation orientation, float spacing, 634 int32 column, int32 row, int32 columnCount, int32 rowCount) 635 { 636 GroupBuilder builder(new BGroupLayout(orientation, spacing)); 637 builder.SetParent(this); 638 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 639 return builder; 640 } 641 642 643 template<typename ParentBuilder> 644 typename Grid<ParentBuilder>::GroupBuilder 645 Grid<ParentBuilder>::AddGroup(BGroupView* groupView, int32 column, int32 row, 646 int32 columnCount, int32 rowCount) 647 { 648 GroupBuilder builder(groupView); 649 builder.SetParent(this); 650 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 651 return builder; 652 } 653 654 655 template<typename ParentBuilder> 656 typename Grid<ParentBuilder>::GroupBuilder 657 Grid<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, int32 column, 658 int32 row, int32 columnCount, int32 rowCount) 659 { 660 GroupBuilder builder(groupLayout); 661 builder.SetParent(this); 662 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 663 return builder; 664 } 665 666 667 template<typename ParentBuilder> 668 typename Grid<ParentBuilder>::GridBuilder 669 Grid<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing, 670 int32 column, int32 row, int32 columnCount, int32 rowCount) 671 { 672 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); 673 builder.SetParent(this); 674 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 675 return builder; 676 } 677 678 679 template<typename ParentBuilder> 680 typename Grid<ParentBuilder>::GridBuilder 681 Grid<ParentBuilder>::AddGrid(BGridView* gridView, int32 column, int32 row, 682 int32 columnCount, int32 rowCount) 683 { 684 GridBuilder builder(gridView); 685 builder.SetParent(this); 686 fLayout->AddView(builder.View(), column, row, columnCount, rowCount); 687 return builder; 688 } 689 690 691 template<typename ParentBuilder> 692 typename Grid<ParentBuilder>::SplitBuilder 693 Grid<ParentBuilder>::AddSplit(enum orientation orientation, float spacing, 694 int32 column, int32 row, int32 columnCount, int32 rowCount) 695 { 696 SplitBuilder builder(orientation, spacing); 697 builder.SetParent(this); 698 fLayout->AddView(builder.View(), column, row, columnCount, rowCount); 699 return builder; 700 } 701 702 703 template<typename ParentBuilder> 704 typename Grid<ParentBuilder>::SplitBuilder 705 Grid<ParentBuilder>::AddSplit(BSplitView* splitView, int32 column, int32 row, 706 int32 columnCount, int32 rowCount) 707 { 708 SplitBuilder builder(splitView); 709 builder.SetParent(this); 710 fLayout->AddView(builder.View(), column, row, columnCount, rowCount); 711 return builder; 712 } 713 714 715 template<typename ParentBuilder> 716 typename Grid<ParentBuilder>::ThisBuilder& 717 Grid<ParentBuilder>::SetColumnWeight(int32 column, float weight) 718 { 719 fLayout->SetColumnWeight(column, weight); 720 return *this; 721 } 722 723 724 template<typename ParentBuilder> 725 typename Grid<ParentBuilder>::ThisBuilder& 726 Grid<ParentBuilder>::SetRowWeight(int32 row, float weight) 727 { 728 fLayout->SetRowWeight(row, weight); 729 return *this; 730 } 731 732 733 template<typename ParentBuilder> 734 typename Grid<ParentBuilder>::ThisBuilder& 735 Grid<ParentBuilder>::SetInsets(float left, float top, float right, 736 float bottom) 737 { 738 fLayout->SetInsets(left, top, right, bottom); 739 return *this; 740 } 741 742 743 template<typename ParentBuilder> 744 Grid<ParentBuilder>::operator BGridLayout*() 745 { 746 return fLayout; 747 } 748 749 750 // #pragma mark - Split 751 752 753 template<typename ParentBuilder> 754 Split<ParentBuilder>::Split(enum orientation orientation, float spacing) 755 : 756 fView(new BSplitView(orientation, spacing)) 757 { 758 } 759 760 761 template<typename ParentBuilder> 762 Split<ParentBuilder>::Split(BSplitView* view) 763 : 764 fView(view) 765 { 766 } 767 768 769 template<typename ParentBuilder> 770 BSplitView* 771 Split<ParentBuilder>::View() const 772 { 773 return fView; 774 } 775 776 777 template<typename ParentBuilder> 778 typename Split<ParentBuilder>::ThisBuilder& 779 Split<ParentBuilder>::GetView(BView** _view) 780 { 781 *_view = fView; 782 return *this; 783 } 784 785 786 template<typename ParentBuilder> 787 typename Split<ParentBuilder>::ThisBuilder& 788 Split<ParentBuilder>::GetSplitView(BSplitView** _view) 789 { 790 *_view = fView; 791 return *this; 792 } 793 794 795 template<typename ParentBuilder> 796 typename Split<ParentBuilder>::ThisBuilder& 797 Split<ParentBuilder>::Add(BView* view) 798 { 799 fView->AddChild(view); 800 return *this; 801 } 802 803 804 template<typename ParentBuilder> 805 typename Split<ParentBuilder>::ThisBuilder& 806 Split<ParentBuilder>::Add(BView* view, float weight) 807 { 808 fView->AddChild(view, weight); 809 return *this; 810 } 811 812 813 template<typename ParentBuilder> 814 typename Split<ParentBuilder>::ThisBuilder& 815 Split<ParentBuilder>::Add(BLayoutItem* item) 816 { 817 fView->AddChild(item); 818 return *this; 819 } 820 821 822 template<typename ParentBuilder> 823 typename Split<ParentBuilder>::ThisBuilder& 824 Split<ParentBuilder>::Add(BLayoutItem* item, float weight) 825 { 826 fView->AddChild(item, weight); 827 return *this; 828 } 829 830 831 template<typename ParentBuilder> 832 typename Split<ParentBuilder>::GroupBuilder 833 Split<ParentBuilder>::AddGroup(enum orientation orientation, float spacing, 834 float weight) 835 { 836 GroupBuilder builder(new BGroupLayout(orientation, spacing)); 837 builder.SetParent(this); 838 fView->AddChild(builder.Layout(), weight); 839 return builder; 840 } 841 842 843 template<typename ParentBuilder> 844 typename Split<ParentBuilder>::GroupBuilder 845 Split<ParentBuilder>::AddGroup(BGroupView* groupView, float weight) 846 { 847 GroupBuilder builder(groupView); 848 builder.SetParent(this); 849 fView->AddChild(builder.Layout(), weight); 850 return builder; 851 } 852 853 854 template<typename ParentBuilder> 855 typename Split<ParentBuilder>::GroupBuilder 856 Split<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight) 857 { 858 GroupBuilder builder(groupLayout); 859 builder.SetParent(this); 860 fView->AddChild(builder.Layout(), weight); 861 return builder; 862 } 863 864 865 template<typename ParentBuilder> 866 typename Split<ParentBuilder>::GridBuilder 867 Split<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing, 868 float weight) 869 { 870 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); 871 builder.SetParent(this); 872 fView->AddChild(builder.Layout(), weight); 873 return builder; 874 } 875 876 877 template<typename ParentBuilder> 878 typename Split<ParentBuilder>::GridBuilder 879 Split<ParentBuilder>::AddGrid(BGridView* gridView, float weight) 880 { 881 GridBuilder builder(gridView); 882 builder.SetParent(this); 883 fView->AddChild(builder.Layout(), weight); 884 return builder; 885 } 886 887 888 template<typename ParentBuilder> 889 typename Split<ParentBuilder>::GridBuilder 890 Split<ParentBuilder>::AddGrid(BGridLayout* layout, float weight) 891 { 892 GridBuilder builder(layout); 893 builder.SetParent(this); 894 fView->AddChild(builder.Layout(), weight); 895 return builder; 896 } 897 898 899 template<typename ParentBuilder> 900 typename Split<ParentBuilder>::SplitBuilder 901 Split<ParentBuilder>::AddSplit(enum orientation orientation, float spacing, 902 float weight) 903 { 904 SplitBuilder builder(orientation, spacing); 905 builder.SetParent(this); 906 fView->AddChild(builder.View(), weight); 907 return builder; 908 } 909 910 911 template<typename ParentBuilder> 912 typename Split<ParentBuilder>::ThisBuilder& 913 Split<ParentBuilder>::SetCollapsible(bool collapsible) 914 { 915 fView->SetCollapsible(collapsible); 916 return *this; 917 } 918 919 920 template<typename ParentBuilder> 921 typename Split<ParentBuilder>::ThisBuilder& 922 Split<ParentBuilder>::SetCollapsible(int32 index, bool collapsible) 923 { 924 fView->SetCollapsible(index, collapsible); 925 return *this; 926 } 927 928 929 template<typename ParentBuilder> 930 typename Split<ParentBuilder>::ThisBuilder& 931 Split<ParentBuilder>::SetCollapsible(int32 first, int32 last, bool collapsible) 932 { 933 fView->SetCollapsible(first, last, collapsible); 934 return *this; 935 } 936 937 938 template<typename ParentBuilder> 939 typename Split<ParentBuilder>::ThisBuilder& 940 Split<ParentBuilder>::SetInsets(float left, float top, float right, 941 float bottom) 942 { 943 fView->SetInsets(left, top, right, bottom); 944 return *this; 945 } 946 947 948 template<typename ParentBuilder> 949 Split<ParentBuilder>::operator BSplitView*() 950 { 951 return fView; 952 } 953 954 955 } // namespace BLayoutBuilder 956 957 958 #endif // _LAYOUT_BUILDER_H 959