1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/*
* The ManaPlus Client
* Copyright (C) 2007-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
* Copyright (C) 2011-2017 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GUI_WIDGETS_LAYOUTCELL_H
#define GUI_WIDGETS_LAYOUTCELL_H
#include "localconsts.h"
class LayoutArray;
class Widget;
/**
* This class describes the formatting of a widget in the cell of a layout
* table. Horizontally, a widget can either fill the width of the cell (minus
* the cell padding), or it can retain its size and be flushed left, or flush
* right, or centered in the cell. The process is similar for the vertical
* alignment, except that top is represented by LEFT and bottom by RIGHT.
*/
class LayoutCell notfinal
{
friend class Layout;
friend class LayoutArray;
public:
A_DEFAULT_COPY(LayoutCell)
enum Alignment
{
LEFT = 0,
RIGHT,
CENTER,
FILL
};
virtual ~LayoutCell();
/**
* Sets the padding around the cell content.
*/
LayoutCell &setPadding(int p)
{ mHPadding = p; mVPadding = p; return *this; }
/**
* Sets the vertical padding around the cell content.
*/
LayoutCell &setVPadding(int p)
{ mVPadding = p; return *this; }
/**
* Sets the horisontal padding around the cell content.
*/
LayoutCell &setHPadding(int p)
{ mHPadding = p; return *this; }
/**
* Sets the horizontal alignment of the cell content.
*/
LayoutCell &setHAlign(const Alignment a)
{ mAlign[0] = a; return *this; }
/**
* Sets the vertical alignment of the cell content.
*/
LayoutCell &setVAlign(const Alignment a)
{ mAlign[1] = a; return *this; }
/**
* @see LayoutArray::at
*/
LayoutCell &at(const int x, const int y) A_WARN_UNUSED;
/**
* @see LayoutArray::place
*/
LayoutCell &place(Widget *const wg,
const int x, const int y,
const int w = 1, const int h = 1);
/**
* @see LayoutArray::matchColWidth
*/
void matchColWidth(const int n1, const int n2);
/**
* @see LayoutArray::setColWidth
*/
void setColWidth(const int n, const int w);
/**
* @see LayoutArray::setRowHeight
*/
void setRowHeight(const int n, const int h);
/**
* @see LayoutArray::extend.
*/
void extend(const int x, const int y,
const int w, const int h);
/**
* Sets the minimum widths and heights of this cell and of all the
* inner cells.
*/
void computeSizes();
void setType(int t)
{ mType = t; }
int getWidth() const noexcept2 A_WARN_UNUSED
{ return mExtent[0]; }
int getHeight() const noexcept2 A_WARN_UNUSED
{ return mExtent[1]; }
void setWidth(const int w) noexcept2
{ mExtent[0] = w; }
void setHeight(const int h) noexcept2
{ mExtent[1] = h; }
enum
{
NONE = 0,
WIDGET,
ARRAY
};
static LayoutCell emptyCell;
private:
LayoutCell() :
mWidget(nullptr),
mHPadding(0),
mVPadding(0),
mType(NONE)
{
mExtent[0] = 0;
mExtent[1] = 0;
mAlign[0] = LEFT;
mAlign[1] = LEFT;
mNbFill[0] = 0;
mNbFill[1] = 0;
mSize[0] = 0;
mSize[1] = 0;
}
// Copy not allowed, as the cell may own an array.
explicit LayoutCell(LayoutCell const &);
LayoutCell &operator=(LayoutCell const &);
union
{
Widget *mWidget;
LayoutArray *mArray;
};
/**
* Returns the embedded array. Creates it if the cell does not contain
* anything yet. Aborts if it contains a widget.
*/
LayoutArray &getArray();
/**
* @see LayoutArray::reflow
*/
void reflow(int nx, int ny, int nw, int nh);
int mSize[2];
int mHPadding;
int mVPadding;
int mExtent[2];
Alignment mAlign[2];
int mNbFill[2];
int mType;
};
#endif // GUI_WIDGETS_LAYOUTCELL_H
|