Unravel Engine C++ Reference
Loading...
Searching...
No Matches
inspector.h
Go to the documentation of this file.
1#pragma once
2
3#include <context/context.hpp>
6
8
9namespace unravel
10{
19{
20public:
23 auto operator=(const property_layout&) -> property_layout& = delete;
24
32
38 property_layout(const entt::meta_data& prop, bool columns = true);
39
45 property_layout(const std::string& name, bool columns = true);
46
53 property_layout(const std::string& name, const std::string& tooltip, bool columns = true);
54
61 property_layout(const std::string& name, const std::function<void()>& callback, bool columns = true);
62
67
73 void set_data(const entt::meta_data& prop, bool columns = true);
74
81 void set_data(const std::string& name, const std::string& tooltip, bool columns = true);
82
87 void push_layout(bool auto_proceed_to_next_column = true);
88
94 auto push_tree_layout(ImGuiTreeNodeFlags flags = 0) -> bool;
95
99 void pop_layout();
100
104 void prepare_for_item();
105
110 static auto get_current() -> property_layout*;
111
112private:
114 bool pushed_{};
116 std::string name_;
118 std::string tooltip_;
120 std::function<void()> callback_;
122 bool columns_{};
124 bool open_{};
126 bool columns_open_{};
127};
128
133{
135 bool read_only{};
138
139 bool is_copyable{true};
140};
141
146{
148 bool changed{};
153
160 {
161 changed |= rhs.changed;
162 edit_finished |= rhs.edit_finished;
163 change_recorded |= rhs.change_recorded;
164 return *this;
165 }
166
172 auto operator|(const inspect_result& rhs) const -> inspect_result
173 {
174 inspect_result result{};
175 result.changed |= rhs.changed;
176 result.edit_finished |= rhs.edit_finished;
177 result.change_recorded |= rhs.change_recorded;
178 return result;
179 }
180};
181
198{
206 {
209 std::function<bool(entt::meta_any&)> getter;
210
213 std::function<bool(meta_any_proxy& proxy, const entt::meta_any&, uint64_t execution_count)> setter;
214
216 std::function<std::string()> get_name;
217 };
218
221 std::shared_ptr<meta_any_proxy_impl> impl = std::make_shared<meta_any_proxy_impl>();
222};
223
229auto make_proxy(entt::meta_any& var, const std::string& name = {}) -> meta_any_proxy;
230
231auto make_property_proxy(const meta_any_proxy& var_proxy, const entt::meta_data& prop) -> meta_any_proxy;
232
240struct inspector : crtp_meta_type<inspector>
241{
248 template<typename T>
249 static void create_and_register(const entt::meta_type& inspected_type,
250 std::unordered_map<entt::id_type, std::shared_ptr<inspector>>& type_map)
251 {
252 type_map[inspected_type.info().index()] = std::make_shared<T>();
253 }
254
256 using attribute_getter = std::function<entt::meta_any(const char*)>;
257
261 virtual ~inspector() = default;
262
267 virtual void before_inspect(const entt::meta_data& prop);
268
273 virtual void after_inspect(const entt::meta_data& prop);
274
284 virtual auto inspect(rtti::context& ctx,
285 entt::meta_any& var,
286 const meta_any_proxy& var_proxy,
287 const var_info& info,
288 const entt::meta_custom& custom) -> inspect_result = 0;
289
290protected:
292 std::unique_ptr<property_layout> layout_;
294 bool open_{};
295};
296
301{
302 entt::meta_factory<inspector>{}.type("inspector"_hs);
303}
304
310#define REFLECT_INSPECTOR_INLINE(inspector_type, inspected_type) \
311 REFLECT_INLINE(inspector_type) \
312 { \
313 entt::meta_factory<inspector_type>{} \
314 .type(entt::hashed_string{#inspector_type}) \
315 .custom<entt::attributes>( \
316 entt::attributes{entt::attribute{"inspected_type", entt::resolve<inspected_type>()}}) \
317 .base<inspector>() \
318 .func<&inspector::create_and_register<inspector_type>>("create_and_register"_hs); \
319 }
320
326#define REFLECT_INSPECTOR(inspector_type, inspected_type) \
327 REFLECT(inspector_type) \
328 { \
329 entt::meta_factory<inspector_type>{} \
330 .type(entt::hashed_string{#inspector_type}) \
331 .custom<entt::attributes>( \
332 entt::attributes{entt::attribute{"inspected_type", entt::resolve<inspected_type>()}}) \
333 .base<inspector>() \
334 .func<&inspector::create_and_register<inspector_type>>("create_and_register"_hs); \
335 }
336
337} // namespace unravel
Manages ImGui layout for property inspection in the editor.
Definition inspector.h:19
auto operator=(const property_layout &) -> property_layout &=delete
void set_data(const entt::meta_data &prop, bool columns=true)
Updates layout data from meta property.
Definition inspector.cpp:75
property_layout()
Default constructor that registers this layout in the global stack.
Definition inspector.cpp:25
void push_layout(bool auto_proceed_to_next_column=true)
Initializes ImGui layout with tables and property label.
Definition inspector.cpp:92
static auto get_current() -> property_layout *
Gets the currently active property layout from the global stack.
Definition inspector.cpp:20
auto operator=(property_layout &&) -> property_layout &=delete
void pop_layout()
Cleans up ImGui state (IDs, tables, tree nodes)
void prepare_for_item()
Prepares ImGui for rendering the property value widget.
auto push_tree_layout(ImGuiTreeNodeFlags flags=0) -> bool
Creates a collapsible tree node layout for nested properties.
property_layout(property_layout &&)=delete
Disable move operations to prevent stack corruption.
property_layout(const property_layout &)=delete
Disable copy operations due to RAII nature and global stack management.
~property_layout()
Destructor that cleans up ImGui state and removes from stack.
Definition inspector.cpp:68
std::string name
Definition hub.cpp:27
const char * tooltip
Provides utilities for inspecting and converting sequence-related types to strings.
auto make_property_proxy(const meta_any_proxy &var_proxy, const entt::meta_data &prop) -> meta_any_proxy
auto make_proxy(entt::meta_any &var, const std::string &name) -> meta_any_proxy
Creates a simple proxy for direct variable access.
#define REFLECT_INLINE(cls)
Definition reflection.h:128
Result of an inspection operation indicating what changes occurred.
Definition inspector.h:146
bool change_recorded
Whether the change was recorded for undo/redo system.
Definition inspector.h:152
auto operator|(const inspect_result &rhs) const -> inspect_result
Creates new result by combining two results with logical OR.
Definition inspector.h:172
bool changed
Whether the value was modified during inspection.
Definition inspector.h:148
auto operator|=(const inspect_result &rhs) -> inspect_result &
Combines this result with another using logical OR.
Definition inspector.h:159
bool edit_finished
Whether user finished editing (e.g., released mouse or pressed enter)
Definition inspector.h:150
std::unique_ptr< property_layout > layout_
Layout manager for this inspector's UI.
Definition inspector.h:292
virtual void before_inspect(const entt::meta_data &prop)
Called before inspecting a property to set up layout.
bool open_
Whether this inspector's UI section is expanded.
Definition inspector.h:294
static void create_and_register(const entt::meta_type &inspected_type, std::unordered_map< entt::id_type, std::shared_ptr< inspector > > &type_map)
Factory method to create and register inspector instances.
Definition inspector.h:249
virtual void after_inspect(const entt::meta_data &prop)
Called after inspecting a property to clean up layout.
virtual ~inspector()=default
Virtual destructor for proper cleanup.
virtual 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=0
Pure virtual method to render and handle interaction for a variable.
std::function< entt::meta_any(const char *)> attribute_getter
Function type for retrieving meta attributes by name.
Definition inspector.h:256
Implementation containing the deferred access functions.
Definition inspector.h:206
std::function< std::string()> get_name
Function to get the property path as a string for debugging and error reporting.
Definition inspector.h:216
std::function< bool(meta_any_proxy &proxy, const entt::meta_any &, uint64_t execution_count)> setter
Definition inspector.h:213
std::function< bool(entt::meta_any &)> getter
Definition inspector.h:209
Safe deferred property access proxy for arbitrary object properties.
Definition inspector.h:198
std::shared_ptr< meta_any_proxy_impl > impl
Definition inspector.h:221
Metadata about a variable being inspected.
Definition inspector.h:133
bool is_property
Whether this is a property that can be overridden in prefabs.
Definition inspector.h:137
bool read_only
Whether the variable should be displayed as read-only.
Definition inspector.h:135