guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
layout.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/layout.hpp"
24
26{
28 {
29 return _axis;
30 }
31
33 {
34 if (_axis == axis) {
35 return *this;
36 }
37 _axis = axis;
38 setHasChanged(true);
39 return *this;
40 }
41
43 {
44 return _mainAxisAlignment;
45 }
46
48 {
49 if (_mainAxisAlignment == alignment) {
50 return *this;
51 }
52 _mainAxisAlignment = alignment;
53 setHasChanged(true);
54 return *this;
55 }
56
58 {
59 return _crossAxisAlignment;
60 }
61
63 {
64 if (_crossAxisAlignment == alignment) {
65 return *this;
66 }
67 _crossAxisAlignment = alignment;
68 setHasChanged(true);
69 return *this;
70 }
71
72 float Layout::getSpacing(void) const
73 {
74 return _spacing;
75 }
76
77 Layout &Layout::setSpacing(float spacing)
78 {
79 if (_spacing == spacing) {
80 return *this;
81 }
82 _spacing = spacing;
83 setHasChanged(true);
84 return *this;
85 }
86
87 float Layout::getPadding(void) const
88 {
89 return _padding;
90 }
91
92 Layout &Layout::setPadding(float padding)
93 {
94 if (_padding == padding) {
95 return *this;
96 }
97 _padding = padding;
98 setHasChanged(true);
99 return *this;
100 }
101
102 bool Layout::hasFixedWidth(void) const
103 {
104 return _hasFixedWidth;
105 }
106
107 float Layout::getFixedWidth(void) const
108 {
109 return _fixedWidth;
110 }
111
113 {
114 if (_hasFixedWidth && _fixedWidth == width) {
115 return *this;
116 }
117 _hasFixedWidth = true;
118 _fixedWidth = width;
119 setHasChanged(true);
120 return *this;
121 }
122
124 {
125 if (!_hasFixedWidth) {
126 return *this;
127 }
128 _hasFixedWidth = false;
129 _fixedWidth = 0.0f;
130 setHasChanged(true);
131 return *this;
132 }
133
134 bool Layout::hasFixedHeight(void) const
135 {
136 return _hasFixedHeight;
137 }
138
139 float Layout::getFixedHeight(void) const
140 {
141 return _fixedHeight;
142 }
143
145 {
146 if (_hasFixedHeight && _fixedHeight == height) {
147 return *this;
148 }
149 _hasFixedHeight = true;
150 _fixedHeight = height;
151 setHasChanged(true);
152 return *this;
153 }
154
156 {
157 if (!_hasFixedHeight) {
158 return *this;
159 }
160 _hasFixedHeight = false;
161 _fixedHeight = 0.0f;
162 setHasChanged(true);
163 return *this;
164 }
165
166 const std::vector<ecs::Entity::Identifier> &Layout::getChildren(void) const
167 {
168 return _children;
169 }
170
172 const std::vector<ecs::Entity::Identifier> &children)
173 {
174 if (_children == children) {
175 return *this;
176 }
177 _children = children;
178 setHasChanged(true);
179 return *this;
180 }
181
183 {
184 _children.push_back(child);
185 setHasChanged(true);
186 return *this;
187 }
188
190 {
191 if (_children.empty()) {
192 return *this;
193 }
194 _children.clear();
195 setHasChanged(true);
196 return *this;
197 }
198} // namespace guillaume::components
bool hasFixedHeight(void) const
Check whether the container height is forced.
Definition layout.cpp:134
Layout & setFixedWidth(float width)
Force the container width instead of wrapping the children.
Definition layout.cpp:112
CrossAxisAlignment getCrossAxisAlignment(void) const
Get the alignment along the cross axis.
Definition layout.cpp:57
Layout & setChildren(const std::vector< ecs::Entity::Identifier > &children)
Replace the list of children to arrange.
Definition layout.cpp:171
Layout & setAxis(Axis axis)
Choose between a row and a column.
Definition layout.cpp:32
float getSpacing(void) const
Get the gap between two consecutive children.
Definition layout.cpp:72
Layout & setPadding(float padding)
Set the inset between the container's edges and its children.
Definition layout.cpp:92
Layout & setMainAxisAlignment(MainAxisAlignment alignment)
Set where the children go along the main axis.
Definition layout.cpp:47
const std::vector< ecs::Entity::Identifier > & getChildren(void) const
Get the children systems::Layout arranges, in order.
Definition layout.cpp:166
float getPadding(void) const
Get the inset between the container's edges and its children.
Definition layout.cpp:87
Layout(void)=default
Default constructor for the Layout component.
float getFixedWidth(void) const
Get the forced container width.
Definition layout.cpp:107
Layout & clearFixedWidth(void)
Let the width wrap the children again.
Definition layout.cpp:123
CrossAxisAlignment
Where each child goes along the cross axis, inside the padding. In a container that wraps its childre...
Definition layout.hpp:99
Layout & clearFixedHeight(void)
Let the height wrap the children again.
Definition layout.cpp:155
float getFixedHeight(void) const
Get the forced container height.
Definition layout.cpp:139
Layout & clearChildren(void)
Empty the list of children; the entities themselves are left untouched.
Definition layout.cpp:189
Layout & setFixedHeight(float height)
Force the container height instead of wrapping the children.
Definition layout.cpp:144
bool hasFixedWidth(void) const
Check whether the container width is forced.
Definition layout.cpp:102
Layout & addChild(ecs::Entity::Identifier child)
Add a child at the end of the list.
Definition layout.cpp:182
MainAxisAlignment getMainAxisAlignment(void) const
Get the alignment along the main axis.
Definition layout.cpp:42
Layout & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set where each child goes along the cross axis.
Definition layout.cpp:62
MainAxisAlignment
Where the children go along the main axis when the container is larger than them.
Definition layout.hpp:86
Axis getAxis(void) const
Get the main axis.
Definition layout.cpp:27
Axis
Direction along which children are arranged.
Definition layout.hpp:74
Layout & setSpacing(float spacing)
Set the gap between two consecutive children.
Definition layout.cpp:77
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
State. Every class here is plain data attached to an entity.