Skip to content
Flecs v4.1
doc.h
Go to the documentation of this file.
1/**
2 * @file addons/doc.h
3 * @brief Doc module.
4 *
5 * The doc module allows for documenting entities (and thus components, systems)
6 * by adding brief and/or detailed descriptions as components. Documentation
7 * added with the doc module can be retrieved at runtime, and can be used by
8 * tooling such as UIs or documentation frameworks.
9 */
10
11#ifdef FLECS_DOC
12
13#ifndef FLECS_DOC_H
14#define FLECS_DOC_H
15
16#ifndef FLECS_MODULE
17#define FLECS_MODULE
18#endif
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/**
25 * @defgroup c_addons_doc Doc
26 * @ingroup c_addons
27 * Utilities for documenting entities, components, and systems.
28 *
29 * @{
30 */
31
32FLECS_API extern const ecs_entity_t ecs_id(EcsDocDescription); /**< Component ID for EcsDocDescription. */
33
34/** Tag for adding a UUID to entities.
35 * Added to an entity as (EcsDocDescription, EcsUuid) by ecs_doc_set_uuid().
36 */
37FLECS_API extern const ecs_entity_t EcsDocUuid;
38
39/** Tag for adding brief descriptions to entities.
40 * Added to an entity as (EcsDocDescription, EcsBrief) by ecs_doc_set_brief().
41 */
42FLECS_API extern const ecs_entity_t EcsDocBrief;
43
44/** Tag for adding detailed descriptions to entities.
45 * Added to an entity as (EcsDocDescription, EcsDocDetail) by ecs_doc_set_detail().
46 */
47FLECS_API extern const ecs_entity_t EcsDocDetail;
48
49/** Tag for adding a link to entities.
50 * Added to an entity as (EcsDocDescription, EcsDocLink) by ecs_doc_set_link().
51 */
52FLECS_API extern const ecs_entity_t EcsDocLink;
53
54/** Tag for adding a color to entities.
55 * Added to an entity as (EcsDocDescription, EcsDocColor) by ecs_doc_set_color().
56 */
57FLECS_API extern const ecs_entity_t EcsDocColor;
58
59/** Component that stores description.
60 * Used as pair together with the following tags to store entity documentation:
61 * - EcsName
62 * - EcsDocBrief
63 * - EcsDocDetail
64 * - EcsDocLink
65 * - EcsDocColor
66 */
67typedef struct EcsDocDescription {
68 char *value; /**< Description value. */
70
71/** Add UUID to entity.
72 * Associate entity with an (external) UUID.
73 *
74 * @param world The world.
75 * @param entity The entity to which to add the UUID.
76 * @param uuid The UUID to add.
77 *
78 * @see ecs_doc_get_uuid()
79 * @see flecs::doc::set_uuid()
80 * @see flecs::entity_builder::set_doc_uuid()
81 */
82FLECS_API
84 ecs_world_t *world,
85 ecs_entity_t entity,
86 const char *uuid);
87
88/** Add human-readable name to entity.
89 * Contrary to entity names, human-readable names do not have to be unique and
90 * can contain special characters used in the query language like '*'.
91 *
92 * @param world The world.
93 * @param entity The entity to which to add the name.
94 * @param name The name to add.
95 *
96 * @see ecs_doc_get_name()
97 * @see flecs::doc::set_name()
98 * @see flecs::entity_builder::set_doc_name()
99 */
100FLECS_API
102 ecs_world_t *world,
103 ecs_entity_t entity,
104 const char *name);
105
106/** Add brief description to entity.
107 *
108 * @param world The world.
109 * @param entity The entity to which to add the description.
110 * @param description The description to add.
111 *
112 * @see ecs_doc_get_brief()
113 * @see flecs::doc::set_brief()
114 * @see flecs::entity_builder::set_doc_brief()
115 */
116FLECS_API
118 ecs_world_t *world,
119 ecs_entity_t entity,
120 const char *description);
121
122/** Add detailed description to entity.
123 *
124 * @param world The world.
125 * @param entity The entity to which to add the description.
126 * @param description The description to add.
127 *
128 * @see ecs_doc_get_detail()
129 * @see flecs::doc::set_detail()
130 * @see flecs::entity_builder::set_doc_detail()
131 */
132FLECS_API
134 ecs_world_t *world,
135 ecs_entity_t entity,
136 const char *description);
137
138/** Add link to external documentation to entity.
139 *
140 * @param world The world.
141 * @param entity The entity to which to add the link.
142 * @param link The link to add.
143 *
144 * @see ecs_doc_get_link()
145 * @see flecs::doc::set_link()
146 * @see flecs::entity_builder::set_doc_link()
147 */
148FLECS_API
150 ecs_world_t *world,
151 ecs_entity_t entity,
152 const char *link);
153
154/** Add color to entity.
155 * UIs can use color as a hint to improve visualizing entities.
156 *
157 * @param world The world.
158 * @param entity The entity to which to add the color.
159 * @param color The color to add.
160 *
161 * @see ecs_doc_get_color()
162 * @see flecs::doc::set_color()
163 * @see flecs::entity_builder::set_doc_color()
164 */
165FLECS_API
167 ecs_world_t *world,
168 ecs_entity_t entity,
169 const char *color);
170
171/** Get UUID from entity.
172 * @param world The world.
173 * @param entity The entity from which to get the UUID.
174 * @return The UUID.
175 *
176 * @see ecs_doc_set_uuid()
177 * @see flecs::doc::get_uuid()
178 * @see flecs::entity_view::get_doc_uuid()
179 */
180FLECS_API
182 const ecs_world_t *world,
183 ecs_entity_t entity);
184
185/** Get human-readable name from entity.
186 * If the entity does not have an explicit human-readable name, this operation will
187 * return the entity name.
188 *
189 * To test if an entity has a human-readable name, use:
190 *
191 * @code
192 * ecs_has_pair(world, e, ecs_id(EcsDocDescription), EcsName);
193 * @endcode
194 *
195 * Or in C++:
196 *
197 * @code
198 * e.has<flecs::doc::Description>(flecs::Name);
199 * @endcode
200 *
201 * @param world The world.
202 * @param entity The entity from which to get the name.
203 * @return The name.
204 *
205 * @see ecs_doc_set_name()
206 * @see flecs::doc::get_name()
207 * @see flecs::entity_view::get_doc_name()
208 */
209FLECS_API
211 const ecs_world_t *world,
212 ecs_entity_t entity);
213
214/** Get brief description from entity.
215 *
216 * @param world The world.
217 * @param entity The entity from which to get the description.
218 * @return The description.
219 *
220 * @see ecs_doc_set_brief()
221 * @see flecs::doc::get_brief()
222 * @see flecs::entity_view::get_doc_brief()
223 */
224FLECS_API
226 const ecs_world_t *world,
227 ecs_entity_t entity);
228
229/** Get detailed description from entity.
230 *
231 * @param world The world.
232 * @param entity The entity from which to get the description.
233 * @return The description.
234 *
235 * @see ecs_doc_set_detail()
236 * @see flecs::doc::get_detail()
237 * @see flecs::entity_view::get_doc_detail()
238 */
239FLECS_API
241 const ecs_world_t *world,
242 ecs_entity_t entity);
243
244/** Get link to external documentation from entity.
245 *
246 * @param world The world.
247 * @param entity The entity from which to get the link.
248 * @return The link.
249 *
250 * @see ecs_doc_set_link()
251 * @see flecs::doc::get_link()
252 * @see flecs::entity_view::get_doc_link()
253 */
254FLECS_API
256 const ecs_world_t *world,
257 ecs_entity_t entity);
258
259/** Get color from entity.
260 *
261 * @param world The world.
262 * @param entity The entity from which to get the color.
263 * @return The color.
264 *
265 * @see ecs_doc_set_color()
266 * @see flecs::doc::get_color()
267 * @see flecs::entity_view::get_doc_color()
268 */
269FLECS_API
271 const ecs_world_t *world,
272 ecs_entity_t entity);
273
274/** Doc module import function.
275 * Usage:
276 * @code
277 * ECS_IMPORT(world, FlecsDoc)
278 * @endcode
279 *
280 * @param world The world.
281 */
282FLECS_API
284 ecs_world_t *world);
285
286/** @} */
287
288#ifdef __cplusplus
289}
290#endif
291
292#endif
293
294#endif
FLECS_API void ecs_doc_set_uuid(ecs_world_t *world, ecs_entity_t entity, const char *uuid)
Add UUID to entity.
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
FLECS_API const ecs_entity_t EcsDocDetail
Tag for adding detailed descriptions to entities.
FLECS_API const ecs_entity_t EcsDocLink
Tag for adding a link to entities.
FLECS_API const char * ecs_doc_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get human-readable name from entity.
FLECS_API const ecs_entity_t EcsDocColor
Tag for adding a color to entities.
FLECS_API const char * ecs_doc_get_color(const ecs_world_t *world, ecs_entity_t entity)
Get color from entity.
FLECS_API const char * ecs_doc_get_uuid(const ecs_world_t *world, ecs_entity_t entity)
Get UUID from entity.
FLECS_API void ecs_doc_set_brief(ecs_world_t *world, ecs_entity_t entity, const char *description)
Add brief description to entity.
FLECS_API const char * ecs_doc_get_link(const ecs_world_t *world, ecs_entity_t entity)
Get link to external documentation from entity.
FLECS_API const char * ecs_doc_get_detail(const ecs_world_t *world, ecs_entity_t entity)
Get detailed description from entity.
FLECS_API const char * ecs_doc_get_brief(const ecs_world_t *world, ecs_entity_t entity)
Get brief description from entity.
FLECS_API const ecs_entity_t EcsDocUuid
Tag for adding a UUID to entities.
FLECS_API void ecs_doc_set_detail(ecs_world_t *world, ecs_entity_t entity, const char *description)
Add detailed description to entity.
FLECS_API const ecs_entity_t EcsDocBrief
Tag for adding brief descriptions to entities.
FLECS_API void ecs_doc_set_link(ecs_world_t *world, ecs_entity_t entity, const char *link)
Add link to external documentation to entity.
FLECS_API void ecs_doc_set_color(ecs_world_t *world, ecs_entity_t entity, const char *color)
Add color to entity.
FLECS_API void ecs_doc_set_name(ecs_world_t *world, ecs_entity_t entity, const char *name)
Add human-readable name to entity.
FLECS_API void FlecsDocImport(ecs_world_t *world)
Doc module import function.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:395
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:439
Component that stores description.
Definition doc.h:67
char * value
Description value.
Definition doc.h:68