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)
 
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=1, const int h=1)
 
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 140 of file layoutcell.h.

141  {
142  NONE = 0,
143  WIDGET,
144  ARRAY
145  };

◆ 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:173

◆ LayoutCell() [1/2]

LayoutCell::LayoutCell ( )
inlineprivate

Definition at line 150 of file layoutcell.h.

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

150  :
151  mWidget(nullptr),
152  mHPadding(0),
153  mVPadding(0),
154  mType(NONE)
155  {
156  mExtent[0] = 0;
157  mExtent[1] = 0;
158  mAlign[0] = LEFT;
159  mAlign[1] = LEFT;
160  mNbFill[0] = 0;
161  mNbFill[1] = 0;
162  mSize[0] = 0;
163  mSize[1] = 0;
164  }
int mHPadding
Definition: layoutcell.h:188
int mVPadding
Definition: layoutcell.h:189
int mNbFill[2]
Definition: layoutcell.h:192
Widget * mWidget
Definition: layoutcell.h:172
int mSize[2]
Definition: layoutcell.h:187
int mExtent[2]
Definition: layoutcell.h:190
Alignment mAlign[2]
Definition: layoutcell.h:191

◆ 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);
108 }
LayoutCell & at(const int x, const int y, const int w=1, const int h=1)
Definition: layoutarray.cpp:59
LayoutArray & getArray()
Definition: layoutcell.cpp:41

◆ 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:187
void computeSizes()
Definition: layoutcell.cpp:78
LayoutArray * mArray
Definition: layoutcell.h:173
std::vector< std::vector< LayoutCell *> > mCells
Definition: layoutarray.h:122

◆ 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:188
int mVPadding
Definition: layoutcell.h:189
friend class LayoutArray
Definition: layoutcell.h:41
int mExtent[2]
Definition: layoutcell.h:190
LayoutArray * mArray
Definition: layoutcell.h:173
Alignment mAlign[2]
Definition: layoutcell.h:191
static LayoutArray tempArray
Definition: layoutcell.cpp:32

◆ getHeight()

int LayoutCell::getHeight ( ) const
inline

Definition at line 131 of file layoutcell.h.

References mExtent.

132  { return mExtent[1]; }
int mExtent[2]
Definition: layoutcell.h:190

◆ getWidth()

int LayoutCell::getWidth ( ) const
inline

Definition at line 128 of file layoutcell.h.

References mExtent.

Referenced by InventoryWindow::widgetResized().

129  { return mExtent[0]; }
int mExtent[2]
Definition: layoutcell.h:190

◆ 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 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 = 1,
const int  h = 1 
)
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 }
LayoutArray & getArray()
Definition: layoutcell.cpp:41
LayoutCell & place(Widget *const widget, const int x, const int y, const int w=1, const int h=1)

◆ 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:188
Definition: rect.h:72
int mVPadding
Definition: layoutcell.h:189
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
Widget * mWidget
Definition: layoutcell.h:172
void reflow(const int nX, const int nY, const int nW, const int nH)
LayoutArray * mArray
Definition: layoutcell.h:173

◆ 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 77 of file layoutcell.h.

References mAlign.

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

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

◆ setHeight()

void LayoutCell::setHeight ( const int  h)
inline

Definition at line 137 of file layoutcell.h.

References mExtent.

138  { mExtent[1] = h; }
int mExtent[2]
Definition: layoutcell.h:190

◆ setHPadding()

LayoutCell& LayoutCell::setHPadding ( int  p)
inline

Sets the horisontal padding around the cell content.

Definition at line 71 of file layoutcell.h.

References mHPadding.

72  { mHPadding = p; return *this; }
int mHPadding
Definition: layoutcell.h:188

◆ 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 125 of file layoutcell.h.

References mType.

Referenced by InventoryWindow::widgetResized().

126  { mType = t; }

◆ setVAlign()

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

Sets the vertical alignment of the cell content.

Definition at line 83 of file layoutcell.h.

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

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

◆ setVPadding()

LayoutCell& LayoutCell::setVPadding ( int  p)
inline

Sets the vertical padding around the cell content.

Definition at line 65 of file layoutcell.h.

References mVPadding.

66  { mVPadding = p; return *this; }
int mVPadding
Definition: layoutcell.h:189

◆ setWidth()

void LayoutCell::setWidth ( const int  w)
inline

Definition at line 134 of file layoutcell.h.

References mExtent.

Referenced by InventoryWindow::widgetResized().

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

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 147 of file layoutcell.h.

Referenced by ContainerPlacer::operator()().

◆ mAlign

Alignment LayoutCell::mAlign[2]
private

Definition at line 191 of file layoutcell.h.

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

◆ mArray

LayoutArray* LayoutCell::mArray

Definition at line 173 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 192 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 172 of file layoutcell.h.

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


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