1 //------------------------------------------------------------------------------
2 // emTiling.h
3 //
4 // Copyright (C) 2005-2010,2014-2015 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20
21 #ifndef emTiling_h
22 #define emTiling_h
23
24 #ifndef emBorder_h
25 #include <emCore/emBorder.h>
26 #endif
27
28
29 //==============================================================================
30 //================================== emTiling ==================================
31 //==============================================================================
32
33 class emTiling : public emBorder {
34
35 public:
36
37 // *********************************************************************
38 // * WARNING!!! *
39 // * *
40 // * This class is deprecated and will be removed in a future version. *
41 // * Please use emLinearLayout, emRasterLayout or emPackLayout instead.*
42 // *********************************************************************
43 //
44 // A panel of this class automatically lays out any child panels within
45 // the content area, just like in a rectangular tiling. By default, the
46 // panel itself is not focusable and has no border, because it is meant
47 // as a pure layout programming tool. For other use, see the derived
48 // class emGroup.
49
50 EM_DEPRECATED( // Because the whole class is deprecated!
51 emTiling(
52 ParentArg parent, const emString & name,
53 const emString & caption=emString(),
54 const emString & description=emString(),
55 const emImage & icon=emImage()
56 )
57 );
58 // Like emBorder, but sets non-focusable.
59
60 virtual ~emTiling();
61 // Destructor.
62
63 bool IsRowByRow() const;
64 void SetRowByRow(bool rowByRow=true);
65 // Whether to layout the child panels column-by-column (false,
66 // the default) or row-by-row (true). Here is an example for the
67 // order of 10 panels in a 4x3 grid:
68 // column-by-column row-by-row
69 // 1 4 7 10 1 2 3 4
70 // 2 5 8 5 6 7 8
71 // 3 6 9 9 10
72
73 int GetFixedColumnCount() const;
74 int GetFixedRowCount() const;
75 void SetFixedColumnCount(int fixedColumnCount);
76 void SetFixedRowCount(int fixedRowCount);
77 // Whether to have a fixed number of columns or rows, and how
78 // many. A value less or equal zero means to have no fixed
79 // number of columns or rows and to let the layout algorithm
80 // decide it. If both are fixed and if there are more child
81 // panels than cells, the row count is increased accordingly.
82 // The default is zero for both.
83
84 int GetMinCellCount() const;
85 void SetMinCellCount(int minCellCount);
86 // Minimum number of cells to be generated. The layout algorithm
87 // behaves like if there were at least this number of child
88 // panels. The additional cells are simply making up unused
89 // space. The default is zero.
90
91 void SetChildTallness(double ct);
92 // Set the demanded tallness of child panels (height/width
93 // ratio). This method is a short cut for:
94 // SetPrefChildTallness(ct);
95 // SetChildTallnessForced();
96
97 void SetPrefChildTallness(double pct);
98 // Set the preferred tallness of child panels (height/width
99 // ratio). The child panels may get another tallness, for
100 // filling the available space best possible. This method is a
101 // short cut for: SetPrefChildTallness(pct,0,true);
102
103 double GetPrefChildTallness(int idx) const;
104 void SetPrefChildTallness(double pct, int idx, bool allFurther=true);
105 // Preferred tallness of child panels in the first row and in
106 // the first column. The index idx denotes a cell. It is a cell
107 // in the first row (idx>0) or in the first column (idx<0), or
108 // both (idx==0). Other cells cannot be set, because they are
109 // sized implicitly by the first row and column. Here is a chart
110 // showing the meaning of idx, and the effect of different
111 // tallnesses:
112 //
113 // +--------+-------+-------------+-----+----
114 // | idx 0 | idx 1 | idx 2 |idx 3| ...
115 // +--------+-------+-------------+-----+----
116 // | | | | |
117 // | idx -1 | | | |
118 // | | | | |
119 // +--------+-------+-------------+-----+----
120 // | idx -2 | | | |
121 // +--------+-------+-------------+-----+----
122 // | | | | |
123 // | | | | |
124 // | idx -3 | | | |
125 // | | | | |
126 // | | | | |
127 // +--------+-------+-------------+-----+----
128 // | ... | | | |
129 //
130 // Now to the important trick argument "allFurther": If true
131 // (the default), all further cells in the row and/or column are
132 // even set. For example, SetPrefChildTallness(1.0,3) means to
133 // set the cells 3, 4, 5, ... INT_MAX. And
134 // SetPrefChildTallness(1.0,-2) means to set the cells -2, -3,
135 // -4, ... INT_MIN. And SetPrefChildTallness(1.0,-3,false) means
136 // to set cell -3 only. And SetPrefChildTallness(1.0,0) means to
137 // set all cells at once.
138 //
139 // There is no limit for idx except through the memory required
140 // by internal arrays.
141 //
142 // The default preferred child tallness is: 0.2
143
144 void SetChildTallnessForced(bool forced=true);
145 // Whether the preferred child tallness has to be applied in any
146 // case, instead of deviating for filling the whole available
147 // space. This method is a short cut for:
148 // SetForcedChildTallnessColumn(forced ? 0 : -1);
149 // SetForcedChildTallnessRow(forced ? 0 : -1);
150
151 int GetForcedChildTallnessColumn() const;
152 int GetForcedChildTallnessRow() const;
153 void SetForcedChildTallnessColumn(int column);
154 void SetForcedChildTallnessRow(int row);
155 // Index of a single column or row, in which the preferred child
156 // tallness has to be applied in any case. -1 means to have no
157 // such column or row (this is the default). Understand that if
158 // both a row and a column are forced, all cells of the whole
159 // grid are forced implicitly.
160
161 emAlignment GetAlignment() const;
162 void SetAlignment(emAlignment alignment);
163 // Alignment of the child panels as a whole within the available
164 // space. This applies only if the available space cannot be
165 // filled completely, with respect to forced child tallness. The
166 // default is EM_ALIGN_CENTER.
167
168 double GetSpaceL() const;
169 double GetSpaceT() const;
170 double GetSpaceH() const;
171 double GetSpaceV() const;
172 double GetSpaceR() const;
173 double GetSpaceB() const;
174 void SetSpaceL(double l);
175 void SetSpaceT(double t);
176 void SetSpaceH(double h);
177 void SetSpaceV(double v);
178 void SetSpaceR(double r);
179 void SetSpaceB(double b);
180 void SetSpace(double l, double t, double h, double v, double r,
181 double b);
182 void SetSpace(double lr, double tb, double h, double v);
183 void SetInnerSpace(double h, double v);
184 void SetOuterSpace(double l, double t, double r, double b);
185 void SetOuterSpace(double lr, double tb);
186 // Left, top, horizontal, vertical, right and bottom space (l,
187 // t, h, v, r, b). This defines space between child panels, and
188 // between child panels and borders. Here is a chart showing the
189 // meaning of the six parameters:
190 //
191 // +-------------------- border -------------------+
192 // | t t t |
193 // | +-------+ +-------+ +-------+ |
194 // | l + panel + h + panel + h + panel + r |
195 // | +-------+ +-------+ +-------+ |
196 // | v v v |
197 // | +-------+ +-------+ +-------+ |
198 // | l + panel + h + panel + h + panel + r |
199 // | +-------+ +-------+ +-------+ |
200 // | b b b |
201 // +-----------------------------------------------+
202 //
203 // The method argument lr means to set l and r to the same
204 // value, same with tb for t and b.
205 //
206 // The values are relative to the average size of the child
207 // panels. For example, v=0.5 means that the vertical space
208 // between child panels gets half as tall as an average child
209 // panel. The default is zero for all parameters.
210
211 protected:
212
213 virtual void LayoutChildren();
214 // Tiles all child panels in the content area (except for an
215 // auxiliary panel, which is laid out in the border).
216
217 private:
218
219 double SpaceL,SpaceT,SpaceH,SpaceV,SpaceR,SpaceB;
220 double PCT;
221 emArray<double> PCTPos, PCTNeg;
222 int FixedColumnCount,FixedRowCount,MinCellCount,FCTColumn,FCTRow;
223 emAlignment Alignment;
224 bool RowByRow;
225
226 friend class emGroup;
227 emTiling(
228 ParentArg parent, const emString & name,
229 const emString & caption,
230 const emString & description,
231 const emImage & icon,
232 int notWarningDeprecatedForInternalUse
233 );
234 };
235
IsRowByRow()236 inline bool emTiling::IsRowByRow() const
237 {
238 return RowByRow;
239 }
240
GetFixedColumnCount()241 inline int emTiling::GetFixedColumnCount() const
242 {
243 return FixedColumnCount;
244 }
245
GetFixedRowCount()246 inline int emTiling::GetFixedRowCount() const
247 {
248 return FixedRowCount;
249 }
250
GetMinCellCount()251 inline int emTiling::GetMinCellCount() const
252 {
253 return MinCellCount;
254 }
255
GetForcedChildTallnessColumn()256 inline int emTiling::GetForcedChildTallnessColumn() const
257 {
258 return FCTColumn;
259 }
260
GetForcedChildTallnessRow()261 inline int emTiling::GetForcedChildTallnessRow() const
262 {
263 return FCTRow;
264 }
265
GetAlignment()266 inline emAlignment emTiling::GetAlignment() const
267 {
268 return Alignment;
269 }
270
GetSpaceL()271 inline double emTiling::GetSpaceL() const
272 {
273 return SpaceL;
274 }
275
GetSpaceT()276 inline double emTiling::GetSpaceT() const
277 {
278 return SpaceT;
279 }
280
GetSpaceH()281 inline double emTiling::GetSpaceH() const
282 {
283 return SpaceH;
284 }
285
GetSpaceV()286 inline double emTiling::GetSpaceV() const
287 {
288 return SpaceV;
289 }
290
GetSpaceR()291 inline double emTiling::GetSpaceR() const
292 {
293 return SpaceR;
294 }
295
GetSpaceB()296 inline double emTiling::GetSpaceB() const
297 {
298 return SpaceB;
299 }
300
301
302 #endif
303