guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
borders.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "guillaume/components/borders.hpp"
24
25#include <stdexcept>
26
28{
30 : _topLeftRadius(0.0f)
31 , _topRightRadius(0.0f)
32 , _bottomRightRadius(0.0f)
33 , _bottomLeftRadius(0.0f)
34 , _color(0, 0, 0, 0)
35 , _width(0.0f)
36 {
37 }
38
40 {
41 return _topLeftRadius;
42 }
43
45 {
46 if (_topLeftRadius == radius) {
47 return *this;
48 }
49 _topLeftRadius = radius;
50 setHasChanged(true);
51 return *this;
52 }
53
55 {
56 return _topRightRadius;
57 }
58
60 {
61 if (_topRightRadius == radius) {
62 return *this;
63 }
64 _topRightRadius = radius;
65 setHasChanged(true);
66 return *this;
67 }
68
70 {
71 return _bottomRightRadius;
72 }
73
75 {
76 if (_bottomRightRadius == radius) {
77 return *this;
78 }
79 _bottomRightRadius = radius;
80 setHasChanged(true);
81 return *this;
82 }
83
85 {
86 return _bottomLeftRadius;
87 }
88
90 {
91 if (_bottomLeftRadius == radius) {
92 return *this;
93 }
94 _bottomLeftRadius = radius;
95 setHasChanged(true);
96 return *this;
97 }
98
100 {
101 return setTopLeftRadius(radius)
102 .setTopRightRadius(radius)
103 .setBottomRightRadius(radius)
104 .setBottomLeftRadius(radius);
105 }
106
107 Borders &Borders::setColor(const utility::graphic::Color32Bit &color)
108 {
109 if (_color == color) {
110 return *this;
111 }
112 _color = color;
113 setHasChanged(true);
114 return *this;
115 }
116
117 utility::graphic::Color32Bit Borders::getColor(void) const
118 {
119 return _color;
120 }
121
123 {
124 if (width < 0.0f) {
125 throw std::invalid_argument("Border width must be non-negative");
126 }
127 if (_width == width) {
128 return *this;
129 }
130 _width = width;
131 setHasChanged(true);
132 return *this;
133 }
134
135 float Borders::getWidth(void) const
136 {
137 return _width;
138 }
139
140 bool Borders::hasStroke(void) const
141 {
142 return _width > 0.0f && _color.getAlpha() > 0;
143 }
144
145 bool Borders::operator==(const Borders &other) const
146 {
147 if (_topLeftRadius != other._topLeftRadius) {
148 return false;
149 }
150 if (_topRightRadius != other._topRightRadius) {
151 return false;
152 }
153 if (_bottomRightRadius != other._bottomRightRadius) {
154 return false;
155 }
156 if (_bottomLeftRadius != other._bottomLeftRadius) {
157 return false;
158 }
159 if (_color != other._color) {
160 return false;
161 }
162 if (_width != other._width) {
163 return false;
164 }
165 return true;
166 }
167
168 bool Borders::operator!=(const Borders &other) const
169 {
170 return !(*this == other);
171 }
172
173 bool Borders::operator<(const Borders &other) const
174 {
175 if (_topLeftRadius != other._topLeftRadius) {
176 return _topLeftRadius < other._topLeftRadius;
177 }
178 if (_topRightRadius != other._topRightRadius) {
179 return _topRightRadius < other._topRightRadius;
180 }
181 if (_bottomRightRadius != other._bottomRightRadius) {
182 return _bottomRightRadius < other._bottomRightRadius;
183 }
184 if (_bottomLeftRadius != other._bottomLeftRadius) {
185 return _bottomLeftRadius < other._bottomLeftRadius;
186 }
187 if (_color != other._color) {
188 return _color < other._color;
189 }
190 return false;
191 }
192
193 std::ostream &operator<<(std::ostream &stream, const Borders &borders)
194 {
195 stream << "Borders(" << borders.getTopLeftRadius() << ", "
196 << borders.getTopRightRadius() << ", "
197 << borders.getBottomRightRadius() << ", "
198 << borders.getBottomLeftRadius() << ")";
199 return stream;
200 }
201} // namespace guillaume::components
Corner radii and outline stroke of a rectangular entity.
Definition borders.hpp:67
Borders & setWidth(float width)
Set the width of the stroke painted by systems::RectangleRender.
Definition borders.cpp:122
Borders & setTopLeftRadius(BorderRadius radius)
Set the radius of the top-left corner.
Definition borders.cpp:44
BorderRadius getBottomLeftRadius(void) const
Get the radius of the bottom-left corner.
Definition borders.cpp:84
float BorderRadius
A corner radius, in dp.
Definition borders.hpp:69
bool operator!=(const Borders &other) const
Opposite of operator==.
Definition borders.cpp:168
Borders & setBottomLeftRadius(BorderRadius radius)
Set the radius of the bottom-left corner.
Definition borders.cpp:89
float getWidth(void) const
Get the width of the stroke.
Definition borders.cpp:135
Borders & setBorderRadius(BorderRadius radius)
Set the same radius on the four corners.
Definition borders.cpp:99
Borders & setTopRightRadius(BorderRadius radius)
Set the radius of the top-right corner.
Definition borders.cpp:59
bool operator==(const Borders &other) const
Compare the four radii, the stroke color and the stroke width. The changed flag is not compared.
Definition borders.cpp:145
BorderRadius getBottomRightRadius(void) const
Get the radius of the bottom-right corner.
Definition borders.cpp:69
Borders & setColor(const utility::graphic::Color32Bit &color)
Set the color of the stroke.
Definition borders.cpp:107
BorderRadius getTopLeftRadius(void) const
Get the radius of the top-left corner.
Definition borders.cpp:39
Borders & setBottomRightRadius(BorderRadius radius)
Set the radius of the bottom-right corner.
Definition borders.cpp:74
Borders(void)
Construct square corners with no stroke: every radius 0, a transparent color and a width of 0.
Definition borders.cpp:29
utility::graphic::Color32Bit getColor(void) const
Get the color of the stroke.
Definition borders.cpp:117
bool operator<(const Borders &other) const
Order borders so they can be used as a key in an ordered container.
Definition borders.cpp:173
bool hasStroke(void) const
Check whether a visible stroke must be painted.
Definition borders.cpp:140
BorderRadius getTopRightRadius(void) const
Get the radius of the top-right corner.
Definition borders.cpp:54
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.
std::ostream & operator<<(std::ostream &stream, const Borders &borders)
Print the four corner radii, for logs and test failures.
Definition borders.cpp:193