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 <memory>
24
25#include "guillaume/entities/divider.hpp"
26#include "guillaume/entities/builder_base.hpp"
27#include "guillaume/systems/divider.hpp"
28
29#include "guillaume/theme.hpp"
30
31namespace guillaume::entities
32{
34 ecs::EntityRegistry &entityRegistry)
35 : EntityBuilderBase<Divider>(componentRegistry, entityRegistry)
36 {
37 reset();
38 }
39
40 std::shared_ptr<Divider> Divider::Builder::buildEntity(void)
41 {
42 auto entity =
43 Divider::create(this->getComponentRegistry(), _pose, _color,
44 _length, _thickness, _inset, _variant);
45 return entity;
46 }
47
49 {
50 _pose = utility::graphic::PoseF();
51 _color = getActiveColor(SchemeColorRole::OutlineVariant);
52 _length = 100.0f;
53 _thickness = HairlineThickness;
54 _inset = 16.0f;
55 _variant = Variant::FullWidth;
56 }
57
59 Divider::Builder::withPose(const utility::graphic::PoseF &pose)
60 {
61 _pose = pose;
62 return *this;
63 }
64
66 Divider::Builder::withColor(const utility::graphic::Color32Bit &color)
67 {
68 _color = color;
69 return *this;
70 }
71
73 {
74 _length = length;
75 return *this;
76 }
77
79 {
80 _thickness = thickness;
81 return *this;
82 }
83
85 {
86 _inset = inset;
87 return *this;
88 }
89
91 {
92 _variant = variant;
93 return *this;
94 }
95
96 std::shared_ptr<Divider>
97 Divider::Builder::makeDivider(std::shared_ptr<Entity> parent,
98 float length, Variant variant)
99 {
100 return withLength(length).withVariant(variant).registerEntity(parent);
101 }
102
103 Divider::Divider(ecs::ComponentRegistry &registry,
104 const utility::graphic::PoseF &pose,
105 const utility::graphic::Color32Bit &color, float length,
106 float thickness, float inset, Variant variant)
107 : ecs::EntityFiller<components::Transform, components::Bound,
108 components::Color, components::Line,
109 components::Divider>(registry)
110 {
113 .setPose(pose);
114
115 config()
116 .setOriginPose(pose)
117 .setAppliedPose(pose)
118 .setColor(color)
119 .setLength(length)
120 .setThickness(thickness)
121 .setInset(inset)
122 .setVariant(variant);
123
124 apply();
125 }
126
128 {
129 }
130
131 components::Divider &Divider::config(void)
132 {
134 getIdentifier());
135 }
136
137 const components::Divider &Divider::config(void) const
138 {
140 getIdentifier());
141 }
142
143 void Divider::apply(void)
144 {
146 }
147
148 Divider &Divider::setVariant(Variant variant)
149 {
150 config().setVariant(variant);
151 apply();
152 return *this;
153 }
154
155 Divider &Divider::setLength(float length)
156 {
157 config().setLength(length);
158 apply();
159 return *this;
160 }
161
162 Divider &Divider::setThickness(float thickness)
163 {
164 config().setThickness(thickness);
165 apply();
166 return *this;
167 }
168
169 Divider &Divider::setBold(bool bold)
170 {
172 }
173
174 bool Divider::isBold(void) const
175 {
176 return config().getThickness() >= BoldThickness;
177 }
178
179 Divider &Divider::setInset(float inset)
180 {
181 config().setInset(inset);
182 apply();
183 return *this;
184 }
185
186 Divider &Divider::setColor(const utility::graphic::Color32Bit &color)
187 {
188 config().setColor(color);
189 apply();
190 return *this;
191 }
192
194 {
195 return config().getVariant();
196 }
197
198} // namespace guillaume::entities
State of a divider: a thin horizontal line separating content.
Definition divider.hpp:59
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.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
Definition entity.cpp:94
Configures Divider widgets and registers them in the scene's entity registry.
Definition divider.hpp:114
Builder & withLength(float length)
Set the total length.
Definition divider.cpp:72
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
Definition divider.cpp:33
Builder & withInset(float inset)
Set how much an inset end is shortened.
Definition divider.cpp:84
Builder & withVariant(Variant variant)
Choose which ends of the line are inset.
Definition divider.cpp:90
std::shared_ptr< Divider > buildEntity(void) override
Build a divider from the current configuration, without registering it or giving it a parent.
Definition divider.cpp:40
std::shared_ptr< Divider > makeDivider(std::shared_ptr< Entity > parent, float length, Variant variant)
Build a divider, register it under parent and reset the builder.
Definition divider.cpp:97
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the line starts.
Definition divider.cpp:59
Builder & withColor(const utility::graphic::Color32Bit &color)
Set the stroke color.
Definition divider.cpp:66
void reset(void) override
Restore the defaults: default pose, the OutlineVariant color of the active theme, length 100 dp,...
Definition divider.cpp:48
Builder & withThickness(float thickness)
Set the stroke thickness.
Definition divider.cpp:78
static std::shared_ptr< Divider > create(Arguments &&...arguments)
Build a divider without registering it in an entity registry.
Definition divider.hpp:228
static constexpr float BoldThickness
Stroke thickness of a bold divider, in dp (Paper bold).
Definition divider.hpp:106
Divider & setLength(float length)
Set the total length. Resizes the line at once.
Definition divider.cpp:155
~Divider(void) override
Destructor.
Definition divider.cpp:127
Divider & setVariant(Variant variant)
Choose which ends of the line are inset. Moves and resizes the line at once.
Definition divider.cpp:148
components::Divider::Variant Variant
Which ends of the line are shortened by the inset: FullWidth (none), Inset (leading end) or Middle (b...
Definition divider.hpp:94
bool isBold(void) const
Check whether the divider uses the bold stroke.
Definition divider.cpp:174
static constexpr float HairlineThickness
Default stroke thickness, in dp: a hairline (Paper StyleSheet.hairlineWidth on a 2x display).
Definition divider.hpp:100
Variant getVariant(void) const
Tell which ends of the line are inset.
Definition divider.cpp:193
Divider & setThickness(float thickness)
Set the stroke thickness. Restyles at once.
Definition divider.cpp:162
Divider & setBold(bool bold)
Switch between the hairline and the bold stroke (Paper bold). Restyles at once.
Definition divider.cpp:169
Divider & setColor(const utility::graphic::Color32Bit &color)
Set the stroke color. Restyles at once.
Definition divider.cpp:186
Divider & setInset(float inset)
Set how much an inset end is shortened. Moves and resizes the line at once.
Definition divider.cpp:179
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
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
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
utility::graphic::Color32Bit getActiveColor(SchemeColorRole role)
Get the color the active scheme gives to a role.