Mana
Loading...
Searching...
No Matches
src
gui
widgets
flowcontainer.cpp
Go to the documentation of this file.
1
/*
2
* The Mana Client
3
* Copyright (C) 2009-2012 The Mana Developers
4
*
5
* This file is part of The Mana Client.
6
*
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*/
20
21
#include "
flowcontainer.h
"
22
23
FlowContainer::FlowContainer
(
int
boxWidth,
int
boxHeight):
24
mBoxWidth(boxWidth),
25
mBoxHeight(boxHeight)
26
{
27
addWidgetListener(
this
);
28
}
29
30
void
FlowContainer::widgetResized
(
const
gcn::Event &event)
31
{
32
if
(getWidth() <
mBoxWidth
)
33
{
34
setWidth(
mBoxWidth
);
35
return
;
36
}
37
38
int
itemCount = mWidgets.size();
39
40
mGridWidth
= getWidth() /
mBoxWidth
;
41
42
if
(
mGridWidth
< 1)
43
mGridWidth
= 1;
44
45
mGridHeight
= itemCount /
mGridWidth
;
46
47
if
(itemCount %
mGridWidth
!= 0 ||
mGridHeight
< 1)
48
++
mGridHeight
;
49
50
int
height =
mGridHeight
*
mBoxHeight
;
51
52
if
(getHeight() != height)
53
{
54
setHeight(height);
55
return
;
56
}
57
58
int
i = 0;
59
height = 0;
60
for
(
auto
&widget : mWidgets)
61
{
62
int
x = i %
mGridWidth
*
mBoxWidth
;
63
widget->setPosition(x, height);
64
65
i++;
66
67
if
(i %
mGridWidth
== 0)
68
height +=
mBoxHeight
;
69
}
70
}
71
72
void
FlowContainer::add
(gcn::Widget *widget)
73
{
74
Container::add(widget);
75
widget->setSize(
mBoxWidth
,
mBoxHeight
);
76
widgetResized
(
nullptr
);
77
}
FlowContainer::add
void add(gcn::Widget *widget) override
Definition
flowcontainer.cpp:72
FlowContainer::mBoxHeight
int mBoxHeight
Definition
flowcontainer.h:54
FlowContainer::mGridWidth
int mGridWidth
Definition
flowcontainer.h:55
FlowContainer::mBoxWidth
int mBoxWidth
Definition
flowcontainer.h:53
FlowContainer::mGridHeight
int mGridHeight
Definition
flowcontainer.h:56
FlowContainer::FlowContainer
FlowContainer(int boxWidth, int boxHeight)
Definition
flowcontainer.cpp:23
FlowContainer::widgetResized
void widgetResized(const gcn::Event &event) override
Invoked when a widget changes its size.
Definition
flowcontainer.cpp:30
flowcontainer.h
Generated by
1.9.8