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