ManaPlus
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends
LayoutCell Class Reference

#include <layoutcell.h>

Inheritance diagram for LayoutCell:
Layout

Public Types

enum  Alignment { LEFT = 0, RIGHT, CENTER, FILL }
 
enum  { NONE = 0, WIDGET, ARRAY }
 

Public Member Functions

virtual ~LayoutCell ()
 
LayoutCellsetPadding (int p)
 
int getVPadding () const
 
int getHPadding () const
 
LayoutCellsetVPadding (int p)
 
LayoutCellsetHPadding (int p)
 
LayoutCellsetHAlign (const Alignment a)
 
LayoutCellsetVAlign (const Alignment a)
 
LayoutCellat (const int x, const int y)
 
LayoutCellplace (Widget *const wg, const int x, const int y, const int w, const int h)
 
void matchColWidth (const int n1, const int n2)
 
void setColWidth (const int n, const int w)
 
void setRowHeight (const int n, const int h)
 
void extend (const int x, const int y, const int w, const int h)
 
void computeSizes ()
 
void setType (int t)
 
int getWidth () const
 
int getHeight () const
 
void setWidth (const int w)
 
void setHeight (const int h)
 

Static Public Attributes

static LayoutCell emptyCell
 

Private Member Functions

 LayoutCell ()
 
 LayoutCell (LayoutCell const &)
 
LayoutCelloperator= (LayoutCell const &)
 
LayoutArraygetArray ()
 
void reflow (int nx, int ny, int nw, int nh)
 

Private Attributes

union {
   Widget *   mWidget
 
   LayoutArray *   mArray
 
}; 
 
int mSize [2]
 
int mHPadding
 
int mVPadding
 
int mExtent [2]
 
Alignment mAlign [2]
 
int mNbFill [2]
 
int mType
 

Friends

class Layout
 
class LayoutArray
 

Detailed Description

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.

Definition at line 38 of file layoutcell.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
NONE 
WIDGET 
ARRAY 

Definition at line 148 of file layoutcell.h.

149  {
150  NONE = 0,
151  WIDGET,
152  ARRAY
153  };

◆ Alignment

Enumerator
LEFT 
RIGHT 
CENTER 
FILL 

Definition at line 46 of file layoutcell.h.

47  {
48  LEFT = 0,
49  RIGHT,
50  CENTER,
51  FILL
52  };

Constructor & Destructor Documentation

◆ ~LayoutCell()

LayoutCell::~LayoutCell ( )
virtual

Definition at line 35 of file layoutcell.cpp.

References ARRAY, delete2, mArray, and mType.

36 {
37  if (mType == ARRAY)
39 }
#define delete2(var)
Definition: delete2.h:24
LayoutArray * mArray
Definition: layoutcell.h:181

◆ LayoutCell() [1/2]

LayoutCell::LayoutCell ( )
inlineprivate

Definition at line 158 of file layoutcell.h.

References LEFT, mAlign, mExtent, mNbFill, mSize, and operator=().

158  :
159  mWidget(nullptr),
160  mHPadding(0),
161  mVPadding(0),
162  mType(NONE)
163  {
164  mExtent[0] = 0;
165  mExtent[1] = 0;
166  mAlign[0] = LEFT;
167  mAlign[1] = LEFT;
168  mNbFill[0] = 0;
169  mNbFill[1] = 0;
170  mSize[0] = 0;
171  mSize[1] = 0;
172  }
int mHPadding
Definition: layoutcell.h:196
int mVPadding
Definition: layoutcell.h:197
int mNbFill[2]
Definition: layoutcell.h:200
Widget * mWidget
Definition: layoutcell.h:180
int mSize[2]
Definition: layoutcell.h:195
int mExtent[2]
Definition: layoutcell.h:198
Alignment mAlign[2]
Definition: layoutcell.h:199

◆ LayoutCell() [2/2]

LayoutCell::LayoutCell ( LayoutCell const &  )
explicitprivate

Member Function Documentation

◆ at()

