xref: /haiku/headers/libs/alm/Area.h (revision e8cd7007416a323259791ac09c013dcce2956976)
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 #define USE_SCALE_VARIABLE 0
24 
25 
26 class Constraint;
27 
28 
29 namespace BALM {
30 
31 
32 class GroupItem {
33 public:
34 								GroupItem(BLayoutItem* item);
35 								GroupItem(BView* view);
36 
37 			BLayoutItem*		LayoutItem();
38 			BView*				View();
39 
40 	const	std::vector<GroupItem>&	GroupItems();
41 			enum orientation	Orientation();
42 
43 			GroupItem& 			operator|(const GroupItem& right);
44 			GroupItem& 			operator/(const GroupItem& bottom);
45 private:
46 								GroupItem();
47 
48 			void				_Init(BLayoutItem* item, BView* view,
49 									  enum orientation orien = B_HORIZONTAL);
50 			GroupItem& 			_AddItem(const GroupItem& item,
51 									enum orientation orien);
52 
53 			BLayoutItem*		fLayoutItem;
54 			BView*				fView;
55 
56 			std::vector<GroupItem>	fGroupItems;
57 			enum orientation	fOrientation;
58 };
59 
60 
61 /**
62  * Rectangular area in the GUI, defined by a tab on each side.
63  */
64 class Area {
65 public:
66 								~Area();
67 
68 			BView*				View();
69 
70 			XTab*				Left() const;
71 			XTab*				Right() const;
72 			YTab*				Top() const;
73 			YTab*				Bottom() const;
74 			void				SetLeft(XTab* left);
75 			void				SetRight(XTab* right);
76 			void				SetTop(YTab* top);
77 			void				SetBottom(YTab* bottom);
78 
79 			Row*				GetRow() const;
80 			Column*				GetColumn() const;
81 			void				SetRow(Row* row);
82 			void				SetColumn(Column* column);
83 
84 			double				ContentAspectRatio() const;
85 			void				SetContentAspectRatio(double ratio);
86 
87 			BSize				ShrinkPenalties() const;
88 			BSize				GrowPenalties() const;
89 			void				SetShrinkPenalties(BSize shrink);
90 			void				SetGrowPenalties(BSize grow);
91 
92 			float				LeftInset() const;
93 			float				TopInset() const;
94 			float				RightInset() const;
95 			float				BottomInset() const;
96 			void				SetLeftInset(float left);
97 			void				SetTopInset(float top);
98 			void				SetRightInset(float right);
99 			void				SetBottomInset(float bottom);
100 
101 								operator BString() const;
102 			void				GetString(BString& string) const;
103 
104 			Constraint*			SetWidthAs(Area* area, float factor = 1.0f);
105 			Constraint*			SetHeightAs(Area* area, float factor = 1.0f);
106 
107 			void				InvalidateSizeConstraints();
108 
109 private:
110 								Area(BLayoutItem* item);
111 
112 #if USE_SCALE_VARIABLE
113 			void				_Init(LinearSpec* ls, XTab* left, YTab* top,
114 									XTab* right, YTab* bottom,
115 									Variable* scaleWidth,
116 									Variable* scaleHeight);
117 			void				_Init(LinearSpec* ls, Row* row, Column* column,
118 									Variable* scaleWidth,
119 									Variable* scaleHeight);
120 #else
121 			void				_Init(LinearSpec* ls, XTab* left, YTab* top,
122 									XTab* right, YTab* bottom);
123 			void				_Init(LinearSpec* ls, Row* row, Column* column);
124 #endif
125 
126 			void				_DoLayout();
127 
128 			void				_UpdateMinSizeConstraint(BSize min);
129 			void				_UpdateMaxSizeConstraint(BSize max);
130 			void				_UpdatePreferredWidthConstraint(
131 									BSize& preferred);
132 			void				_UpdatePreferredHeightConstraint(
133 									BSize& preferred);
134 			void				_SetupPreferredConstraints();
135 private:
136 			BLayoutItem*		fLayoutItem;
137 
138 			LinearSpec*			fLS;
139 
140 			XTab*				fLeft;
141 			XTab*				fRight;
142 			YTab*				fTop;
143 			YTab*				fBottom;
144 
145 			Row*				fRow;
146 			Column*				fColumn;
147 
148 			BSize				fShrinkPenalties;
149 			BSize				fGrowPenalties;
150 
151 			BSize				fTopLeftInset;
152 			BSize				fRightBottomInset;
153 
154 			BList				fConstraints;
155 			Constraint*			fMinContentWidth;
156 			Constraint*			fMaxContentWidth;
157 			Constraint*			fMinContentHeight;
158 			Constraint*			fMaxContentHeight;
159 			Constraint*			fPreferredContentWidth;
160 			Constraint*			fPreferredContentHeight;
161 			double				fContentAspectRatio;
162 			Constraint*			fContentAspectRatioC;
163 
164 #if USE_SCALE_VARIABLE
165 			Variable*			fScaleWidth;
166 			Variable*			fScaleHeight;
167 #endif
168 public:
169 	friend class		BALMLayout;
170 
171 };
172 
173 }	// namespace BALM
174 
175 using BALM::Area;
176 using BALM::GroupItem;
177 
178 #endif	// AREA_H
179 
180