ManaPlus
vertcontainer.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009-2010 The Mana Developers
4  * Copyright (C) 2011-2018 The ManaPlus Developers
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
23 
24 #include "utils/foreach.h"
25 
26 #include "debug.h"
27 
29  const int verticalItemSize,
30  const bool resizable,
31  const int leftSpacing) :
32  Container(widget),
34  mResizableWidgets(),
35  mVerticalItemSize(verticalItemSize),
36  mCount(0),
37  mNextY(0),
38  mLeftSpacing(leftSpacing),
39  mVerticalSpacing(0),
40  mResizable(resizable)
41 {
42  addWidgetListener(this);
43 }
44 
45 void VertContainer::add1(Widget *const widget, const int spacing)
46 {
47  add2(widget, mResizable, spacing);
48 }
49 
50 void VertContainer::add2(Widget *const widget, const bool resizable,
51  const int spacing)
52 {
53  if (widget == nullptr)
54  return;
55 
56  Container::add(widget);
58  if (resizable)
59  {
61  mVerticalItemSize * 5);
62  mResizableWidgets.push_back(widget);
63  }
64  else if (widget->getHeight() > mVerticalItemSize)
65  {
66  widget->setSize(widget->getWidth(), mVerticalItemSize);
67  }
68 
69  if (spacing == -1)
71  else
72  mNextY += mVerticalItemSize + (spacing * 2);
73  setHeight(mNextY);
74 }
75 
77 {
79 
80  mCount = 0;
81  mNextY = 0;
82  mResizableWidgets.clear();
83 }
84 
86 {
87  FOR_EACH (STD_VECTOR<Widget*>::const_iterator, it, mResizableWidgets)
88  (*it)->setWidth(getWidth());
89 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
virtual void clear()
void add1(Widget *const widget, const int spacing)
void add2(Widget *const widget, const bool resizable, const int spacing)
void widgetResized(const Event &event)
std::vector< Widget * > mResizableWidgets
Definition: vertcontainer.h:59
VertContainer(const Widget2 *const widget, const int verticalItemSize, const bool resizable, const int leftSpacing)
virtual void add(Widget *const widget)
void setPosition(const int x, const int y)
Definition: widget.cpp:160
void setHeight(const int height)
Definition: widget.cpp:139
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
#define A_UNUSED
Definition: localconsts.h:151
Definition: widget.h:97
Definition: event.h:77
int getHeight() const
Definition: widget.h:239
Rect mDimension
Definition: widget.h:1100