LayoutCell & LayoutCell::at ( const int  x,
const int  y 
)
See also
LayoutArray::at

Definition at line 105 of file layoutcell.cpp.

References LayoutArray::at(), and getArray().

Referenced by ContainerPlacer::at(), LayoutHelper::getPlacer(), and setVAlign().

106 {
107  return getArray().at(x, y, 1, 1);
108 }
LayoutArray & getArray()
Definition: layoutcell.cpp:41
LayoutCell & at(const int x, const int y, const int w, const int h)
Definition: layoutarray.cpp:59

◆ computeSizes()

void LayoutCell::computeSizes ( )

Sets the minimum widths and heights of this cell and of all the inner cells.

Definition at line 78 of file layoutcell.cpp.

References ARRAY, computeSizes(), LayoutArray::getSize(), mArray, LayoutArray::mCells, mSize, and mType.

Referenced by computeSizes(), Layout::reflow(), and setVAlign().

79 {
80  if (mType != ARRAY)
81  return;
82 
83  STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
84  i = mArray->mCells.begin();
85  const STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
86  i_end = mArray->mCells.end();
87  while (i != i_end)
88  {
89  STD_VECTOR <LayoutCell *>::const_iterator j = i->begin();
90  while (j != i->end())
91  {
92  LayoutCell *const cell = *j;
93  if ((cell != nullptr) && cell->mType == ARRAY)
94  cell->computeSizes();
95 
96  ++j;
97  }
98  ++i;
99  }
100 
101  mSize[0] = mArray->getSize(0);
102  mSize[1] = mArray->getSize(1);
103 }
int getSize(const int dim) const
int mSize[2]
Definition: layoutcell.h:195
void computeSizes()
Definition: layoutcell.cpp:78
LayoutArray * mArray
Definition: layoutcell.h:181
std::vector< std::vector< LayoutCell *> > mCells
Definition: layoutarray.h:127

◆ extend()

void LayoutCell::extend ( const int  x,
const int  y,
const int  w,
const int  h 
)
See also
LayoutArray::extend.

Definition at line 132 of file layoutcell.cpp.

References LayoutArray::extend(), and getArray().

Referenced by setVAlign(), and TradeWindow::TradeWindow().

134 {
135  getArray().extend(x, y, w, h);
136 }
LayoutArray & getArray()
Definition: layoutcell.cpp:41
void extend(const int x, const int y, const int w, const int h)

◆ getArray()

LayoutArray & LayoutCell::getArray ( )
private

Returns the embedded array. Creates it if the cell does not contain anything yet. Aborts if it contains a widget.

Definition at line 41 of file layoutcell.cpp.

References ARRAY, FILL, LayoutArray, mAlign, mArray, mExtent, mHPadding, mType, mVPadding, tempArray, and WIDGET.

Referenced by at(), extend(), Layout::Layout(), matchColWidth(), place(), setColWidth(), and setRowHeight().

42 {
43  if (mType == WIDGET)
44  return tempArray;
45  if (mType == ARRAY)
46  {
47  if (mArray == nullptr)
48  return tempArray;
49  return *mArray;
50  }
51 
52  mArray = new LayoutArray;
53  mType = ARRAY;
54  mExtent[0] = 1;
55  mExtent[1] = 1;
56  mHPadding = 0;
57  mVPadding = 0;
58  mAlign[0] = FILL;
59  mAlign[1] = FILL;
60  return *mArray;
61 }
int mHPadding
Definition: layoutcell.h:196
int mVPadding
Definition: layoutcell.h:197
friend class LayoutArray
Definition: layoutcell.h:41
int mExtent[2]
Definition: layoutcell.h:198
LayoutArray * mArray
Definition: layoutcell.h:181
Alignment mAlign[2]
Definition: layoutcell.h:199
static LayoutArray tempArray
Definition: layoutcell.cpp:32

◆ getHeight()

int LayoutCell::getHeight ( ) const
inline

Definition at line 139 of file layoutcell.h.

References mExtent.

140  { return mExtent[1]; }
int mExtent[2]
Definition: layoutcell.h:198

