GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/vertcontainer.cpp Lines: 25 31 80.6 %
Date: 2021-03-17 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-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
23
#include "gui/widgets/vertcontainer.h"
24
25
#include "utils/foreach.h"
26
27
#include "debug.h"
28
29
15
VertContainer::VertContainer(const Widget2 *const widget,
30
                             const int verticalItemSize,
31
                             const bool resizable,
32
15
                             const int leftSpacing) :
33
    Container(widget),
34
    WidgetListener(),
35
    mResizableWidgets(),
36
    mVerticalItemSize(verticalItemSize),
37
    mCount(0),
38
    mNextY(0),
39
    mLeftSpacing(leftSpacing),
40
    mVerticalSpacing(0),
41
45
    mResizable(resizable)
42
{
43
15
    addWidgetListener(this);
44
15
}
45
46
349
void VertContainer::add1(Widget *const widget, const int spacing)
47
{
48
349
    add2(widget, mResizable, spacing);
49
349
}
50
51
487
void VertContainer::add2(Widget *const widget, const bool resizable,
52
                         const int spacing)
53
{
54
487
    if (widget == nullptr)
55
        return;
56
57
487
    Container::add(widget);
58
487
    widget->setPosition(mLeftSpacing, mNextY);
59
487
    if (resizable)
60
    {
61
139
        widget->setSize(mDimension.width - mLeftSpacing,
62
278
            mVerticalItemSize * 5);
63
139
        mResizableWidgets.push_back(widget);
64
    }
65
696
    else if (widget->getHeight() > mVerticalItemSize)
66
    {
67
        widget->setSize(widget->getWidth(), mVerticalItemSize);
68
    }
69
70
487
    if (spacing == -1)
71
349
        mNextY += mVerticalItemSize + (mVerticalSpacing * 2);
72
    else
73
138
        mNextY += mVerticalItemSize + (spacing * 2);
74
487
    setHeight(mNextY);
75
}
76
77
void VertContainer::clear()
78
{
79
    Container::clear();
80
81
    mCount = 0;
82
    mNextY = 0;
83
    mResizableWidgets.clear();
84
}
85
86
487
void VertContainer::widgetResized(const Event &event A_UNUSED)
87
{
88
5271
    FOR_EACH (STD_VECTOR<Widget*>::const_iterator, it, mResizableWidgets)
89
4698
        (*it)->setWidth(getWidth());
90
487
}