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-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "gui/widgets/layouthelper.h" |
25 |
|
|
|
26 |
|
|
#include "gui/widgets/basiccontainer2.h" |
27 |
|
|
#include "gui/widgets/containerplacer.h" |
28 |
|
|
|
29 |
|
|
#include "debug.h" |
30 |
|
|
|
31 |
|
44 |
LayoutHelper::LayoutHelper(BasicContainer2 *const container) : |
32 |
|
|
WidgetListener(), |
33 |
|
|
mLayout(), |
34 |
|
88 |
mContainer(container) |
35 |
|
|
{ |
36 |
✓✗ |
44 |
if (mContainer != nullptr) |
37 |
✓✗ |
44 |
mContainer->addWidgetListener(this); |
38 |
|
44 |
} |
39 |
|
|
|
40 |
|
132 |
LayoutHelper::~LayoutHelper() |
41 |
|
|
{ |
42 |
✓✗ |
44 |
if (mContainer != nullptr) |
43 |
|
44 |
mContainer->removeWidgetListener(this); |
44 |
|
44 |
} |
45 |
|
|
|
46 |
|
|
const Layout &LayoutHelper::getLayout() const |
47 |
|
|
{ |
48 |
|
|
return mLayout; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
LayoutCell &LayoutHelper::place(const int x, const int y, |
52 |
|
|
Widget *const wg, |
53 |
|
|
const int w, const int h) |
54 |
|
|
{ |
55 |
|
|
if (mContainer != nullptr) |
56 |
|
|
mContainer->add(wg); |
57 |
|
|
return mLayout.place(wg, x, y, w, h); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
50 |
ContainerPlacer LayoutHelper::getPlacer(const int x, const int y) |
61 |
|
|
{ |
62 |
|
50 |
return ContainerPlacer(mContainer, &mLayout.at(x, y)); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void LayoutHelper::reflowLayout(int w, int h) |
66 |
|
|
{ |
67 |
|
|
mLayout.reflow(w, h); |
68 |
|
|
if (mContainer != nullptr) |
69 |
|
|
mContainer->setSize(w, h); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
62 |
void LayoutHelper::widgetResized(const Event &event A_UNUSED) |
73 |
|
|
{ |
74 |
✓✗ |
62 |
if (mContainer == nullptr) |
75 |
|
|
return; |
76 |
|
124 |
const Rect area = mContainer->getChildrenArea(); |
77 |
|
62 |
int w = area.width; |
78 |
|
62 |
int h = area.height; |
79 |
|
62 |
mLayout.reflow(w, h); |
80 |
|
|
} |