◆ getHPadding()

int LayoutCell::getHPadding ( ) const
inline

Definition at line 65 of file layoutcell.h.

References mHPadding.

Referenced by StatsClanTab::updateClan(), and RelationClanTab::updateClan().

66  { return mHPadding; }
int mHPadding
Definition: layoutcell.h:196

◆ getVPadding()

int LayoutCell::getVPadding ( ) const
inline

Definition at line 62 of file layoutcell.h.

References mVPadding.

Referenced by StatsClanTab::updateClan(), and RelationClanTab::updateClan().

63  { return mVPadding; }
int mVPadding
Definition: layoutcell.h:197

◆ getWidth()

int LayoutCell::getWidth ( ) const
inline

Definition at line 136 of file layoutcell.h.

References mExtent.

Referenced by InventoryWindow::widgetResized().

137  { return mExtent[0]; }
int mExtent[2]
Definition: layoutcell.h:198

◆ matchColWidth()

void LayoutCell::matchColWidth ( const int  n1,
const int  n2 
)
See also
LayoutArray::matchColWidth

Definition at line 117 of file layoutcell.cpp.

References getArray(), and LayoutArray::matchColWidth().

Referenced by InfoClanTab::InfoClanTab(), MapDebugTab::MapDebugTab(), NetDebugTab::NetDebugTab(), setVAlign(), and TargetDebugTab::TargetDebugTab().

118 {
119  getArray().matchColWidth(n1, n2);
120 }
LayoutArray & getArray()
Definition: layoutcell.cpp:41
void matchColWidth(const int n1, const int n2)

◆ operator=()

LayoutCell& LayoutCell::operator= ( LayoutCell const &  )
private

Referenced by LayoutCell().

◆ place()

LayoutCell & LayoutCell::place ( Widget *const  wg,
const int  x,
const int  y,
const int  w,
const int  h 
)
See also
LayoutArray::place

Definition at line 110 of file layoutcell.cpp.

References getArray(), and LayoutArray::place().

Referenced by ContainerPlacer::operator()(), LayoutHelper::place(), Window::place(), and setVAlign().

113 {
114  return getArray().place(wg, x, y, w, h);
115 }
LayoutCell & place(Widget *const widget, const int x, const int y, const int w, const int h)
LayoutArray & getArray()
Definition: layoutcell.cpp:41

◆ reflow()

void LayoutCell::reflow ( int  nx,
int  ny,
int  nw,
int  nh 
)
private
See also
LayoutArray::reflow

Definition at line 63 of file layoutcell.cpp.

References ARRAY, mArray, mHPadding, mType, mVPadding, mWidget, NONE, LayoutArray::reflow(), and Widget::setDimension().

Referenced by Layout::reflow(), and LayoutArray::reflow().

64 {
65  if (mType == NONE)
66  return;
67 
68  nx += mHPadding;
69  ny += mVPadding;
70  nw -= 2 * mHPadding;
71  nh -= 2 * mVPadding;
72  if (mType == ARRAY)
73  mArray->reflow(nx, ny, nw, nh);
74  else
75  mWidget->setDimension(Rect(nx, ny, nw, nh));
76 }
int mHPadding
Definition: layoutcell.h:196
Definition: rect.h:72
int mVPadding
Definition: layoutcell.h:197
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
Widget * mWidget
Definition: layoutcell.h:180
void reflow(const int nX, const int nY, const int nW, const int nH)
LayoutArray * mArray
Definition: layoutcell.h:181

◆ setColWidth()

void LayoutCell::setColWidth ( const int  n,
const int  w 
)
See also
LayoutArray::setColWidth

Definition at line 122 of file layoutcell.cpp.

References getArray(), and LayoutArray::setColWidth().

Referenced by OutfitWindow::OutfitWindow(), setVAlign(), and TradeWindow::TradeWindow().

123 {
124  getArray().setColWidth(n, w);
125 }
void setColWidth(const int n, const int w)
Definition: layoutarray.cpp:99
LayoutArray & getArray()
Definition: layoutcell.cpp:41

