Mana
Loading...
Searching...
No Matches
layout.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2007-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <guichan/widgets/container.hpp>
25
26#include <vector>
27
28class LayoutCell;
29
34{
35 public:
36 ContainerPlacer(gcn::Container *c = nullptr, LayoutCell *l = nullptr):
37 mContainer(c), mCell(l)
38 {}
39
44 { return *mCell; }
45
49 ContainerPlacer at(int x, int y);
50
55 LayoutCell &operator()
56 (int x, int y, gcn::Widget *, int w = 1, int h = 1);
57
58 private:
59 gcn::Container *mContainer;
61};
62
67{
68 friend class LayoutCell;
69
70 public:
71
73
75
79 LayoutCell &at(int x, int y, int w = 1, int h = 1);
80
88 LayoutCell &place(gcn::Widget *, int x, int y, int w = 1, int h = 1);
89
93 void setColWidth(int n, int w);
94
98 void setRowHeight(int n, int h);
99
103 void matchColWidth(int n1, int n2);
104
108 void extend(int x, int y, int w, int h);
109
115 void reflow(int nX, int nY, int nW, int nH);
116
117 private:
118
119 // Copy not allowed, as the array owns all its cells.
122
126 void align(int &pos, int &size, int dim,
127 LayoutCell const &cell, const short *sizes) const;
128
132 void resizeGrid(int w, int h);
133
138 std::vector< short > getSizes(int dim, int upp) const;
139
143 int getSize(int dim) const;
144
145 std::vector< short > mSizes[2];
146 std::vector< std::vector < LayoutCell * > > mCells;
147
149};
150
159{
160 friend class Layout;
161 friend class LayoutArray;
162
163 public:
168
169 LayoutCell() = default;
170 ~LayoutCell();
171
172 // Copy not allowed, as the cell may own an array.
173 LayoutCell(LayoutCell const &) = delete;
174 LayoutCell &operator=(LayoutCell const &) = delete;
175
180 { mPadding = p; return *this; }
181
186 { mAlign[0] = a; return *this; }
187
192 { mAlign[1] = a; return *this; }
193
197 LayoutCell &at(int x, int y)
198 { return getArray().at(x, y); }
199
203 LayoutCell &place(gcn::Widget *wg, int x, int y, int w = 1, int h = 1)
204 { return getArray().place(wg, x, y, w, h); }
205
209 void matchColWidth(int n1, int n2)
210 { getArray().matchColWidth(n1, n2); }
211
215 void setColWidth(int n, int w)
216 { getArray().setColWidth(n, w); }
217
221 void setRowHeight(int n, int h)
222 { getArray().setRowHeight(n, h); }
223
227 void extend(int x, int y, int w, int h)
228 { getArray().extend(x, y, w, h); }
229
234 void computeSizes();
235
236 private:
237 union
238 {
239 gcn::Widget *mWidget;
241 };
242
243 enum
244 {
246 };
247
253
257 void reflow(int nx, int ny, int nw, int nh);
258
259 short mSize[2];
261 char mExtent[2];
262 char mAlign[2];
263 char mNbFill[2];
264 char mType = NONE;
265};
266
280class Layout : public LayoutCell
281{
282 public:
283 Layout();
284
288 void setMargin(int m)
289 { setPadding(m); }
290
295 void reflow(int &nW, int &nH);
296
301 enum
302 {
303 AUTO_DEF = -42,
304 AUTO_SET = -43,
305 AUTO_ADD = -44
306 };
307
308 private:
310};
This class is a helper for adding widgets to nested tables in a window.
Definition layout.h:34
ContainerPlacer(gcn::Container *c=nullptr, LayoutCell *l=nullptr)
Definition layout.h:36
LayoutCell * mCell
Definition layout.h:60
LayoutCell & getCell()
Gets the pointed cell.
Definition layout.h:43
gcn::Container * mContainer
Definition layout.h:59
ContainerPlacer at(int x, int y)
Returns a placer for the same container but to an inner cell.
Definition layout.cpp:26
This class contains a rectangular array of cells.
Definition layout.h:67
std::vector< std::vector< LayoutCell * > > mCells
Definition layout.h:146
void align(int &pos, int &size, int dim, LayoutCell const &cell, const short *sizes) const
Gets the position and size of a widget along a given axis.
Definition layout.cpp:190
std::vector< short > mSizes[2]
Definition layout.h:145
void setColWidth(int n, int w)
Sets the minimum width of a column.
Definition layout.cpp:140
LayoutArray(LayoutArray const &)
void reflow(int nX, int nY, int nW, int nH)
Computes and sets the positions of all the widgets.
Definition layout.cpp:287
void matchColWidth(int n1, int n2)
Sets the widths of two columns to the maximum of their widths.
Definition layout.cpp:152
int getSize(int dim) const
Gets the total size along a given axis.
Definition layout.cpp:274
void extend(int x, int y, int w, int h)
Spawns a cell over several columns/rows.
Definition layout.cpp:161
void resizeGrid(int w, int h)
Ensures the private vectors are large enough.
Definition layout.cpp:115
char mSpacing
Definition layout.h:148
LayoutCell & place(gcn::Widget *, int x, int y, int w=1, int h=1)
Places a widget in a given cell.
Definition layout.cpp:168
std::vector< short > getSizes(int dim, int upp) const
Gets the column/row sizes along a given axis.
Definition layout.cpp:214
void setRowHeight(int n, int h)
Sets the minimum height of a row.
Definition layout.cpp:146
LayoutCell & at(int x, int y, int w=1, int h=1)
Returns a reference on the cell at given position.
Definition layout.cpp:104
LayoutArray & operator=(LayoutArray const &)
This class describes the formatting of a widget in the cell of a layout table.
Definition layout.h:159
~LayoutCell()
Definition layout.cpp:38
void setRowHeight(int n, int h)
Definition layout.h:221
LayoutCell & setPadding(int p)
Sets the padding around the cell content.
Definition layout.h:179
char mAlign[2]
Definition layout.h:262
char mPadding
Definition layout.h:260
short mSize[2]
Definition layout.h:259
char mNbFill[2]
Definition layout.h:263
char mType
Definition layout.h:264
LayoutCell(LayoutCell const &)=delete
void reflow(int nx, int ny, int nw, int nh)
Definition layout.cpp:59
void setColWidth(int n, int w)
Definition layout.h:215
LayoutCell()=default
LayoutCell & operator=(LayoutCell const &)=delete
gcn::Widget * mWidget
Definition layout.h:239
void matchColWidth(int n1, int n2)
Definition layout.h:209
LayoutCell & place(gcn::Widget *wg, int x, int y, int w=1, int h=1)
Definition layout.h:203
LayoutArray * mArray
Definition layout.h:240
LayoutCell & setVAlign(Alignment a)
Sets the vertical alignment of the cell content.
Definition layout.h:191
char mExtent[2]
Definition layout.h:261
LayoutCell & setHAlign(Alignment a)
Sets the horizontal alignment of the cell content.
Definition layout.h:185
void extend(int x, int y, int w, int h)
Definition layout.h:227
LayoutCell & at(int x, int y)
Definition layout.h:197
LayoutArray & getArray()
Returns the embedded array.
Definition layout.cpp:44
void computeSizes()
Sets the minimum widths and heights of this cell and of all the inner cells.
Definition layout.cpp:72
This class is an helper for setting the position of widgets.
Definition layout.h:281
void reflow(int &nW, int &nH)
Sets the positions of all the widgets.
Definition layout.cpp:321
Layout()
Definition layout.cpp:315
@ AUTO_ADD
Adds the share to the current size.
Definition layout.h:305
@ AUTO_SET
Uses the share as the new size.
Definition layout.h:304
@ AUTO_DEF
Default value, behaves like AUTO_ADD.
Definition layout.h:303
bool mComputed
Definition layout.h:309
void setMargin(int m)
Sets the margin around the layout.
Definition layout.h:288