TGUI  1.4.0
Loading...
Searching...
No Matches
RelFloatRect.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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_REL_FLOAT_RECT_HPP
26#define TGUI_REL_FLOAT_RECT_HPP
27
28#include <TGUI/AbsoluteOrRelativeValue.hpp>
29#include <TGUI/Rect.hpp>
30
32
33TGUI_MODULE_EXPORT namespace tgui
34{
38 struct TGUI_API RelFloatRect
39 {
43 constexpr RelFloatRect() = default;
44
55 m_left{left},
56 m_top{top},
57 m_width{width},
58 m_height{height}
59 {
60 }
61
65 TGUI_NODISCARD constexpr float getLeft() const
66 {
67 return m_left.getValue();
68 }
69
73 TGUI_NODISCARD constexpr float getTop() const
74 {
75 return m_top.getValue();
76 }
77
81 TGUI_NODISCARD constexpr float getWidth() const
82 {
83 return m_width.getValue();
84 }
85
89 TGUI_NODISCARD constexpr float getHeight() const
90 {
91 return m_height.getValue();
92 }
93
97 TGUI_NODISCARD constexpr Vector2f getPosition() const
98 {
99 return {m_left.getValue(), m_top.getValue()};
100 }
101
105 TGUI_NODISCARD constexpr Vector2f getSize() const
106 {
107 return {m_width.getValue(), m_height.getValue()};
108 }
109
113 TGUI_NODISCARD constexpr FloatRect getRect() const
114 {
115 return {m_left.getValue(), m_top.getValue(), m_width.getValue(), m_height.getValue()};
116 }
117
124 constexpr void updateParentSize(Vector2f newParentSize)
125 {
126 m_left.updateParentSize(newParentSize.x);
127 m_top.updateParentSize(newParentSize.y);
128 m_width.updateParentSize(newParentSize.x);
129 m_height.updateParentSize(newParentSize.y);
130 }
131
133 private:
134
135 AbsoluteOrRelativeValue m_left;
136 AbsoluteOrRelativeValue m_top;
137 AbsoluteOrRelativeValue m_width;
138 AbsoluteOrRelativeValue m_height;
139 };
140}
141
143
144#endif // TGUI_REL_FLOAT_RECT_HPP
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:45
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:38
FloatRect that can contain absolute values or values relative to the parent size.
Definition RelFloatRect.hpp:39
constexpr RelFloatRect()=default
Default constructor.
TGUI_NODISCARD constexpr FloatRect getRect() const
Returns the the rectangle as an absolute value.
Definition RelFloatRect.hpp:113
TGUI_NODISCARD constexpr Vector2f getPosition() const
Returns the size of the rect as an absolute value.
Definition RelFloatRect.hpp:97
TGUI_NODISCARD constexpr float getHeight() const
Returns the height of the rect as an absolute value.
Definition RelFloatRect.hpp:89
TGUI_NODISCARD constexpr float getLeft() const
Returns the left position of the rect as an absolute value.
Definition RelFloatRect.hpp:65
TGUI_NODISCARD constexpr float getWidth() const
Returns the width of the rect as an absolute value.
Definition RelFloatRect.hpp:81
constexpr RelFloatRect(AbsoluteOrRelativeValue left, AbsoluteOrRelativeValue top, AbsoluteOrRelativeValue width, AbsoluteOrRelativeValue height)
Constructs the rectangle from its position and size.
Definition RelFloatRect.hpp:53
TGUI_NODISCARD constexpr float getTop() const
Returns the top position of the rect as an absolute value.
Definition RelFloatRect.hpp:73
TGUI_NODISCARD constexpr Vector2f getSize() const
Returns the size of the rect as an absolute value.
Definition RelFloatRect.hpp:105