Unravel Engine C++ Reference
Loading...
Searching...
No Matches
inspector_layer.cpp
Go to the documentation of this file.
1#include "inspector_layer.h"
2#include "imgui/imgui.h"
3#include "inspectors.h"
5#include <editor/hub/hub.h>
6
7namespace unravel
8{
9
11 entt::meta_any& var,
12 const meta_any_proxy& var_proxy,
13 const var_info& info,
14 const entt::meta_custom& custom) -> inspect_result
15{
16
17 auto& data = var.cast<layer_mask&>();
18 std::bitset<32> bits = data.mask;
19
20 inspect_result result{};
21
22
23 const auto& layer_names = ctx.get<settings>().layer.layers;
24
25
26 std::string preview;
27
28 if(bits.all())
29 {
30 preview = "Everything";
31 }
32 else if(bits.none())
33 {
34 preview = "Nothing";
35 }
36 else
37 {
38
39 for(size_t i = 0; i < bits.size(); ++i)
40 {
41 if(bits.test(i) && !layer_names[i].empty())
42 {
43 if(!preview.empty())
44 {
45 preview += ",";
46 }
47 preview += layer_names[i];
48 }
49 }
50 }
51
52 if(ImGui::CalcTextSize(preview.c_str()).x > ImGui::GetContentRegionAvail().x)
53 {
54 preview = "Mixed...";
55 }
56
57
58 if(ImGui::BeginCombo("##Type", preview.c_str()))
59 {
60 ImGui::PushItemFlag(ImGuiItemFlags_AutoClosePopups, false);
61
62 if(ImGui::MenuItem("Edit Layers...", "", false))
63 {
64 ctx.get_cached<hub>().open_project_settings(ctx, "Layers");
65 }
66
67 if(ImGui::MenuItem("Nothing", "", bits.none()))
68 {
69 bits.reset();
70
71 result.changed = true;
72 }
73
74 if(ImGui::MenuItem("Everything", "", bits.all()))
75 {
76 bits.set();
77
78 result.changed = true;
79 }
80
81 for(size_t i = 0; i < bits.size(); ++i)
82 {
83 if(layer_names[i].empty())
84 {
85 continue;
86 }
87 if(ImGui::MenuItem(layer_names[i].c_str(), "", bits.test(i)))
88 {
89 bits.flip(i);
90 result.changed = true;
91 }
92
93 ImGui::DrawItemActivityOutline();
94 }
95
96
97 ImGui::PopItemFlag();
98
99 ImGui::EndCombo();
100 }
101
102 if(result.changed)
103 {
104 result.edit_finished |= true;//ImGui::IsItemDeactivatedAfterEdit();
105
106 data.mask = int(bits.to_ulong());
107 }
108
109 return result;
110}
111
112} // namespace unravel
Result of an inspection operation indicating what changes occurred.
Definition inspector.h:146
auto inspect(rtti::context &ctx, entt::meta_any &var, const meta_any_proxy &var_proxy, const var_info &info, const entt::meta_custom &custom) -> inspect_result override
Safe deferred property access proxy for arbitrary object properties.
Definition inspector.h:198
Metadata about a variable being inspected.
Definition inspector.h:133