Unravel Engine C++ Reference
Loading...
Searching...
No Matches
ui_tree.cpp
Go to the documentation of this file.
1#include "ui_tree.hpp"
3#include <fstream>
6
7namespace unravel
8{
10{
11 // Register ui_tree with entt
12 entt::meta_factory<ui_tree>{}
13 .type("ui_tree"_hs)
15 entt::attribute{"name", "ui_tree"},
16 entt::attribute{"pretty_name", "Visual Tree"},
17 entt::attribute{"category", "UI"},
18 })
19 .data<&ui_tree::content>("content"_hs)
21 entt::attribute{"name", "content"},
22 entt::attribute{"pretty_name", "Content"},
23 entt::attribute{"tooltip", "The HTML/RML content of the visual tree"},
24 entt::attribute{"multiline", true},
25 entt::attribute{"type", "code"},
26 entt::attribute{"wrap", true},
27 });
28}
29
31{
32 try_save(ar, ser20::make_nvp("content", obj.content));
33}
36
38{
39 try_load(ar, ser20::make_nvp("content", obj.content));
40}
43
44void save_to_file(const std::string& absolute_path, const ui_tree::sptr& obj)
45{
46 std::ofstream stream(absolute_path);
47 if(stream.good())
48 {
49 stream.write(obj->content.c_str(), obj->content.size());
50 }
51}
52
53void save_to_file_bin(const std::string& absolute_path, const ui_tree::sptr& obj)
54{
55 std::ofstream stream(absolute_path, std::ios::binary);
56 if(stream.good())
57 {
58 ser20::oarchive_binary_t ar(stream);
59 try_save(ar, ser20::make_nvp("ui_tree", *obj));
60 }
61}
62
63void load_from_file(const std::string& absolute_path, ui_tree::sptr& obj)
64{
65 std::ifstream stream(absolute_path);
66 if(stream.good())
67 {
68 obj->content = fs::read_stream_str(stream);
69 }
70}
71
72void load_from_file_bin(const std::string& absolute_path, ui_tree::sptr& obj)
73{
74 std::ifstream stream(absolute_path, std::ios::binary);
75 if(stream.good())
76 {
77 ser20::iarchive_binary_t ar(stream);
78 try_load(ar, ser20::make_nvp("ui_tree", *obj));
79 }
80}
81
82} // namespace unravel
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:133
#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