18#include <lagrange/utils/warnoff.h>
19#include <entt/entt.hpp>
20#include <lagrange/utils/warnon.h>
26using Registry = entt::registry;
27using Entity = entt::entity;
28inline constexpr entt::null_t NullEntity{};
30using System = std::function<void(Registry& registry)>;
31using StringID = entt::id_type;
35 std::string display_name;
38 std::function<void(entt::registry*, Entity)> show_widget;
40 TypeData& set_display_name(
const std::string& name)
46 TypeData& set_icon(
const std::string& ic)
52 TypeData& set_keybind(
const std::string& kb)
58 TypeData& set_show_widget(
const std::function<
void(entt::registry*, Entity)>& fn)
68enum class IndexingMode { VERTEX, EDGE, FACE, CORNER, INDEXED };
69enum class PrimitiveType { POINTS, LINES, TRIANGLES };
70enum class SelectionBehavior { SET, ADD, ERASE };
72using namespace entt::literals;
74inline StringID string_id(
const std::string& str)
76 return entt::hashed_string(str.c_str());
78inline StringID string_id(
const char* str)
80 return entt::hashed_string(str);
84void component_clone(Registry* w, Entity src, Entity dst)
86 w->emplace_or_replace<T>(dst, w->get<T>(src));
90void component_move(Registry* w, Entity src, Entity dst)
92 w->emplace_or_replace<T>(dst, std::move(w->get<T>(src)));
97void component_add_default(Registry* w, Entity dst)
99 w->emplace_or_replace<T>(dst);
105 static const char* id() {
return "PayloadEntity"; }
113 static const char* id() {
return "PayloadComponent"; }
114 entt::id_type component_hash;
119template <
typename Component>
120void register_component(
const std::string& display_name = entt::type_id<Component>().name().data())
122 using namespace entt::literals;
123 entt::meta_factory<Component>()
124 .template func<&component_clone<Component>>(
"component_clone"_hs)
125 .
template func<&component_move<Component>>(
"component_move"_hs)
126 .template func<&component_add_default<Component>>(
"component_add_default"_hs)
127 .
template custom<TypeData>(
TypeData().set_display_name(display_name));
130template <
typename Component, auto Func>
131void register_component_widget()
133 using namespace entt::literals;
134 entt::meta_factory<Component>().template func<Func>(
"show_widget"_hs);
137template <
typename Component>
138void register_component_widget(
const std::function<
void(Registry*, Entity)>& fn)
140 using namespace entt::literals;
141 entt::meta_factory<Component>().template custom<TypeData>(TypeData().set_show_widget(fn));
144inline void show_widget(Registry& w, Entity e,
const entt::meta_type& meta_type)
146 using namespace entt::literals;
147 auto fn = meta_type.func(
"show_widget"_hs);
149 fn.invoke({}, &w, e);
151 const TypeData* type_data = meta_type.custom();
153 type_data->show_widget(&w, e);
158template <
typename Resolvable>
159void show_widget(Registry& r, Entity e,
const Resolvable& resolvable)
161 show_widget(r, e, entt::resolve(resolvable));
Lagrange UI Viewer and mini 3D engine.
Definition AcceleratedPicking.h:23
Main namespace for Lagrange.
Payload for sending components through UI.
Definition Entity.h:112
Payload for sending entities through UI.
Definition Entity.h:104