GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/layoutcell.h Lines: 15 15 100.0 %
Date: 2018-07-14 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-2018  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
200
        { mHPadding = p; mVPadding = p; return *this; }
61
62
        int getVPadding() const
63
        { return mVPadding; }
64
65
        int getHPadding() const
66
        { return mHPadding; }
67
68
        /**
69
         * Sets the vertical padding around the cell content.
70
         */
71
        LayoutCell &setVPadding(int p)
72
        { mVPadding = p; return *this; }
73
74
        /**
75
         * Sets the horisontal padding around the cell content.
76
         */
77
        LayoutCell &setHPadding(int p)
78
        { mHPadding = p; return *this; }
79
80
        /**
81
         * Sets the horizontal alignment of the cell content.
82
         */
83
        LayoutCell &setHAlign(const Alignment a)
84
3
        { mAlign[0] = a; return *this; }
85
86
        /**
87
         * Sets the vertical alignment of the cell content.
88
         */
89
        LayoutCell &setVAlign(const Alignment a)
90
        { mAlign[1] = a; return *this; }
91
92
        /**
93
         * @see LayoutArray::at
94
         */
95
        LayoutCell &at(const int x, const int y) A_WARN_UNUSED;
96
97
        /**
98
         * @see LayoutArray::place
99
         */
100
        LayoutCell &place(Widget *const wg,
101
                          const int x,
102
                          const int y,
103
                          const int w,
104
                          const int h);
105
106
        /**
107
         * @see LayoutArray::matchColWidth
108
         */
109
        void matchColWidth(const int n1, const int n2);
110
111
        /**
112
         * @see LayoutArray::setColWidth
113
         */
114
        void setColWidth(const int n, const int w);
115
116
        /**
117
         * @see LayoutArray::setRowHeight
118
         */
119
        void setRowHeight(const int n, const int h);
120
121
        /**
122
         * @see LayoutArray::extend.
123
         */
124
        void extend(const int x, const int y,
125
                    const int w, const int h);
126
127
        /**
128
         * Sets the minimum widths and heights of this cell and of all the
129
         * inner cells.
130
         */
131
        void computeSizes();
132
133
        void setType(int t)
134
1
        { mType = t; }
135
136
        int getWidth() const noexcept2 A_WARN_UNUSED
137
1
        { return mExtent[0]; }
138
139
        int getHeight() const noexcept2 A_WARN_UNUSED
140
        { return mExtent[1]; }
141
142
        void setWidth(const int w) noexcept2
143
1
        { mExtent[0] = w; }
144
145
        void setHeight(const int h) noexcept2
146
        { mExtent[1] = h; }
147
148
        enum
149
        {
150
            NONE = 0,
151
            WIDGET,
152
            ARRAY
153
        };
154
155
        static LayoutCell emptyCell;
156
157
    private:
158
734
        LayoutCell() :
159
            mWidget(nullptr),
160
            mHPadding(0),
161
            mVPadding(0),
162
734
            mType(NONE)
163
        {
164
734
            mExtent[0] = 0;
165
734
            mExtent[1] = 0;
166
734
            mAlign[0] = LEFT;
167
734
            mAlign[1] = LEFT;
168
734
            mNbFill[0] = 0;
169
734
            mNbFill[1] = 0;
170
734
            mSize[0] = 0;
171
734
            mSize[1] = 0;
172
        }
173
174
        // Copy not allowed, as the cell may own an array.
175
        explicit LayoutCell(LayoutCell const &);
176
        LayoutCell &operator=(LayoutCell const &);
177
178
        union
179
        {
180
            Widget *mWidget;
181
            LayoutArray *mArray;
182
        };
183
184
        /**
185
         * Returns the embedded array. Creates it if the cell does not contain
186
         * anything yet. Aborts if it contains a widget.
187
         */
188
        LayoutArray &getArray();
189
190
        /**
191
         * @see LayoutArray::reflow
192
         */
193
        void reflow(int nx, int ny, int nw, int nh);
194
195
        int mSize[2];
196
        int mHPadding;
197
        int mVPadding;
198
        int mExtent[2];
199
        Alignment mAlign[2];
200
        int mNbFill[2];
201
        int mType;
202
};
203
204
#endif  // GUI_WIDGETS_LAYOUTCELL_H