GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/layoutcell.h Lines: 15 15 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2007-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
#ifndef GUI_WIDGETS_LAYOUTCELL_H
24
#define GUI_WIDGETS_LAYOUTCELL_H
25
26
#include "localconsts.h"
27
28
class LayoutArray;
29
class Widget;
30
31
/**
32
 * This class describes the formatting of a widget in the cell of a layout
33
 * table. Horizontally, a widget can either fill the width of the cell (minus
34
 * the cell padding), or it can retain its size and be flushed left, or flush
35
 * right, or centered in the cell. The process is similar for the vertical
36
 * alignment, except that top is represented by LEFT and bottom by RIGHT.
37
 */
38
class LayoutCell notfinal
39
{
40
    friend class Layout;
41
    friend class LayoutArray;
42
43
    public:
44
        A_DEFAULT_COPY(LayoutCell)
45
46
        enum Alignment
47
        {
48
            LEFT = 0,
49
            RIGHT,
50
            CENTER,
51
            FILL
52
        };
53
54
        virtual ~LayoutCell();
55
56
        /**
57
         * Sets the padding around the cell content.
58
         */
59
        LayoutCell &setPadding(int p)
60
398
        { mHPadding = p; mVPadding = p; return *this; }
61
62
        /**
63
         * Sets the vertical padding around the cell content.
64
         */
65
        LayoutCell &setVPadding(int p)
66
        { mVPadding = p; return *this; }
67
68
        /**
69
         * Sets the horisontal padding around the cell content.
70
         */
71
        LayoutCell &setHPadding(int p)
72
        { mHPadding = p; return *this; }
73
74
        /**
75
         * Sets the horizontal alignment of the cell content.
76
         */
77
        LayoutCell &setHAlign(const Alignment a)
78
6
        { mAlign[0] = a; return *this; }
79
80
        /**
81
         * Sets the vertical alignment of the cell content.
82
         */
83
        LayoutCell &setVAlign(const Alignment a)
84
        { mAlign[1] = a; return *this; }
85
86
        /**
87
         * @see LayoutArray::at
88
         */
89
        LayoutCell &at(const int x, const int y) A_WARN_UNUSED;
90
91
        /**
92
         * @see LayoutArray::place
93
         */
94
        LayoutCell &place(Widget *const wg,
95
                          const int x, const int y,
96
                          const int w = 1, const int h = 1);
97
98
        /**
99
         * @see LayoutArray::matchColWidth
100
         */
101
        void matchColWidth(const int n1, const int n2);
102
103
        /**
104
         * @see LayoutArray::setColWidth
105
         */
106
        void setColWidth(const int n, const int w);
107
108
        /**
109
         * @see LayoutArray::setRowHeight
110
         */
111
        void setRowHeight(const int n, const int h);
112
113
        /**
114
         * @see LayoutArray::extend.
115
         */
116
        void extend(const int x, const int y,
117
                    const int w, const int h);
118
119
        /**
120
         * Sets the minimum widths and heights of this cell and of all the
121
         * inner cells.
122
         */
123
        void computeSizes();
124
125
        void setType(int t)
126
2
        { mType = t; }
127
128
        int getWidth() const noexcept2 A_WARN_UNUSED
129
2
        { return mExtent[0]; }
130
131
        int getHeight() const noexcept2 A_WARN_UNUSED
132
        { return mExtent[1]; }
133
134
        void setWidth(const int w) noexcept2
135
2
        { mExtent[0] = w; }
136
137
        void setHeight(const int h) noexcept2
138
        { mExtent[1] = h; }
139
140
        enum
141
        {
142
            NONE = 0,
143
            WIDGET,
144
            ARRAY
145
        };
146
147
        static LayoutCell emptyCell;
148
149
    private:
150
1452
        LayoutCell() :
151
            mWidget(nullptr),
152
            mHPadding(0),
153
            mVPadding(0),
154
1452
            mType(NONE)
155
        {
156
1452
            mExtent[0] = 0;
157
1452
            mExtent[1] = 0;
158
1452
            mAlign[0] = LEFT;
159
1452
            mAlign[1] = LEFT;
160
1452
            mNbFill[0] = 0;
161
1452
            mNbFill[1] = 0;
162
1452
            mSize[0] = 0;
163
1452
            mSize[1] = 0;
164
        }
165
166
        // Copy not allowed, as the cell may own an array.
167
        explicit LayoutCell(LayoutCell const &);
168
        LayoutCell &operator=(LayoutCell const &);
169
170
        union
171
        {
172
            Widget *mWidget;
173
            LayoutArray *mArray;
174
        };
175
176
        /**
177
         * Returns the embedded array. Creates it if the cell does not contain
178
         * anything yet. Aborts if it contains a widget.
179
         */
180
        LayoutArray &getArray();
181
182
        /**
183
         * @see LayoutArray::reflow
184
         */
185
        void reflow(int nx, int ny, int nw, int nh);
186
187
        int mSize[2];
188
        int mHPadding;
189
        int mVPadding;
190
        int mExtent[2];
191
        Alignment mAlign[2];
192
        int mNbFill[2];
193
        int mType;
194
};
195
196
#endif  // GUI_WIDGETS_LAYOUTCELL_H