TGUI 1.13
Loading...
Searching...
No Matches
Outline.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_OUTLINE_HPP
26#define TGUI_OUTLINE_HPP
27
28#include <TGUI/AbsoluteOrRelativeValue.hpp>
29#include <TGUI/Vector2.hpp>
30
32
33namespace tgui
34{
36
37 class TGUI_API Outline
38 {
39 public:
45 constexpr Outline(AbsoluteOrRelativeValue size = 0) :
46 m_left{size},
47 m_top{size},
48 m_right{size},
49 m_bottom{size}
50 {
51 }
52
58 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic_v<T>, T>>
59 constexpr Outline(T size) :
60 m_left{size},
61 m_top{size},
62 m_right{size},
63 m_bottom{size}
64 {
65 }
66
74 m_left{width},
75 m_top{height},
76 m_right{width},
77 m_bottom{height}
78 {
79 }
80
89 constexpr Outline(AbsoluteOrRelativeValue leftBorderWidth,
90 AbsoluteOrRelativeValue topBorderHeight,
91 AbsoluteOrRelativeValue rightBorderWidth,
92 AbsoluteOrRelativeValue bottomBorderHeight) :
93 m_left{leftBorderWidth},
94 m_top{topBorderHeight},
95 m_right{rightBorderWidth},
96 m_bottom{bottomBorderHeight}
97 {
98 }
99
105 [[nodiscard]] constexpr float getLeft() const
106 {
107 return m_left.getValue();
108 }
109
115 [[nodiscard]] constexpr float getTop() const
116 {
117 return m_top.getValue();
118 }
119
125 [[nodiscard]] constexpr float getRight() const
126 {
127 return m_right.getValue();
128 }
129
135 [[nodiscard]] constexpr float getBottom() const
136 {
137 return m_bottom.getValue();
138 }
139
144 [[nodiscard]] constexpr Vector2f getOffset() const
145 {
146 return {getLeft(), getTop()};
147 }
148
154 [[nodiscard]] constexpr float getLeftPlusRight() const
155 {
156 return getLeft() + getRight();
157 }
158
164 [[nodiscard]] constexpr float getTopPlusBottom() const
165 {
166 return getTop() + getBottom();
167 }
168
176 [[nodiscard]] constexpr bool operator==(const Outline& outline) const
177 {
178 return (getLeft() == outline.getLeft()) && (getTop() == outline.getTop()) && (getRight() == outline.getRight())
179 && (getBottom() == outline.getBottom());
180 }
181
189 [[nodiscard]] constexpr bool operator!=(const Outline& outline) const
190 {
191 return !(*this == outline);
192 }
193
199 [[nodiscard]] constexpr Outline operator+(const Outline& other) const
200 {
201 return {getLeft() + other.getLeft(),
202 getTop() + other.getTop(),
203 getRight() + other.getRight(),
204 getBottom() + other.getBottom()};
205 }
206
212 [[nodiscard]] constexpr Outline operator-(const Outline& other) const
213 {
214 return {getLeft() - other.getLeft(),
215 getTop() - other.getTop(),
216 getRight() - other.getRight(),
217 getBottom() - other.getBottom()};
218 }
219
225 constexpr Outline& operator+=(const Outline& other)
226 {
227 m_left = getLeft() + other.getLeft();
228 m_top = getTop() + other.getTop();
229 m_right = getRight() + other.getRight();
230 m_bottom = getBottom() + other.getBottom();
231 return *this;
232 }
233
239 constexpr Outline& operator-=(const Outline& other)
240 {
241 m_left = getLeft() - other.getLeft();
242 m_top = getTop() - other.getTop();
243 m_right = getRight() - other.getRight();
244 m_bottom = getBottom() - other.getBottom();
245 return *this;
246 }
247
254 constexpr void updateParentSize(Vector2f newParentSize)
255 {
256 m_left.updateParentSize(newParentSize.x);
257 m_top.updateParentSize(newParentSize.y);
258 m_right.updateParentSize(newParentSize.x);
259 m_bottom.updateParentSize(newParentSize.y);
260 }
261
268 [[nodiscard]] String toString() const
269 {
270 return U"(" + m_left.toString() + U", " + m_top.toString() + U", " + m_right.toString() + U", " + m_bottom.toString()
271 + U")";
272 }
273
275
276 private:
277 AbsoluteOrRelativeValue m_left = 0;
278 AbsoluteOrRelativeValue m_top = 0;
279 AbsoluteOrRelativeValue m_right = 0;
280 AbsoluteOrRelativeValue m_bottom = 0;
281 };
282
284
285 using Borders = Outline;
286 using Padding = Outline;
287} // namespace tgui
288
289#endif // TGUI_OUTLINE_HPP
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:44
Definition Outline.hpp:38
constexpr Outline operator+(const Outline &other) const
Adds two outlines together (e.g. to add padding and borders).
Definition Outline.hpp:199
constexpr bool operator!=(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:189
constexpr Outline & operator-=(const Outline &other)
Subtracts an outline from this instance.
Definition Outline.hpp:239
constexpr Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight)
Constructor that initializes the outline.
Definition Outline.hpp:89
constexpr float getTop() const
Returnes the height of the top outline.
Definition Outline.hpp:115
constexpr Outline(AbsoluteOrRelativeValue width, AbsoluteOrRelativeValue height)
Constructor that initializes the outline.
Definition Outline.hpp:73
constexpr Vector2f getOffset() const
Returnes the width of the left and top outlines.
Definition Outline.hpp:144
constexpr float getRight() const
Returnes the width of the right outline.
Definition Outline.hpp:125
constexpr float getLeftPlusRight() const
Returnes the width of the left and right outlines combined.
Definition Outline.hpp:154
constexpr Outline & operator+=(const Outline &other)
Adds an outline to this instance (e.g. to add padding and borders).
Definition Outline.hpp:225
constexpr Outline(T size)
Constructor that initializes the outline.
Definition Outline.hpp:59
constexpr float getLeft() const
Returnes the width of the left outline.
Definition Outline.hpp:105
constexpr Outline(AbsoluteOrRelativeValue size=0)
Default constructor that initializes the outline.
Definition Outline.hpp:45
constexpr bool operator==(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:176
constexpr float getTopPlusBottom() const
Returnes the height of the top and bottom outlines combined.
Definition Outline.hpp:164
constexpr float getBottom() const
Returnes the height of the bottom outline.
Definition Outline.hpp:135
constexpr Outline operator-(const Outline &other) const
Subtracts two outlines from each other.
Definition Outline.hpp:212
T y
Y coordinate of the vector.
Definition Vector2.hpp:136
T x
X coordinate of the vector.
Definition Vector2.hpp:135
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37