TGUI 1.11
Loading...
Searching...
No Matches
Outline.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 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/Vector2.hpp>
29#include <TGUI/AbsoluteOrRelativeValue.hpp>
30
32
33namespace tgui
34{
36
37 class TGUI_API Outline
38 {
39 public:
40
46 constexpr Outline(AbsoluteOrRelativeValue size = 0) :
47 m_left {size},
48 m_top {size},
49 m_right {size},
50 m_bottom{size}
51 {
52 }
53
59 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic<T>::value, T>>
60 constexpr Outline(T size) :
61 m_left {size},
62 m_top {size},
63 m_right {size},
64 m_bottom{size}
65 {
66 }
67
75 m_left {width},
76 m_top {height},
77 m_right {width},
78 m_bottom{height}
79 {
80 }
81
90 constexpr Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight) :
91 m_left {leftBorderWidth},
92 m_top {topBorderHeight},
93 m_right {rightBorderWidth},
94 m_bottom{bottomBorderHeight}
95 {
96 }
97
103 TGUI_NODISCARD constexpr float getLeft() const
104 {
105 return m_left.getValue();
106 }
107
113 TGUI_NODISCARD constexpr float getTop() const
114 {
115 return m_top.getValue();
116 }
117
123 TGUI_NODISCARD constexpr float getRight() const
124 {
125 return m_right.getValue();
126 }
127
133 TGUI_NODISCARD constexpr float getBottom() const
134 {
135 return m_bottom.getValue();
136 }
137
142 TGUI_NODISCARD constexpr Vector2f getOffset() const
143 {
144 return {getLeft(), getTop()};
145 }
146
152 TGUI_NODISCARD constexpr float getLeftPlusRight() const
153 {
154 return getLeft() + getRight();
155 }
156
162 TGUI_NODISCARD constexpr float getTopPlusBottom() const
163 {
164 return getTop() + getBottom();
165 }
166
174 TGUI_NODISCARD constexpr bool operator==(const Outline& outline) const
175 {
176 return (getLeft() == outline.getLeft()) && (getTop() == outline.getTop()) && (getRight() == outline.getRight()) && (getBottom() == outline.getBottom());
177 }
178
186 TGUI_NODISCARD constexpr bool operator!=(const Outline& outline) const
187 {
188 return !(*this == outline);
189 }
190
196 TGUI_NODISCARD constexpr Outline operator+(const Outline& other) const
197 {
198 return {getLeft() + other.getLeft(),
199 getTop() + other.getTop(),
200 getRight() + other.getRight(),
201 getBottom() + other.getBottom()};
202 }
203
209 TGUI_NODISCARD constexpr Outline operator-(const Outline& other) const
210 {
211 return {getLeft() - other.getLeft(),
212 getTop() - other.getTop(),
213 getRight() - other.getRight(),
214 getBottom() - other.getBottom()};
215 }
216
222 constexpr Outline& operator+=(const Outline& other)
223 {
224 m_left = getLeft() + other.getLeft();
225 m_top = getTop() + other.getTop();
226 m_right = getRight() + other.getRight();
227 m_bottom = getBottom() + other.getBottom();
228 return *this;
229 }
230
236 constexpr Outline& operator-=(const Outline& other)
237 {
238 m_left = getLeft() - other.getLeft();
239 m_top = getTop() - other.getTop();
240 m_right = getRight() - other.getRight();
241 m_bottom = getBottom() - other.getBottom();
242 return *this;
243 }
244
251 constexpr void updateParentSize(Vector2f newParentSize)
252 {
253 m_left.updateParentSize(newParentSize.x);
254 m_top.updateParentSize(newParentSize.y);
255 m_right.updateParentSize(newParentSize.x);
256 m_bottom.updateParentSize(newParentSize.y);
257 }
258
265 TGUI_NODISCARD String toString() const
266 {
267 return U"(" + m_left.toString() + U", " + m_top.toString() + U", " + m_right.toString() + U", " + m_bottom.toString() + U")";
268 }
269
271 private:
272
273 AbsoluteOrRelativeValue m_left = 0;
274 AbsoluteOrRelativeValue m_top = 0;
275 AbsoluteOrRelativeValue m_right = 0;
276 AbsoluteOrRelativeValue m_bottom = 0;
277 };
278
280
281 using Borders = Outline;
282 using Padding = Outline;
283
285}
286
288
289#endif // TGUI_OUTLINE_HPP
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:43
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:196
constexpr bool operator!=(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:186
constexpr Outline & operator-=(const Outline &other)
Subtracts an outline from this instance.
Definition Outline.hpp:236
constexpr Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight)
Constructor that initializes the outline.
Definition Outline.hpp:90
constexpr float getTop() const
Returnes the height of the top outline.
Definition Outline.hpp:113
constexpr Outline(AbsoluteOrRelativeValue width, AbsoluteOrRelativeValue height)
Constructor that initializes the outline.
Definition Outline.hpp:74
constexpr Vector2f getOffset() const
Returnes the width of the left and top outlines.
Definition Outline.hpp:142
constexpr float getRight() const
Returnes the width of the right outline.
Definition Outline.hpp:123
constexpr float getLeftPlusRight() const
Returnes the width of the left and right outlines combined.
Definition Outline.hpp:152
constexpr Outline & operator+=(const Outline &other)
Adds an outline to this instance (e.g. to add padding and borders)
Definition Outline.hpp:222
constexpr Outline(T size)
Constructor that initializes the outline.
Definition Outline.hpp:60
constexpr float getLeft() const
Returnes the width of the left outline.
Definition Outline.hpp:103
constexpr Outline(AbsoluteOrRelativeValue size=0)
Default constructor that initializes the outline.
Definition Outline.hpp:46
constexpr bool operator==(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:174
constexpr float getTopPlusBottom() const
Returnes the height of the top and bottom outlines combined.
Definition Outline.hpp:162
constexpr float getBottom() const
Returnes the height of the bottom outline.
Definition Outline.hpp:133
constexpr Outline operator-(const Outline &other) const
Subtracts two outlines from each other.
Definition Outline.hpp:209
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:36