Unravel Engine C++ Reference
Loading...
Searching...
No Matches
ui_document_component.cpp
Go to the documentation of this file.
7
8#include <type_traits>
9
10namespace unravel
11{
13{
14 auto world_space_predicate_entt = entt::property_predicate<bool>([](const entt::meta_any& obj) -> bool
15 {
16 auto* data = obj.try_cast<ui_document_component>();
17 return data && data->render_mode == ui_render_mode::world_space;
18 });
19
20 entt::meta_factory<ui_render_mode>{}
21 .type("ui_render_mode"_hs)
23 entt::attribute{"name", "ui_render_mode"},
24 entt::attribute{"pretty_name", "UI Render Mode"},
25 })
26 .data<ui_render_mode::screen_space_overlay>("screen_space_overlay"_hs)
28 entt::attribute{"name", "screen_space_overlay"},
29 entt::attribute{"pretty_name", "Screen Space Overlay"},
30 })
31 .data<ui_render_mode::world_space>("world_space"_hs)
33 entt::attribute{"name", "world_space"},
34 entt::attribute{"pretty_name", "World Space"},
35 });
36
37 entt::meta_factory<ui_document_component>{}
38 .type("ui_document_component"_hs)
40 entt::attribute{"name", "ui_document_component"},
41 entt::attribute{"category", "UI"},
42 entt::attribute{"pretty_name", "UI Document"},
43 })
44 .func<&component_meta<ui_document_component>::exists>("component_exists"_hs)
45 .func<&component_meta<ui_document_component>::add>("component_add"_hs)
46 .func<&component_meta<ui_document_component>::remove>("component_remove"_hs)
47 .func<&component_meta<ui_document_component>::save>("component_save"_hs)
48 .func<&component_meta<ui_document_component>::load>("component_load"_hs)
50 .custom<entt::attributes>(entt::attributes{
51 entt::attribute{"name", "enabled"},
52 entt::attribute{"pretty_name", "Enabled"},
53 })
54 .data<&ui_document_component::asset>("asset"_hs)
56 entt::attribute{"name", "asset"},
57 entt::attribute{"pretty_name", "Asset"},
58 })
59 .data<&ui_document_component::render_mode>("render_mode"_hs)
61 entt::attribute{"name", "render_mode"},
62 entt::attribute{"pretty_name", "Render Mode"},
63 entt::attribute{"tooltip", "Screen-space overlay or world-space 3D quad"},
64 entt::attribute{"hint", entt::property_predicate<std::string>([](const entt::meta_any& obj) -> std::string {
65 auto* data = obj.try_cast<ui_document_component>();
66 if(data && data->render_mode == ui_render_mode::screen_space_overlay)
67 {
68 return "Screen Space Overlay can be viewed in the Game View.";
69 }
70 return {};
71 })},
72 })
73 .data<&ui_document_component::size>("size"_hs)
75 entt::attribute{"name", "size"},
76 entt::attribute{"pretty_name", "Size"},
77 entt::attribute{"group", "World Space Units"},
78 entt::attribute{"tooltip", "Document resolution (pixels). For world-space only."},
79 entt::attribute{"predicate", world_space_predicate_entt},
80 })
81 .data<&ui_document_component::pixels_per_world_unit>("pixels_per_world_unit"_hs)
83 entt::attribute{"name", "pixels_per_world_unit"},
84 entt::attribute{"pretty_name", "Pixels per World Unit"},
85 entt::attribute{"group", "World Space Units"},
86 entt::attribute{"tooltip", "Pixels per world unit for world-space rendering."},
87 entt::attribute{"predicate", world_space_predicate_entt},
88 });
89}
90
92{
93 try_save(ar, ser20::make_nvp("enabled", obj.is_enabled()));
94 try_save(ar, ser20::make_nvp("asset", obj.asset));
95 try_save(ar, ser20::make_nvp("render_mode", obj.render_mode));
96 try_save(ar, ser20::make_nvp("size", obj.size));
97 try_save(ar, ser20::make_nvp("pixels_per_world_unit", obj.pixels_per_world_unit));
98}
101
103{
104 bool enabled = true;
105 if(try_load(ar, ser20::make_nvp("enabled", enabled)))
106 {
107 obj.set_enabled(enabled);
108 }
109 try_load(ar, ser20::make_nvp("asset", obj.asset));
110 try_load(ar, ser20::make_nvp("render_mode", obj.render_mode));
111 try_load(ar, ser20::make_nvp("size", obj.size));
112 try_load(ar, ser20::make_nvp("pixels_per_world_unit", obj.pixels_per_world_unit));
113}
116
117} // namespace unravel
auto property_predicate(property_predicate_t< T > predicate) -> property_predicate_t< T >
Definition reflection.h:89
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
@ screen_space_overlay
Screen-space overlay (viewport-sized or positioned)
@ world_space
World-space (rendered on 3D quad, uses transform)
#define REFLECT(cls)
Definition reflection.h:149
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Component that holds a reference to a UI document for RmlUi rendering.
void set_enabled(bool enabled)
Set the enabled state of the document.
auto is_enabled() const -> bool
Check if document is currently enabled.
ui_render_mode render_mode
Rendering mode: screen or world.
bool enabled