ManaPlus
layouthelper.cpp
Go to the documentation of this file.
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 
25 
28 
29 #include "debug.h"
30 
33  mLayout(),
34  mContainer(container)
35 {
36  if (mContainer != nullptr)
38 }
39 
41 {
42  if (mContainer != nullptr)
44 }
45 
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 
61 {
62  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 
73 {
74  if (mContainer == nullptr)
75  return;
76  const Rect area = mContainer->getChildrenArea();
77  int w = area.width;
78  int h = area.height;
79  mLayout.reflow(w, h);
80 }
virtual void add(Widget *const widget)
Definition: event.h:79
LayoutCell & place(Widget *const wg, const int x, const int y, const int w, const int h)
Definition: layoutcell.cpp:111
LayoutCell & at(const int x, const int y)
Definition: layoutcell.cpp:106
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
void widgetResized(const Event &event)
LayoutHelper(BasicContainer2 *const container)
Layout mLayout
Definition: layouthelper.h:92
ContainerPlacer getPlacer(const int x, const int y)
BasicContainer2 * mContainer
Definition: layouthelper.h:93
const Layout & getLayout() const A_CONST
void reflowLayout(int w, int h)
Definition: layout.h:45
void reflow(int &nW, int &nH)
Definition: layout.cpp:36
Definition: rect.h:74
int width
Definition: rect.h:219
int height
Definition: rect.h:224
Definition: widget.h:99
void setSize(const int width, const int height)
Definition: widget.cpp:367
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:307
#define A_UNUSED
Definition: localconsts.h:160