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