Spacing.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/
27 #ifndef Pt_Forms_Spacing_H
28 #define Pt_Forms_Spacing_H
29 
30 #include <Pt/Forms/Api.h>
31 
32 namespace Pt{
33 namespace Forms{
34 
57 class Spacing
58 {
59  public:
62  Spacing(double all)
63  {
64  set(all);
65  }
66 
69  Spacing(double horizontal, double vertical)
70  {
71  set(horizontal, vertical);
72  }
73 
76  Spacing(double left, double top, double right, double bottom)
77  {
78  set(left, top, right, bottom);
79  }
80 
84  {
85  set( 0, 0, 0, 0);
86  }
87 
90  void set(double value)
91  {
92  set(value, value);
93  }
94 
97  void set(double horizontal, double vertical)
98  {
99  _left = horizontal;
100  _top = vertical;
101  _right = horizontal;
102  _bottom = vertical;
103  }
104 
107  void set(double left, double top, double right, double bottom)
108  {
109  _left = left;
110  _top = top;
111  _right = right;
112  _bottom = bottom;
113  }
114 
117  double left() const
118  {
119  return _left;
120  }
121 
124  void setLeft(double left)
125  {
126  _left = left;
127  }
128 
131  double topBottom() const
132  {
133  return _top + _bottom;
134  }
135 
138  double leftRight() const
139  {
140  return _left + _right;
141  }
142 
145  double top() const
146  {
147  return _top;
148  }
149 
152  void setTop(double top)
153  {
154  _top = top;
155  }
156 
159  double right() const
160  {
161  return _right;
162  }
163 
166  void setRight(double right)
167  {
168  _right = right;
169  }
170 
173  double bottom() const
174  {
175  return _bottom;
176  }
177 
180  void setBottom(double bottom)
181  {
182  _bottom = bottom;
183  }
184 
187  bool operator==(const Spacing& s) const
188  {
189  return (s._left == _left) &&
190  (s._top == _top) &&
191  (s._right == _right) &&
192  (s._bottom == _bottom);
193  }
194 
195  private:
196  double _left;
197  double _top;
198  double _right;
199  double _bottom;
200 };
201 
202 }}
203 
204 #endif
bool operator==(const Spacing &s) const
Returns true when both values compare equal.
Definition: Spacing.h:187
Core module.
Definition: Allocator.h:33
double left() const
Returns the left inset.
Definition: Spacing.h:117
void set(double value)
Sets every side to value.
Definition: Spacing.h:90
double right() const
Returns the right inset.
Definition: Spacing.h:159
double leftRight() const
Returns the sum of the left and right insets.
Definition: Spacing.h:138
double bottom() const
Returns the bottom inset.
Definition: Spacing.h:173
void set(double left, double top, double right, double bottom)
Sets left, top, right, and bottom.
Definition: Spacing.h:107
void setRight(double right)
Sets the right inset to right.
Definition: Spacing.h:166
double top() const
Returns the top inset.
Definition: Spacing.h:145
Spacing(double all)
Creates equal spacing of all on every side.
Definition: Spacing.h:62
Spacing()
Creates zero spacing on every side.
Definition: Spacing.h:83
void setBottom(double bottom)
Sets the bottom inset to bottom.
Definition: Spacing.h:180
void setLeft(double left)
Sets the left inset to left.
Definition: Spacing.h:124
Spacing(double horizontal, double vertical)
Creates spacing of horizontal and vertical.
Definition: Spacing.h:69
void set(double horizontal, double vertical)
Sets left and right to horizontal, top and bottom to vertical.
Definition: Spacing.h:97
Spacing(double left, double top, double right, double bottom)
Creates spacing from left, top, right, and bottom.
Definition: Spacing.h:76
double topBottom() const
Returns the sum of the top and bottom insets.
Definition: Spacing.h:131
Stores four-sided inset values.
Definition: Spacing.h:58
void setTop(double top)
Sets the top inset to top.
Definition: Spacing.h:152