27#include "guillaume/entities/view.hpp"
28#include "guillaume/entities/builder_base.hpp"
30#include "guillaume/systems/layout.hpp"
45 _borderRadius, _axis, _mainAxisAlignment,
46 _crossAxisAlignment, _spacing, _padding,
47 _hasFixedWidth, _fixedWidth, _hasFixedHeight,
48 _fixedHeight, _entities);
54 _pose = utility::graphic::PoseF();
55 _color = { 0, 0, 0, 0 };
56 _borderRadius = 16.0f;
57 _axis = Axis::Horizontal;
58 _mainAxisAlignment = MainAxisAlignment::Start;
59 _crossAxisAlignment = CrossAxisAlignment::Center;
62 _hasFixedWidth =
false;
63 _hasFixedHeight =
false;
84 _borderRadius = borderRadius;
97 _mainAxisAlignment = alignment;
104 _crossAxisAlignment = alignment;
122 _hasFixedWidth =
true;
129 _hasFixedHeight =
true;
130 _fixedHeight = height;
135 const std::vector<std::shared_ptr<ecs::Entity>> &
entities)
142 std::shared_ptr<Entity> parent,
const utility::graphic::PoseF &pose,
143 const std::vector<std::shared_ptr<ecs::Entity>> &
entities)
149 std::shared_ptr<Entity> parent,
const utility::graphic::PoseF &pose,
150 const utility::graphic::Color32Bit &color,
151 const std::vector<std::shared_ptr<ecs::Entity>> &
entities)
156 .registerEntity(parent);
160 const utility::graphic::PoseF &pose,
161 const utility::graphic::Color32Bit &color,
float borderRadius,
164 float padding,
bool hasFixedWidth,
float fixedWidth,
165 bool hasFixedHeight,
float fixedHeight,
166 const std::vector<std::shared_ptr<ecs::Entity>> &
entities)
186 layout.setFixedWidth(fixedWidth);
188 if (hasFixedHeight) {
189 layout.setFixedHeight(fixedHeight);
195 std::vector<ecs::Entity::Identifier> childIdentifiers;
196 childIdentifiers.reserve(
entities.size());
198 for (
const auto &entity:
entities) {
199 if (entity !=
nullptr
202 childIdentifiers.push_back(entity->getIdentifier());
340 const std::vector<std::shared_ptr<ecs::Entity>> &
entities)
342 std::vector<ecs::Entity::Identifier> childIdentifiers;
343 childIdentifiers.reserve(
entities.size());
345 for (
const auto &entity:
entities) {
346 if (entity !=
nullptr
348 entity->setParent(shared_from_this());
349 childIdentifiers.push_back(entity->getIdentifier());
357 .setChildren(childIdentifiers);
364 void View::build(
void)
366 const auto self = shared_from_this();
367 const auto &children =
377 std::vector<std::shared_ptr<ecs::Entity>> pending;
379 for (
auto iterator = direct.begin(); iterator != direct.end();) {
380 const bool isLayoutChild =
381 std::find(children.begin(), children.end(),
382 (*iterator)->getIdentifier())
385 if (isLayoutChild && (*iterator)->getParent() != self) {
386 pending.push_back(std::move(*iterator));
387 iterator = direct.erase(iterator);
393 for (
const auto &entity: pending) {
394 entity->setParent(self);
400 void View::applyGeometry(
void)
406 registry, identifier,
407 registry.
getComponent<components::Layout>(identifier).getChildren(),
Corner radii and outline stroke of a rectangular entity.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
How a container arranges its children: in a row or a column, with which alignment,...
Layout & setChildren(const std::vector< ecs::Entity::Identifier > &children)
Replace the list of children to arrange.
Layout & setAxis(Axis axis)
Choose between a row and a column.
Layout & setPadding(float padding)
Set the inset between the container's edges and its children.
Layout & setMainAxisAlignment(MainAxisAlignment alignment)
Set where the children go along the main axis.
Layout & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set where each child goes along the cross axis.
Layout & setSpacing(float spacing)
Set the gap between two consecutive children.
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
Owns entities and gives the systems the list of entities to visit.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
ParentEntityFiller(ComponentRegistry &componentRegistry)
ComponentRegistry & getComponentRegistry(void)
std::vector< std::shared_ptr< Entity > > & accessDirectEntities(void) override
Give access to the list of entities this entity owns directly.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Configures View widgets and registers them in the scene's entity registry.
Builder & withMainAxisAlignment(MainAxisAlignment alignment)
Set how the children are distributed along the axis.
Builder & withCrossAxisAlignment(CrossAxisAlignment alignment)
Set how each child is aligned across the axis.
Builder & withColor(const utility::graphic::Color32Bit &color)
Set the background color.
Builder & withEntities(const std::vector< std::shared_ptr< ecs::Entity > > &entities)
Set the entities the view arranges, in layout order.
void reset(void) override
Restore the defaults: default pose, transparent background, corner radius 16 dp, horizontal axis,...
Builder & withSpacing(float spacing)
Set the gap between two consecutive children.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
Builder & withBorderRadius(float borderRadius)
Set the corner radius of the background.
Builder & withFixedWidth(float width)
Force the width of the view.
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the view is.
Builder & withFixedHeight(float height)
Force the height of the view.
std::shared_ptr< View > buildEntity(void) override
Build a view from the current configuration, without registering it or giving it a parent.
Builder & withPadding(float padding)
Set the space between the edges of the view and its children.
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.
Builder & withAxis(Axis axis)
Choose between a row and a column.
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.
components::Layout::Axis Axis
components::Layout::CrossAxisAlignment CrossAxisAlignment
How each child is aligned across the axis.
View & setAxis(Axis axis)
Choose between a row and a column. Arranges the children at once.
components::Layout::MainAxisAlignment MainAxisAlignment
How the children are distributed along the axis.
View & setPadding(float padding)
Set the space between the edges of the view and its children. Arranges the children at once.
View & clearFixedWidth(void)
Let the width follow the children again: their extent plus the padding. Arranges the children at once...
View & setEntities(const std::vector< std::shared_ptr< ecs::Entity > > &entities)
Replace the entities the view arranges.
View & setColor(const utility::graphic::Color32Bit &color)
Set the background color.
View & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set how each child is aligned across the axis. Arranges the children at once.
View & setFixedHeight(float height)
Force the height of the view, whatever its children. Arranges the children at once.
View & setFixedWidth(float width)
Force the width of the view, whatever its children. Arranges the children at once.
View & setMainAxisAlignment(MainAxisAlignment alignment)
Set how the children are distributed along the axis. Arranges the children at once.
View & setPose(const utility::graphic::PoseF &pose)
Move the view. Moves its layout children at once.
static std::shared_ptr< View > create(Arguments &&...arguments)
Build a view without registering it in an entity registry.
View & setSpacing(float spacing)
Set the gap between two consecutive children. Arranges the children at once.
View & clearFixedHeight(void)
Let the height follow the children again: their extent plus the padding. Arranges the children at onc...
View & setBorderRadius(float borderRadius)
Set the corner radius of the background.
static void apply(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const std::vector< ecs::Entity::Identifier > &childIdentifiers, std::uint32_t layer=0)
Arrange children inside a container and size the container.
static std::uint32_t layerOf(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &identifier)
Get the layer of an entity: its depth in the entity tree.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Widgets: the classes used to create entities with the right components and children.