GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/vertcontainer.cpp Lines: 25 31 80.6 %
Date: 2017-11-29 Branches: 9 12 75.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009-2010  The Mana Developers
4
 *  Copyright (C) 2011-2017  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
22
#include "gui/widgets/vertcontainer.h"
23
24
#include "utils/foreach.h"
25
26
#include "debug.h"
27
28
30
VertContainer::VertContainer(const Widget2 *const widget,
29
                             const int verticalItemSize,
30
                             const bool resizable,
31
30
                             const int leftSpacing) :
32
    Container(widget),
33
    WidgetListener(),
34
    mResizableWidgets(),
35
    mVerticalItemSize(verticalItemSize),
36
    mCount(0),
37
    mNextY(0),
38
    mLeftSpacing(leftSpacing),
39
    mVerticalSpacing(0),
40
90
    mResizable(resizable)
41
{
42
30
    addWidgetListener(this);
43
30
}
44
45
706
void VertContainer::add1(Widget *const widget, const int spacing)
46
{
47
706
    add2(widget, mResizable, spacing);
48
706
}
49
50
962
void VertContainer::add2(Widget *const widget, const bool resizable,
51
                         const int spacing)
52
{
53
962
    if (widget == nullptr)
54
        return;
55
56
962
    Container::add(widget);
57
962
    widget->setPosition(mLeftSpacing, mNextY);
58
962
    if (resizable)
59
    {
60
516
        widget->setSize(mDimension.width - mLeftSpacing,
61
258
            mVerticalItemSize * 5);
62
258
        mResizableWidgets.push_back(widget);
63
    }
64
1408
    else if (widget->getHeight() > mVerticalItemSize)
65
    {
66
        widget->setSize(widget->getWidth(), mVerticalItemSize);
67
    }
68
69
962
    if (spacing == -1)
70
706
        mNextY += mVerticalItemSize + (mVerticalSpacing * 2);
71
    else
72
256
        mNextY += mVerticalItemSize + (spacing * 2);
73
962
    setHeight(mNextY);
74
}
75
76
void VertContainer::clear()
77
{
78
    Container::clear();
79
80
    mCount = 0;
81
    mNextY = 0;
82
    mResizableWidgets.clear();
83
}
84
85
962
void VertContainer::widgetResized(const Event &event A_UNUSED)
86
{
87
9862
    FOR_EACH (STD_VECTOR<Widget*>::const_iterator, it, mResizableWidgets)
88
8180
        (*it)->setWidth(getWidth());
89
962
}