1 /* 2 * Copyright 2006 - 2010, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef AREA_H 6 #define AREA_H 7 8 9 #include <vector> 10 11 #include <Alignment.h> 12 #include <List.h> 13 #include <Size.h> 14 #include <SupportDefs.h> 15 #include <View.h> 16 17 #include "Column.h" 18 #include "LinearSpec.h" 19 #include "Row.h" 20 #include "Tab.h" 21 22 23 class Constraint; 24 25 26 namespace BALM { 27 28 29 class GroupItem { 30 public: 31 GroupItem(BLayoutItem* item); 32 GroupItem(BView* view); 33 34 BLayoutItem* LayoutItem(); 35 BView* View(); 36 37 const std::vector<GroupItem>& GroupItems(); 38 enum orientation Orientation(); 39 40 GroupItem& operator|(const GroupItem& right); 41 GroupItem& operator/(const GroupItem& bottom); 42 private: 43 GroupItem(); 44 45 void _Init(BLayoutItem* item, BView* view, 46 enum orientation orien = B_HORIZONTAL); 47 GroupItem& _AddItem(const GroupItem& item, 48 enum orientation orien); 49 50 BLayoutItem* fLayoutItem; 51 BView* fView; 52 53 std::vector<GroupItem> fGroupItems; 54 enum orientation fOrientation; 55 }; 56 57 58 /** 59 * Rectangular area in the GUI, defined by a tab on each side. 60 */ 61 class Area { 62 public: 63 ~Area(); 64 65 BView* View(); 66 67 XTab* Left() const; 68 XTab* Right() const; 69 YTab* Top() const; 70 YTab* Bottom() const; 71 void SetLeft(XTab* left); 72 void SetRight(XTab* right); 73 void SetTop(YTab* top); 74 void SetBottom(YTab* bottom); 75 76 Row* GetRow() const; 77 Column* GetColumn() const; 78 void SetRow(Row* row); 79 void SetColumn(Column* column); 80 81 double ContentAspectRatio() const; 82 void SetContentAspectRatio(double ratio); 83 84 BSize ShrinkPenalties() const; 85 BSize GrowPenalties() const; 86 void SetShrinkPenalties(BSize shrink); 87 void SetGrowPenalties(BSize grow); 88 89 int32 LeftInset() const; 90 int32 TopInset() const; 91 int32 RightInset() const; 92 int32 BottomInset() const; 93 void SetLeftInset(int32 left); 94 void SetTopInset(int32 top); 95 void SetRightInset(int32 right); 96 void SetBottomInset(int32 bottom); 97 98 operator BString() const; 99 void GetString(BString& string) const; 100 101 Constraint* SetWidthAs(Area* area, float factor = 1.0f); 102 Constraint* SetHeightAs(Area* area, float factor = 1.0f); 103 104 void InvalidateSizeConstraints(); 105 106 private: 107 Area(BLayoutItem* item); 108 109 void _Init(LinearSpec* ls, XTab* left, YTab* top, 110 XTab* right, YTab* bottom); 111 void _Init(LinearSpec* ls, Row* row, Column* column); 112 113 void _DoLayout(); 114 115 void _UpdateMinSizeConstraint(BSize min); 116 void _UpdateMaxSizeConstraint(BSize max); 117 void _UpdatePreferredConstraint(BSize preferred); 118 119 private: 120 BLayoutItem* fLayoutItem; 121 122 LinearSpec* fLS; 123 124 XTab* fLeft; 125 XTab* fRight; 126 YTab* fTop; 127 YTab* fBottom; 128 129 Row* fRow; 130 Column* fColumn; 131 132 BSize fShrinkPenalties; 133 BSize fGrowPenalties; 134 135 BSize fTopLeftInset; 136 BSize fRightBottomInset; 137 138 BList fConstraints; 139 Constraint* fMinContentWidth; 140 Constraint* fMaxContentWidth; 141 Constraint* fMinContentHeight; 142 Constraint* fMaxContentHeight; 143 Constraint* fPreferredContentWidth; 144 Constraint* fPreferredContentHeight; 145 double fContentAspectRatio; 146 Constraint* fContentAspectRatioC; 147 148 public: 149 friend class BALMLayout; 150 151 }; 152 153 } // namespace BALM 154 155 using BALM::Area; 156 using BALM::GroupItem; 157 158 #endif // AREA_H 159 160