GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/layouthelper.cpp Lines: 17 28 60.7 %
Date: 2017-11-29 Branches: 4 12 33.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
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/layouthelper.h"
24
25
#include "gui/widgets/basiccontainer2.h"
26
#include "gui/widgets/containerplacer.h"
27
28
#include "debug.h"
29
30
82
LayoutHelper::LayoutHelper(BasicContainer2 *const container) :
31
    WidgetListener(),
32
    mLayout(),
33
164
    mContainer(container)
34
{
35
82
    if (mContainer != nullptr)
36
82
        mContainer->addWidgetListener(this);
37
82
}
38
39
246
LayoutHelper::~LayoutHelper()
40
{
41
82
    if (mContainer != nullptr)
42
82
        mContainer->removeWidgetListener(this);
43
82
}
44
45
const Layout &LayoutHelper::getLayout() const
46
{
47
    return mLayout;
48
}
49
50
LayoutCell &LayoutHelper::place(const int x, const int y,
51
                                Widget *const wg,
52
                                const int w, const int h)
53
{
54
    if (mContainer != nullptr)
55
        mContainer->add(wg);
56
    return mLayout.place(wg, x, y, w, h);
57
}
58
59
94
ContainerPlacer LayoutHelper::getPlacer(const int x, const int y)
60
{
61
94
    return ContainerPlacer(mContainer, &mLayout.at(x, y));
62
}
63
64
void LayoutHelper::reflowLayout(int w, int h)
65
{
66
    mLayout.reflow(w, h);
67
    if (mContainer != nullptr)
68
        mContainer->setSize(w, h);
69
}
70
71
118
void LayoutHelper::widgetResized(const Event &event A_UNUSED)
72
{
73
118
    if (mContainer == nullptr)
74
        return;
75
236
    const Rect area = mContainer->getChildrenArea();
76
118
    int w = area.width;
77
118
    int h = area.height;
78
118
    mLayout.reflow(w, h);
79
}