Unravel Engine C++ Reference
Loading...
Searching...
No Matches
ui_tree.cpp
Go to the documentation of this file.
1#include "ui_tree.hpp"
4#include <fstream>
7
8namespace unravel
9{
11{
12 // Register ui_tree with entt
13 entt::meta_factory<ui_tree>{}
14 .type("ui_tree"_hs)
16 entt::attribute{"name", "ui_tree"},
17 entt::attribute{"pretty_name", "Visual Tree"},
18 entt::attribute{"category", "UI"},
19 })
20 .data<&ui_tree::content>("content"_hs)
22 entt::attribute{"name", "content"},
23 entt::attribute{"pretty_name", "Content"},
24 entt::attribute{"tooltip", "The HTML/RML content of the visual tree"},
25 entt::attribute{"multiline", true},
26 entt::attribute{"type", "code"},
27 entt::attribute{"wrap", true},
28 });
29}
30
32{
33 try_save(ar, ser20::make_nvp("content", obj.content));
34}
37
39{
40 try_load(ar, ser20::make_nvp("content", obj.content));
41}
44
45void save_to_file(const std::string& absolute_path, const ui_tree::sptr& obj)
46{
47 std::ofstream stream(absolute_path);
48 if(stream.good())
49 {
50 stream.write(obj->content.c_str(), obj->content.size());
51 }
52}
53
54void save_to_file_bin(const std::string& absolute_path, const ui_tree::sptr& obj)
55{
56 std::ofstream stream(absolute_path, std::ios::binary);
57 if(stream.good())
58 {
59 ser20::oarchive_binary_t ar(stream);
60 try_save(ar, ser20::make_nvp("ui_tree", *obj));
61 }
62}
63
64void load_from_file(const std::string& absolute_path, ui_tree::sptr& obj)
65{
66 fs::file_istream input(absolute_path);
67 if(!input.is_open())
68 {
69 return;
70 }
71 obj->content = fs::read_stream_str(input);
72}
73
74void load_from_file_bin(const std::string& absolute_path, ui_tree::sptr& obj)
75{
76 fs::file_istream input(absolute_path, std::ios::binary);
77 if(!input.is_open())
78 {
79 return;
80 }
82 try_load(ar, ser20::make_nvp("ui_tree", *obj));
83}
84
85} // namespace unravel
stdio-backed input stream. Accepts std::ios open flags (e.g. std::ios::binary) when opening a
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
std::string read_stream_str(std::istream &stream)
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
void load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
#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
Represents a UI visual tree asset (HTML/RML document).
Definition ui_tree.h:25
std::shared_ptr< ui_tree > sptr
Shared pointer to a visual tree.
Definition ui_tree.h:26