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

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
NONE 
WIDGET 
ARRAY 

Definition at line 149 of file layoutcell.h.

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

◆ Alignment

Enumerator
LEFT 
RIGHT 
CENTER 
FILL 

Definition at line 47 of file layoutcell.h.

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

Constructor & Destructor Documentation

◆ ~LayoutCell()

LayoutCell::~LayoutCell ( )
virtual

Definition at line 36 of file layoutcell.cpp.

37 {
38  if (mType == ARRAY)
40 }
LayoutArray * mArray
Definition: layoutcell.h:182
#define delete2(var)
Definition: delete2.h:25

References ARRAY, delete2, mArray, and mType.

◆ LayoutCell() [1/2]

LayoutCell::LayoutCell ( )
inlineprivate

Definition at line 159 of file layoutcell.h.

159  :
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  }
int mExtent[2]
Definition: layoutcell.h:199
int mSize[2]
Definition: layoutcell.h:196
int mNbFill[2]
Definition: layoutcell.h:201
Alignment mAlign[2]
Definition: layoutcell.h:200
int mHPadding
Definition: layoutcell.h:197
Widget * mWidget
Definition: layoutcell.h:181
int mVPadding
Definition: layoutcell.h:198

References LEFT, mAlign, mExtent, mNbFill, and mSize.

◆ 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 106 of file layoutcell.cpp.

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

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

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

◆ computeSizes()

void LayoutCell::computeSizes ( )

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

Definition at line 79 of file layoutcell.cpp.

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

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

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

◆ extend()

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

Definition at line 133 of file layoutcell.cpp.

135 {
136  getArray().extend(x, y, w, h);
137 }
void extend(const int x, const int y, const int w, const int h)

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

Referenced by TradeWindow::TradeWindow().

◆ 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 42 of file layoutcell.cpp.

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

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

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

◆ getHeight()

int LayoutCell::getHeight ( ) const
inline

Definition at line 140 of file layoutcell.h.

141  { return mExtent[1]; }

References mExtent.

◆ getHPadding()

int LayoutCell::getHPadding ( ) const
inline

Definition at line 66 of file layoutcell.h.

67  { return mHPadding; }

References mHPadding.

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

◆ getVPadding()

int LayoutCell::getVPadding ( ) const
inline

Definition at line 63 of file layoutcell.h.

64  { return mVPadding; }

References mVPadding.

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

◆ getWidth()

int LayoutCell::getWidth ( ) const
inline

Definition at line 137 of file layoutcell.h.

138  { return mExtent[0]; }

References mExtent.

Referenced by InventoryWindow::widgetResized().

◆ matchColWidth()

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

Definition at line 118 of file layoutcell.cpp.

119 {
120  getArray().matchColWidth(n1, n2);
121 }
void matchColWidth(const int n1, const int n2)

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

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

◆ operator=()

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

◆ 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 111 of file layoutcell.cpp.

114 {
115  return getArray().place(wg, x, y, w, h);
116 }
LayoutCell & place(Widget *const widget, const int x, const int y, const int w, const int h)

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

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

◆ reflow()

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

Definition at line 64 of file layoutcell.cpp.

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

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

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

◆ setColWidth()

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

Definition at line 123 of file layoutcell.cpp.

124 {
125  getArray().setColWidth(n, w);
126 }
void setColWidth(const int n, const int w)

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

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

◆ setHAlign()

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

Sets the horizontal alignment of the cell content.

Definition at line 84 of file layoutcell.h.

85  { mAlign[0] = a; return *this; }

References mAlign.

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

◆ setHeight()

void LayoutCell::setHeight ( const int  h)
inline

Definition at line 146 of file layoutcell.h.

147  { mExtent[1] = h; }

References mExtent.

◆ setHPadding()

LayoutCell& LayoutCell::setHPadding ( int  p)
inline

Sets the horisontal padding around the cell content.

Definition at line 78 of file layoutcell.h.

79  { mHPadding = p; return *this; }

References mHPadding.

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

135  { mType = t; }

References mType.

Referenced by InventoryWindow::widgetResized().

◆ setVAlign()

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

Sets the vertical alignment of the cell content.

Definition at line 90 of file layoutcell.h.

91  { mAlign[1] = a; return *this; }

References mAlign.

◆ setVPadding()

LayoutCell& LayoutCell::setVPadding ( int  p)
inline

Sets the vertical padding around the cell content.

Definition at line 72 of file layoutcell.h.

73  { mVPadding = p; return *this; }

References mVPadding.

◆ setWidth()

void LayoutCell::setWidth ( const int  w)
inline

Definition at line 143 of file layoutcell.h.

144  { mExtent[0] = w; }

References mExtent.

Referenced by InventoryWindow::widgetResized().

Friends And Related Function Documentation

◆ Layout

friend class Layout
friend

Definition at line 41 of file layoutcell.h.

◆ LayoutArray

friend class LayoutArray
friend

Definition at line 42 of file layoutcell.h.

Referenced by getArray().

Field Documentation

◆ 

union { ... }

◆ emptyCell

LayoutCell LayoutCell::emptyCell
static

Definition at line 156 of file layoutcell.h.

Referenced by ContainerPlacer::operator()().

◆ mAlign

Alignment LayoutCell::mAlign[2]
private

Definition at line 200 of file layoutcell.h.

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

◆ mArray

LayoutArray* LayoutCell::mArray

Definition at line 182 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 201 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 181 of file layoutcell.h.

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


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