guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
view.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 <utility>
26#include <cstdint>
27#include <memory>
28#include <vector>
29
30#include <utility/graphic/color.hpp>
31
32#include "guillaume/ecs/component_registry.hpp"
33#include "guillaume/entities/builder_base.hpp"
34#include "guillaume/ecs/entity.hpp"
35#include "guillaume/ecs/entity_builder.hpp"
36#include "guillaume/ecs/parent_entity_filler.hpp"
37
38#include "guillaume/components/borders.hpp"
39#include "guillaume/components/bound.hpp"
40#include "guillaume/components/color.hpp"
41#include "guillaume/components/layout.hpp"
42#include "guillaume/components/transform.hpp"
43
44namespace guillaume::entities
45{
46
98 class View:
99 public std::enable_shared_from_this<View>,
100 public ecs::ParentEntityFiller<components::Layout,
101 components::Transform, components::Bound,
102 components::Color, components::Borders>
103 {
104 public:
112
117 class Builder: public EntityBuilderBase<View>
118 {
119 private:
120 utility::graphic::PoseF _pose;
121 utility::graphic::Color32Bit _color;
122 float _borderRadius;
123 Axis _axis;
124 MainAxisAlignment _mainAxisAlignment;
126 _crossAxisAlignment;
127 float _spacing;
128 float _padding;
129 bool _hasFixedWidth;
130 bool _hasFixedHeight;
131 float _fixedWidth;
132 float _fixedHeight;
133 std::vector<std::shared_ptr<ecs::Entity>>
134 _entities;
135
136 public:
144 Builder(ecs::ComponentRegistry &componentRegistry,
145 ecs::EntityRegistry &entityRegistry);
146
155 std::shared_ptr<View> buildEntity(void) override;
156
163 void reset(void) override;
164
171 Builder &withPose(const utility::graphic::PoseF &pose);
172
178 Builder &withColor(const utility::graphic::Color32Bit &color);
179
186 Builder &withBorderRadius(float borderRadius);
187
194 Builder &withAxis(Axis axis);
195
204
212
218 Builder &withSpacing(float spacing);
219
227 Builder &withPadding(float padding);
228
235 Builder &withFixedWidth(float width);
236
243 Builder &withFixedHeight(float height);
244
256 const std::vector<std::shared_ptr<ecs::Entity>> &entities);
257
272 std::shared_ptr<View> makeDefaultView(
273 std::shared_ptr<Entity> parent,
274 const utility::graphic::PoseF &pose,
275 const std::vector<std::shared_ptr<ecs::Entity>> &entities);
276
289 std::shared_ptr<View> makeColorView(
290 std::shared_ptr<Entity> parent,
291 const utility::graphic::PoseF &pose,
292 const utility::graphic::Color32Bit &color,
293 const std::vector<std::shared_ptr<ecs::Entity>> &entities);
294 };
295
309 template<typename... Arguments>
310 static std::shared_ptr<View> create(Arguments &&...arguments)
311 {
312 std::shared_ptr<View> entity(
313 new View(std::forward<Arguments>(arguments)...));
314 entity->build();
315 return entity;
316 }
317
321 ~View(void);
322
328 View &setPose(const utility::graphic::PoseF &pose);
329
336 View &setColor(const utility::graphic::Color32Bit &color);
337
344 View &setBorderRadius(float borderRadius);
345
353 View &setAxis(Axis axis);
354
363
371
378 View &setSpacing(float spacing);
379
387 View &setPadding(float padding);
388
395 View &setFixedWidth(float width);
396
402 View &clearFixedWidth(void);
403
410 View &setFixedHeight(float height);
411
417 View &clearFixedHeight(void);
418
433 const std::vector<std::shared_ptr<ecs::Entity>> &entities);
434
435 private:
442 void applyGeometry(void);
443
444 private:
469 const utility::graphic::PoseF &pose,
470 const utility::graphic::Color32Bit &color, float borderRadius,
471 Axis axis, MainAxisAlignment mainAxisAlignment,
472 CrossAxisAlignment crossAxisAlignment, float spacing,
473 float padding, bool hasFixedWidth, float fixedWidth,
474 bool hasFixedHeight, float fixedHeight,
475 const std::vector<std::shared_ptr<ecs::Entity>> &entities);
476
485 void build(void);
486 };
487
488} // namespace guillaume::entities
CrossAxisAlignment
Where each child goes along the cross axis, inside the padding. In a container that wraps its childre...
Definition layout.hpp:99
MainAxisAlignment
Where the children go along the main axis when the container is larger than them.
Definition layout.hpp:86
Axis
Direction along which children are arranged.
Definition layout.hpp:74
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
The base class of a widget with children: an EntityFiller that is also a ParentEntity.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Builder & withMainAxisAlignment(MainAxisAlignment alignment)
Set how the children are distributed along the axis.
Definition view.cpp:95
Builder & withCrossAxisAlignment(CrossAxisAlignment alignment)
Set how each child is aligned across the axis.
Definition view.cpp:102
Builder & withColor(const utility::graphic::Color32Bit &color)
Set the background color.
Definition view.cpp:76
Builder & withEntities(const std::vector< std::shared_ptr< ecs::Entity > > &entities)
Set the entities the view arranges, in layout order.
Definition view.cpp:134
void reset(void) override
Restore the defaults: default pose, transparent background, corner radius 16 dp, horizontal axis,...
Definition view.cpp:52
Builder & withSpacing(float spacing)
Set the gap between two consecutive children.
Definition view.cpp:108
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
Definition view.cpp:35
Builder & withBorderRadius(float borderRadius)
Set the corner radius of the background.
Definition view.cpp:82
Builder & withFixedWidth(float width)
Force the width of the view.
Definition view.cpp:120
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the view is.
Definition view.cpp:69
Builder & withFixedHeight(float height)
Force the height of the view.
Definition view.cpp:127
std::shared_ptr< View > buildEntity(void) override
Build a view from the current configuration, without registering it or giving it a parent.
Definition view.cpp:42
Builder & withPadding(float padding)
Set the space between the edges of the view and its children.
Definition view.cpp:114
std::shared_ptr< View > makeDefaultView(std::shared_ptr< Entity > parent, const utility::graphic::PoseF &pose, const std::vector< std::shared_ptr< ecs::Entity > > &entities)
Build a transparent view, register it under parent and reset the builder.
Definition view.cpp:141
Builder & withAxis(Axis axis)
Choose between a row and a column.
Definition view.cpp:88
std::shared_ptr< View > makeColorView(std::shared_ptr< Entity > parent, const utility::graphic::PoseF &pose, const utility::graphic::Color32Bit &color, const std::vector< std::shared_ptr< ecs::Entity > > &entities)
Build a view with a background color, register it under parent and reset the builder.
Definition view.cpp:148
A rectangle, colored or transparent, that lays its children out in a row or a column.
Definition view.hpp:103
components::Layout::Axis Axis
Definition view.hpp:107
components::Layout::CrossAxisAlignment CrossAxisAlignment
How each child is aligned across the axis.
Definition view.hpp:111
View & setAxis(Axis axis)
Choose between a row and a column. Arranges the children at once.
Definition view.cpp:240
components::Layout::MainAxisAlignment MainAxisAlignment
How the children are distributed along the axis.
Definition view.hpp:109
View & setPadding(float padding)
Set the space between the edges of the view and its children. Arranges the children at once.
Definition view.cpp:284
View & clearFixedWidth(void)
Let the width follow the children again: their extent plus the padding. Arranges the children at once...
Definition view.cpp:306
View & setEntities(const std::vector< std::shared_ptr< ecs::Entity > > &entities)
Replace the entities the view arranges.
Definition view.cpp:339
~View(void)
Destructor.
Definition view.cpp:209
View & setColor(const utility::graphic::Color32Bit &color)
Set the background color.
Definition view.cpp:224
View & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set how each child is aligned across the axis. Arranges the children at once.
Definition view.cpp:262
View & setFixedHeight(float height)
Force the height of the view, whatever its children. Arranges the children at once.
Definition view.cpp:317
View & setFixedWidth(float width)
Force the width of the view, whatever its children. Arranges the children at once.
Definition view.cpp:295
View & setMainAxisAlignment(MainAxisAlignment alignment)
Set how the children are distributed along the axis. Arranges the children at once.
Definition view.cpp:251
View & setPose(const utility::graphic::PoseF &pose)
Move the view. Moves its layout children at once.
Definition view.cpp:213
static std::shared_ptr< View > create(Arguments &&...arguments)
Build a view without registering it in an entity registry.
Definition view.hpp:310
View & setSpacing(float spacing)
Set the gap between two consecutive children. Arranges the children at once.
Definition view.cpp:273
View & clearFixedHeight(void)
Let the height follow the children again: their extent plus the padding. Arranges the children at onc...
Definition view.cpp:328
View & setBorderRadius(float borderRadius)
Set the corner radius of the background.
Definition view.cpp:232
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46