1 /* 2 * Copyright 2006 - 2010, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef ALM_LAYOUT_H 6 #define ALM_LAYOUT_H 7 8 9 #include <AbstractLayout.h> 10 #include <File.h> 11 #include <List.h> 12 #include <Size.h> 13 #include <SupportDefs.h> 14 #include <View.h> 15 16 #include "Area.h" 17 #include "Column.h" 18 #include "LinearSpec.h" 19 #include "Row.h" 20 #include "Tab.h" 21 22 23 namespace BALM { 24 25 /*! 26 * A GUI layout engine using the Auckland Layout Model (ALM). 27 */ 28 class BALMLayout : public BAbstractLayout { 29 public: 30 BALMLayout(float spacing = 0.0f); 31 virtual ~BALMLayout(); 32 33 XTab* AddXTab(); 34 YTab* AddYTab(); 35 Row* AddRow(); 36 Row* AddRow(YTab* top, YTab* bottom); 37 Column* AddColumn(); 38 Column* AddColumn(XTab* left, XTab* right); 39 40 XTab* Left() const; 41 XTab* Right() const; 42 YTab* Top() const; 43 YTab* Bottom() const; 44 45 char* PerformancePath() const; 46 void SetPerformancePath(char* path); 47 48 LinearSpec* Solver() const; 49 50 void SetInset(float inset); 51 float Inset() const; 52 53 void SetSpacing(float spacing); 54 float Spacing() const; 55 56 Area* AreaFor(const BView* view) const; 57 Area* AreaFor(const BLayoutItem* item) const; 58 Area* CurrentArea() const; 59 void SetCurrentArea(const Area* area); 60 void SetCurrentArea(const BView* view); 61 void SetCurrentArea(const BLayoutItem* item); 62 63 XTab* LeftOf(const BView* view) const; 64 XTab* LeftOf(const BLayoutItem* item) const; 65 XTab* RightOf(const BView* view) const; 66 XTab* RightOf(const BLayoutItem* item) const; 67 YTab* TopOf(const BView* view) const; 68 YTab* TopOf(const BLayoutItem* item) const; 69 YTab* BottomOf(const BView* view) const; 70 YTab* BottomOf(const BLayoutItem* item) const; 71 72 virtual BLayoutItem* AddView(BView* child); 73 virtual BLayoutItem* AddView(int32 index, BView* child); 74 virtual Area* AddView(BView* view, XTab* left, YTab* top, 75 XTab* right = NULL, YTab* bottom = NULL); 76 virtual Area* AddView(BView* view, Row* row, Column* column); 77 virtual Area* AddViewToRight(BView* view, XTab* right = NULL, 78 YTab* top = NULL, YTab* bottom = NULL); 79 virtual Area* AddViewToLeft(BView* view, XTab* left = NULL, 80 YTab* top = NULL, YTab* bottom = NULL); 81 virtual Area* AddViewToTop(BView* view, YTab* top = NULL, 82 XTab* left = NULL, XTab* right = NULL); 83 virtual Area* AddViewToBottom(BView* view, 84 YTab* bottom = NULL, XTab* left = NULL, 85 XTab* right = NULL); 86 87 virtual bool AddItem(BLayoutItem* item); 88 virtual bool AddItem(int32 index, BLayoutItem* item); 89 virtual Area* AddItem(BLayoutItem* item, XTab* left, 90 YTab* top, XTab* right = NULL, 91 YTab* bottom = NULL); 92 virtual Area* AddItem(BLayoutItem* item, Row* row, 93 Column* column); 94 virtual Area* AddItemToRight(BLayoutItem* item, 95 XTab* right = NULL, YTab* top = NULL, 96 YTab* bottom = NULL); 97 virtual Area* AddItemToLeft(BLayoutItem* item, 98 XTab* left = NULL, YTab* top = NULL, 99 YTab* bottom = NULL); 100 virtual Area* AddItemToTop(BLayoutItem* item, 101 YTab* top = NULL, XTab* left = NULL, 102 XTab* right = NULL); 103 virtual Area* AddItemToBottom(BLayoutItem* item, 104 YTab* bottom = NULL, XTab* left = NULL, 105 XTab* right = NULL); 106 107 virtual BSize BaseMinSize(); 108 virtual BSize BaseMaxSize(); 109 virtual BSize BasePreferredSize(); 110 virtual BAlignment BaseAlignment(); 111 112 virtual void InvalidateLayout(bool children = false); 113 114 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 115 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 116 virtual void DerivedLayoutItems(); 117 118 private: 119 /*! Add a view without initialize the Area. */ 120 BLayoutItem* _CreateLayoutItem(BView* view); 121 122 void _SolveLayout(); 123 124 void _UpdateAreaConstraints(); 125 126 BSize _CalculateMinSize(); 127 BSize _CalculateMaxSize(); 128 BSize _CalculatePreferredSize(); 129 130 131 LinearSpec fSolver; 132 133 XTab* fLeft; 134 XTab* fRight; 135 YTab* fTop; 136 YTab* fBottom; 137 BSize fMinSize; 138 BSize fMaxSize; 139 BSize fPreferredSize; 140 char* fPerformancePath; 141 142 float fInset; 143 float fSpacing; 144 145 Area* fCurrentArea; 146 }; 147 148 } // namespace BALM 149 150 using BALM::BALMLayout; 151 152 #endif // ALM_LAYOUT_H 153