ManaPlus
layoutcell.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2007-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WIDGETS_LAYOUTCELL_H
25 #define GUI_WIDGETS_LAYOUTCELL_H
26 
27 #include "localconsts.h"
28 
29 class LayoutArray;
30 class Widget;
31 
40 {
41  friend class Layout;
42  friend class LayoutArray;
43 
44  public:
46 
47  enum Alignment
48  {
49  LEFT = 0,
52  FILL
53  };
54 
55  virtual ~LayoutCell();
56 
61  { mHPadding = p; mVPadding = p; return *this; }
62 
63  int getVPadding() const
64  { return mVPadding; }
65 
66  int getHPadding() const
67  { return mHPadding; }
68 
73  { mVPadding = p; return *this; }
74 
79  { mHPadding = p; return *this; }
80 
85  { mAlign[0] = a; return *this; }
86 
91  { mAlign[1] = a; return *this; }
92 
96  LayoutCell &at(const int x, const int y) A_WARN_UNUSED;
97 
101  LayoutCell &place(Widget *const wg,
102  const int x,
103  const int y,
104  const int w,
105  const int h);
106 
110  void matchColWidth(const int n1, const int n2);
111 
115  void setColWidth(const int n, const int w);
116 
120  void setRowHeight(const int n, const int h);
121 
125  void extend(const int x, const int y,
126  const int w, const int h);
127 
132  void computeSizes();
133 
134  void setType(int t)
135  { mType = t; }
136 
138  { return mExtent[0]; }
139 
141  { return mExtent[1]; }
142 
143  void setWidth(const int w) noexcept2
144  { mExtent[0] = w; }
145 
146  void setHeight(const int h) noexcept2
147  { mExtent[1] = h; }
148 
149  enum
150  {
151  NONE = 0,
153  ARRAY
154  };
155 
157 
158  private:
160  mWidget(nullptr),
161  mHPadding(0),
162  mVPadding(0),
163  mType(NONE)
164  {
165  mExtent[0] = 0;
166  mExtent[1] = 0;
167  mAlign[0] = LEFT;
168  mAlign[1] = LEFT;
169  mNbFill[0] = 0;
170  mNbFill[1] = 0;
171  mSize[0] = 0;
172  mSize[1] = 0;
173  }
174 
175  // Copy not allowed, as the cell may own an array.
176  explicit LayoutCell(LayoutCell const &);
178 
179  union
180  {
183  };
184 
190 
194  void reflow(int nx, int ny, int nw, int nh);
195 
196  int mSize[2];
199  int mExtent[2];
201  int mNbFill[2];
202  int mType;
203 };
204 
205 #endif // GUI_WIDGETS_LAYOUTCELL_H
virtual ~LayoutCell()
Definition: layoutcell.cpp:36
void extend(const int x, const int y, const int w, const int h)
Definition: layoutcell.cpp:133
static LayoutCell emptyCell
Definition: layoutcell.h:156
void reflow(int nx, int ny, int nw, int nh)
Definition: layoutcell.cpp:64
LayoutCell & operator=(LayoutCell const &)
LayoutCell & setPadding(int p)
Definition: layoutcell.h:60
int mExtent[2]
Definition: layoutcell.h:199
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:128
int mSize[2]
Definition: layoutcell.h:196
void setColWidth(const int n, const int w)
Definition: layoutcell.cpp:123
int mNbFill[2]
Definition: layoutcell.h:201
Alignment mAlign[2]
Definition: layoutcell.h:200
int getHPadding() const
Definition: layoutcell.h:66
void setType(int t)
Definition: layoutcell.h:134
void setWidth(const int w)
Definition: layoutcell.h:143
LayoutCell & setHPadding(int p)
Definition: layoutcell.h:78
LayoutArray * mArray
Definition: layoutcell.h:182
int getVPadding() const
Definition: layoutcell.h:63
LayoutCell(LayoutCell const &)
int getHeight() const
Definition: layoutcell.h:140
LayoutCell & place(Widget *const wg, const int x, const int y, const int w, const int h)
Definition: layoutcell.cpp:111
int mHPadding
Definition: layoutcell.h:197
LayoutCell & setHAlign(const Alignment a)
Definition: layoutcell.h:84
int getWidth() const
Definition: layoutcell.h:137
LayoutCell & setVAlign(const Alignment a)
Definition: layoutcell.h:90
LayoutCell & setVPadding(int p)
Definition: layoutcell.h:72
LayoutArray & getArray()
Definition: layoutcell.cpp:42
void computeSizes()
Definition: layoutcell.cpp:79
Widget * mWidget
Definition: layoutcell.h:181
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:118
LayoutCell & at(const int x, const int y)
Definition: layoutcell.cpp:106
void setHeight(const int h)
Definition: layoutcell.h:146
int mVPadding
Definition: layoutcell.h:198
Definition: layout.h:45
Definition: widget.h:99
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define noexcept2
Definition: localconsts.h:50
#define nullptr
Definition: localconsts.h:45
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:41