Unravel Engine C++ Reference
Loading...
Searching...
No Matches
style_sheet.cpp
Go to the documentation of this file.
1#include "style_sheet.hpp"
3#include <fstream>
6
7namespace unravel
8{
10{
11 // Register style_sheet with entt
12 entt::meta_factory<style_sheet>{}
13 .type("style_sheet"_hs)
15 entt::attribute{"name", "style_sheet"},
16 entt::attribute{"pretty_name", "Style Sheet"},
17 entt::attribute{"category", "UI"},
18 })
19 .data<&style_sheet::content>("content"_hs)
21 entt::attribute{"name", "content"},
22 entt::attribute{"pretty_name", "Content"},
23 entt::attribute{"tooltip", "The CSS/RCSS content of the style sheet"},
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 style_sheet::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 style_sheet::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("style_sheet", *obj));
60 }
61}
62
63void load_from_file(const std::string& absolute_path, style_sheet::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, style_sheet::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("style_sheet", *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 style sheet asset (CSS/RCSS document).
Definition style_sheet.h:26
std::shared_ptr< style_sheet > sptr
Shared pointer to a style sheet.
Definition style_sheet.h:27