◆ setHAlign()

LayoutCell& LayoutCell::setHAlign ( const Alignment  a)
inline

Sets the horizontal alignment of the cell content.

Definition at line 83 of file layoutcell.h.

References mAlign.

Referenced by ConnectionDialog::ConnectionDialog(), and LoginDialog::LoginDialog().

84  { mAlign[0] = a; return *this; }
Alignment mAlign[2]
Definition: layoutcell.h:199

◆ setHeight()

void LayoutCell::setHeight ( const int  h)
inline

Definition at line 145 of file layoutcell.h.

References mExtent.

146  { mExtent[1] = h; }
int mExtent[2]
Definition: layoutcell.h:198

◆ setHPadding()

LayoutCell& LayoutCell::setHPadding ( int  p)
inline

Sets the horisontal padding around the cell content.

Definition at line 77 of file layoutcell.h.

References mHPadding.

78  { mHPadding = p; return *this; }
int mHPadding
Definition: layoutcell.h:196

◆ setPadding()

LayoutCell& LayoutCell::setPadding ( int  p)
inline

◆ setRowHeight()

void LayoutCell::setRowHeight ( const int  n,
const int  h 
)

◆ setType()

void LayoutCell::setType ( int  t)
inline

Definition at line 133 of file layoutcell.h.

References mType.

Referenced by InventoryWindow::widgetResized().

134  { mType = t; }

◆ setVAlign()

LayoutCell& LayoutCell::setVAlign ( const Alignment  a)
inline

Sets the vertical alignment of the cell content.

Definition at line 89 of file layoutcell.h.

References A_WARN_UNUSED, at(), computeSizes(), extend(), mAlign, matchColWidth(), place(), setColWidth(), setRowHeight(), x, and y.

90  { mAlign[1] = a; return *this; }
Alignment mAlign[2]
Definition: layoutcell.h:199

◆ setVPadding()

LayoutCell& LayoutCell::setVPadding ( int  p)
inline

Sets the vertical padding around the cell content.

Definition at line 71 of file layoutcell.h.

References mVPadding.

72  { mVPadding = p; return *this; }
int mVPadding
Definition: layoutcell.h:197

◆ setWidth()

void LayoutCell::setWidth ( const int  w)
inline

Definition at line 142 of file layoutcell.h.

References mExtent.

Referenced by InventoryWindow::widgetResized().

143  { mExtent[0] = w; }
int mExtent[2]
Definition: layoutcell.h:198

Friends And Related Function Documentation

◆ Layout

friend class Layout
friend

Definition at line 40 of file layoutcell.h.

◆ LayoutArray

friend class LayoutArray
friend

Definition at line 41 of file layoutcell.h.

Referenced by getArray().

Field Documentation

◆ @8

union { ... }

◆ emptyCell

LayoutCell LayoutCell::emptyCell
static

Definition at line 155 of file layoutcell.h.

Referenced by ContainerPlacer::operator()().

◆ mAlign

Alignment LayoutCell::mAlign[2]
private

Definition at line 199 of file layoutcell.h.

Referenced by getArray(), LayoutCell(), LayoutArray::place(), setHAlign(), and setVAlign().

◆ mArray

LayoutArray* LayoutCell::mArray

Definition at line 181 of file layoutcell.h.

Referenced by computeSizes(), getArray(), reflow(), and ~LayoutCell().

◆ mExtent

int LayoutCell::mExtent[2]
private

◆ mHPadding

int LayoutCell::mHPadding
private

◆ mNbFill

int LayoutCell::mNbFill[2]
private

Definition at line 200 of file layoutcell.h.

Referenced by LayoutCell().

◆ mSize

int LayoutCell::mSize[2]
private

◆ mType

int LayoutCell::mType
private

◆ mVPadding

int LayoutCell::mVPadding
private

◆ mWidget

Widget* LayoutCell::mWidget

Definition at line 180 of file layoutcell.h.

Referenced by LayoutArray::place(), and reflow().


The documentation for this class was generated from the following files: