guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
layout.hpp
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#pragma once
24
25#include <vector>
26
27#include "guillaume/ecs/component.hpp"
28#include "guillaume/ecs/entity.hpp"
29
31{
32
68 class Layout: public ecs::Component
69 {
70 public:
74 enum class Axis {
77 };
78
93
104
105 private:
106 Axis _axis { Axis::Horizontal };
107 MainAxisAlignment _mainAxisAlignment {
109 };
110
111 CrossAxisAlignment _crossAxisAlignment {
113 };
114
115 float _spacing { 0.0f };
116 float _padding { 0.0f };
117 bool _hasFixedWidth { false };
118 bool _hasFixedHeight { false };
119 float _fixedWidth { 0.0f };
120 float _fixedHeight { 0.0f };
121 std::vector<ecs::Entity::Identifier>
122 _children {};
123
124 public:
128 Layout(void) = default;
129
133 ~Layout(void) = default;
134
140 Axis getAxis(void) const;
141
150 Layout &setAxis(Axis axis);
151
157
168
174
184
189 float getSpacing(void) const;
190
200 Layout &setSpacing(float spacing);
201
208 float getPadding(void) const;
209
219 Layout &setPadding(float padding);
220
226 bool hasFixedWidth(void) const;
227
233 float getFixedWidth(void) const;
234
248 Layout &setFixedWidth(float width);
249
257 Layout &clearFixedWidth(void);
258
264 bool hasFixedHeight(void) const;
265
271 float getFixedHeight(void) const;
272
285 Layout &setFixedHeight(float height);
286
295
305 const std::vector<ecs::Entity::Identifier> &getChildren(void) const;
306
316 Layout &
317 setChildren(const std::vector<ecs::Entity::Identifier> &children);
318
329
338 Layout &clearChildren(void);
339 };
340
341} // 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
~Layout(void)=default
Default destructor for the Layout component.
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
@ End
Packed at the right (row) or bottom (column).
Definition layout.hpp:89
@ Start
Packed at the left (row) or top (column).
Definition layout.hpp:87
Axis getAxis(void) const
Get the main axis.
Definition layout.cpp:27
Axis
Direction along which children are arranged.
Definition layout.hpp:74
@ Vertical
Column: children placed top to bottom.
Definition layout.hpp:76
@ Horizontal
Row: children placed left to right.
Definition layout.hpp:75
Layout & setSpacing(float spacing)
Set the gap between two consecutive children.
Definition layout.cpp:77
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
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.