guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
divider.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/systems/divider.hpp"
24
25#include <algorithm>
26
27namespace guillaume::systems
28{
29 namespace
30 {
32 utility::graphic::PoseF shifted(const utility::graphic::PoseF &pose,
33 float offset)
34 {
35 auto result = pose;
36 result.setPosition(utility::graphic::PositionF(
37 pose.getPosition().getX() + offset, pose.getPosition().getY(),
38 pose.getPosition().getZ()));
39 return result;
40 }
41 } // namespace
42
45 components::Bound, components::Color,
46 components::Line>(ecs::Phase::Measure)
47 {
48 }
49
50 void Divider::apply(ecs::ComponentRegistry &componentRegistry,
51 const ecs::Entity::Identifier &entityIdentifier)
52 {
53 auto &divider = componentRegistry.getComponent<components::Divider>(
54 entityIdentifier);
55 auto &transform = componentRegistry.getComponent<components::Transform>(
56 entityIdentifier);
57
58 const float leading = divider.getLeadingInset();
59 const float trailing = divider.getTrailingInset();
60
61 // Something else moved the entity: adopt the new position. The
62 // Transform holds the origin shifted by the leading inset, so shift
63 // it back to recover the origin.
64 if (transform.getPose() != divider.getAppliedPose()) {
65 divider.setOriginPose(shifted(transform.getPose(), -leading));
66 }
67
68 const auto pose = shifted(divider.getOriginPose(), leading);
69 transform.setPose(pose);
70 divider.setAppliedPose(pose);
71
72 componentRegistry.getComponent<components::Bound>(entityIdentifier)
73 .setWidth(std::max(0.0f, divider.getLength() - leading - trailing))
74 .setHeight(divider.getThickness());
75
76 componentRegistry.getComponent<components::Line>(entityIdentifier)
77 .setThickness(divider.getThickness());
78
79 componentRegistry.getComponent<components::Color>(entityIdentifier)
80 .setColor(divider.getColor());
81 }
82
83 void Divider::update(const ecs::Entity::Identifier &entityIdentifier)
84 {
85 if (!requireComponent<components::Divider>(entityIdentifier)
86 || !requireComponent<components::Transform>(entityIdentifier)
87 || !requireComponent<components::Bound>(entityIdentifier)
88 || !requireComponent<components::Color>(entityIdentifier)
89 || !requireComponent<components::Line>(entityIdentifier)) {
90 return;
91 }
92
93 apply(getComponentRegistry(), entityIdentifier);
94 }
95} // namespace guillaume::systems
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
Definition bound.hpp:62
Bound & setHeight(float height) noexcept
Set the height.
Definition bound.cpp:42
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Definition color.hpp:58
State of a divider: a thin horizontal line separating content.
Definition divider.hpp:59
Divider & setAppliedPose(const utility::graphic::PoseF &pose)
Record the pose written to the Transform.
Definition divider.cpp:119
const utility::graphic::PoseF & getAppliedPose(void) const
Get the pose systems::Divider last wrote to the Transform.
Definition divider.cpp:114
A straight stroke across the width of the entity: a divider, an indicator, the underline of a text fi...
Definition line.hpp:62
Where an entity is in space: its pose (position and orientation) and its scale.
Definition transform.hpp:64
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.
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
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
Definition system.cpp:53
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the geometry of one divider for this frame.
Definition divider.cpp:83
Divider(void)
Create the system in the Measure phase.
Definition divider.cpp:43
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Write the geometry of one divider from its configuration.
Definition divider.cpp:50
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
Rules. Every class here runs each frame on the entities that have the components it declares.