Unravel Engine C++ Reference
Loading...
Searching...
No Matches
inspector_resolution.cpp
Go to the documentation of this file.
2#include "imgui/imgui.h"
3#include "inspectors.h"
5
6namespace unravel
7{
8
10 entt::meta_any& var,
11 const meta_any_proxy& var_proxy,
12 const var_info& info,
13 const entt::meta_custom& custom) -> inspect_result
14{
15 auto& data = var.cast<settings::resolution_settings&>();
16 auto& resolutions = data.resolutions;
17
18 inspect_result result{};
19
20 // Display current resolutions
21 for(size_t i = 0; i < resolutions.size(); ++i)
22 {
23 auto& resolution = resolutions[i];
24
25 ImGui::PushID(static_cast<int>(i));
26
27 ImGui::Separator();
28
29 // Resolution header with delete button
30 ImGui::AlignTextToFramePadding();
31 if(ImGui::TreeNode(("Resolution " + std::to_string(i)).c_str()))
32 {
33 // Name field
34 {
35 property_layout layout("Name");
36 char name_buffer[256];
37 std::strncpy(name_buffer, resolution.name.c_str(), sizeof(name_buffer) - 1);
38 name_buffer[sizeof(name_buffer) - 1] = '\0';
39
40 if(ImGui::InputText("##name", name_buffer, sizeof(name_buffer)))
41 {
42 resolution.name = name_buffer;
43 result.changed = true;
44 }
45 result.edit_finished |= ImGui::IsItemDeactivatedAfterEdit();
46 ImGui::DrawItemActivityOutline();
47 }
48
49 // Width field
50 {
51 property_layout layout("Width");
52 int width = resolution.width;
53 if(ImGui::InputInt("##width", &width, 1, 100))
54 {
55 if(width >= 0)
56 {
57 resolution.width = width;
58 result.changed = true;
59 }
60 }
61 result.edit_finished |= ImGui::IsItemDeactivatedAfterEdit();
62 ImGui::DrawItemActivityOutline();
63 }
64
65 // Height field
66 {
67 property_layout layout("Height");
68 int height = resolution.height;
69 if(ImGui::InputInt("##height", &height, 1, 100))
70 {
71 if(height >= 0)
72 {
73 resolution.height = height;
74 result.changed = true;
75 }
76 }
77 result.edit_finished |= ImGui::IsItemDeactivatedAfterEdit();
78 ImGui::DrawItemActivityOutline();
79 }
80
81 // Aspect ratio field
82 {
83 property_layout layout("Aspect Ratio");
84 float aspect = resolution.aspect;
85 if(ImGui::InputFloat("##aspect", &aspect, 0.01f, 0.1f, "%.3f"))
86 {
87 if(aspect >= 0.0f)
88 {
89 resolution.aspect = aspect;
90 result.changed = true;
91 }
92 }
93 result.edit_finished |= ImGui::IsItemDeactivatedAfterEdit();
94 ImGui::DrawItemActivityOutline();
95
96 ImGui::SameLine();
97 if(ImGui::Button("Auto Calculate"))
98 {
99 if(resolution.width > 0 && resolution.height > 0)
100 {
101 resolution.aspect = static_cast<float>(resolution.width) / static_cast<float>(resolution.height);
102 result.changed = true;
103 result.edit_finished = true;
104 }
105 }
106 ImGui::SetItemTooltipEx("Calculate aspect ratio from width and height");
107 }
108
109 // Delete button (don't allow deleting the first resolution "Free Aspect")
110 if(i > 0 && !info.read_only)
111 {
112 ImGui::Separator();
113 if(ImGui::Button(ICON_MDI_DELETE " Delete Resolution"))
114 {
115 resolutions.erase(resolutions.begin() + i);
116 result.changed = true;
117 result.edit_finished = true;
118 ImGui::TreePop();
119 ImGui::PopID();
120 break; // Exit the loop since we modified the vector
121 }
122 ImGui::SetItemTooltipEx("Delete this resolution");
123 }
124
125 ImGui::TreePop();
126 }
127
128 ImGui::PopID();
129 }
130
131 // Add new resolution button
132 if(!info.read_only)
133 {
134 ImGui::Separator();
135 if(ImGui::Button(ICON_MDI_PLUS " Add New Resolution"))
136 {
138 new_resolution.name = "New Resolution";
139 new_resolution.width = 1920;
140 new_resolution.height = 1080;
141 new_resolution.aspect = 16.0f / 9.0f;
142
143 resolutions.push_back(new_resolution);
144 result.changed = true;
145 result.edit_finished = true;
146 }
147 ImGui::SetItemTooltipEx("Add a new resolution preset");
148 }
149
150 return result;
151}
152
153} // namespace unravel
Manages ImGui layout for property inspection in the editor.
Definition inspector.h:19
#define ICON_MDI_PLUS
#define ICON_MDI_DELETE
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
std::vector< resolution > resolutions
Definition settings.h:83
Metadata about a variable being inspected.
Definition inspector.h:133