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{
11
13{
14 property_layout_group(const std::string& name);
16};
25{
26public:
29 auto operator=(const property_layout&) -> property_layout& = delete;
30
38
44 property_layout(const entt::meta_data& prop, const entt::meta_any& object, bool columns = true);
45
51 property_layout(const std::string& name, bool columns = true);
52
59 property_layout(const std::string& name, const std::string& tooltip, bool columns = true);
60
61
68 property_layout(const std::string& name, const std::string& tooltip, const std::string& hint, bool columns = true);
69
76 property_layout(const std::string& name, const std::function<void()>& callback, bool columns = true);
77
82
88 void set_data(const entt::meta_data& prop, const entt::meta_any& object, bool columns = true);
89
96 void set_data(const std::string& name, const std::string& tooltip = "", const std::string& hint = "", bool columns = true);
97
102 void push_layout(bool auto_proceed_to_next_column = true);
103
109 auto push_tree_layout(ImGuiTreeNodeFlags flags = 0, bool default_open = true) -> bool;
110
114 void pop_layout();
115
119 void prepare_for_item();
120
125 static auto get_current() -> property_layout*;
126
127private:
128 hpp::optional<property_layout_group> group_;
130 bool pushed_{};
132 std::string name_;
134 std::string hint_;
136 std::string tooltip_;
138 std::function<void()> callback_;
140 bool columns_{};
142 bool open_{};
144 bool columns_open_{};
145};
146
151{
153 bool read_only{};
156
157 bool is_copyable{true};
158};
159
164{
166 bool changed{};
171
178 {
179 changed |= rhs.changed;
180 edit_finished |= rhs.edit_finished;
181 change_recorded |= rhs.change_recorded;
182 return *this;
183 }
184
190 auto operator|(const inspect_result& rhs) const -> inspect_result
191 {
192 inspect_result result{};
193 result.changed |= rhs.changed;
194 result.edit_finished |= rhs.edit_finished;
195 result.change_recorded |= rhs.change_recorded;
196 return result;
197 }
198};
199
216{
224 {
225
229 std::shared_ptr<meta_any_proxy_impl> parent;
230
231 std::string type_name;
232
233 std::string name;
234
235
236 auto get(entt::meta_any& result) -> bool
237 {
238 return getter(result);
239 }
240
241 auto set(meta_any_proxy& proxy, const entt::meta_any& value, uint64_t execution_count) -> bool
242 {
243 return setter(proxy, value, execution_count);
244 }
245
246 void detach()
247 {
248 if(resolver)
249 {
251 }
252
253 if(parent)
254 {
255 parent->detach();
256 }
257 }
258
259
260 std::function<bool(entt::meta_any&)> resolver;
261
264 std::function<bool(entt::meta_any&)> getter;
265
268 std::function<bool(meta_any_proxy& proxy, const entt::meta_any&, uint64_t execution_count)> setter;
269
270 };
271
274 std::shared_ptr<meta_any_proxy_impl> impl = std::make_shared<meta_any_proxy_impl>();
275
276
279 void detach()
280 {
281 impl->detach();
282 }
283};
284
290auto make_proxy(entt::meta_any& var, const std::string& name = {}) -> meta_any_proxy;
291
298auto make_entity_proxy(entt::meta_any& var, const std::string& name = {}) -> meta_any_proxy;
299
300auto make_property_proxy(const meta_any_proxy& var_proxy, const entt::meta_data& prop) -> meta_any_proxy;
301
309struct inspector : crtp_meta_type<inspector>
310{
317 template<typename T>
318 static void create_and_register(const entt::meta_type& inspected_type,
319 std::unordered_map<entt::id_type, std::shared_ptr<inspector>>& type_map)
320 {
321 type_map[inspected_type.info().index()] = std::make_shared<T>();
322 }
323
325 using attribute_getter = std::function<entt::meta_any(const char*)>;
326
330 virtual ~inspector() = default;
331
337 virtual void before_inspect(const entt::meta_data& prop, const entt::meta_any& object);
338
344 virtual void after_inspect(const entt::meta_data& prop, const entt::meta_any& object);
345
355 virtual auto inspect(rtti::context& ctx,
356 entt::meta_any& var,
357 const meta_any_proxy& var_proxy,
358 const var_info& info,
359 const entt::meta_custom& custom) -> inspect_result = 0;
360
361protected:
363 std::unique_ptr<property_layout> layout_;
365 bool open_{};
366};
367
372{
373 entt::meta_factory<inspector>{}.type("inspector"_hs);
374}
375
381#define REFLECT_INSPECTOR_INLINE(inspector_type, inspected_type) \
382 REFLECT_INLINE(inspector_type) \
383 { \
384 entt::meta_factory<inspector_type>{} \
385 .type(entt::hashed_string{#inspector_type}) \
386 .custom<entt::attributes>( \
387 entt::attributes{entt::attribute{"inspected_type", entt::resolve<inspected_type>()}}) \
388 .base<inspector>() \
389 .func<&inspector::create_and_register<inspector_type>>("create_and_register"_hs); \
390 }
391
397#define REFLECT_INSPECTOR(inspector_type, inspected_type) \
398 REFLECT(inspector_type) \
399 { \
400 entt::meta_factory<inspector_type>{} \
401 .type(entt::hashed_string{#inspector_type}) \
402 .custom<entt::attributes>( \
403 entt::attributes{entt::attribute{"inspected_type", entt::resolve<inspected_type>()}}) \
404 .base<inspector>() \
405 .func<&inspector::create_and_register<inspector_type>>("create_and_register"_hs); \
406 }
407
408} // namespace unravel
Manages ImGui layout for property inspection in the editor.
Definition inspector.h:25
auto operator=(const property_layout &) -> property_layout &=delete
property_layout()
Default constructor that registers this layout in the global stack.
Definition inspector.cpp:68
auto push_tree_layout(ImGuiTreeNodeFlags flags=0, bool default_open=true) -> bool
Creates a collapsible tree node layout for nested properties.
void push_layout(bool auto_proceed_to_next_column=true)
Initializes ImGui layout with tables and property label.
static auto get_current() -> property_layout *
Gets the currently active property layout from the global stack.
Definition inspector.cpp:59
auto operator=(property_layout &&) -> property_layout &=delete
void set_data(const entt::meta_data &prop, const entt::meta_any &object, bool columns=true)
Updates layout data from meta property.
void pop_layout()
Cleans up ImGui state (IDs, tables, tree nodes)
void prepare_for_item()
Prepares ImGui for rendering the property value widget.
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.
std::string name
Definition hub.cpp:33
const char * tooltip
Provides utilities for inspecting and converting sequence-related types to strings.
auto make_entity_proxy(entt::meta_any &var, const std::string &name) -> meta_any_proxy
Like make_proxy, but for entt::handle roots resolved by id_component UUID each access.
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:144
Result of an inspection operation indicating what changes occurred.
Definition inspector.h:164
bool change_recorded
Whether the change was recorded for undo/redo system.
Definition inspector.h:170
auto operator|(const inspect_result &rhs) const -> inspect_result
Creates new result by combining two results with logical OR.
Definition inspector.h:190
bool changed
Whether the value was modified during inspection.
Definition inspector.h:166
auto operator|=(const inspect_result &rhs) -> inspect_result &
Combines this result with another using logical OR.
Definition inspector.h:177
bool edit_finished
Whether user finished editing (e.g., released mouse or pressed enter)
Definition inspector.h:168
std::unique_ptr< property_layout > layout_
Layout manager for this inspector's UI.
Definition inspector.h:363
bool open_
Whether this inspector's UI section is expanded.
Definition inspector.h:365
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:318
virtual void after_inspect(const entt::meta_data &prop, const entt::meta_any &object)
Called after inspecting a property to clean up layout.
virtual void before_inspect(const entt::meta_data &prop, const entt::meta_any &object)
Called before inspecting a property to set 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:325
Implementation containing the deferred access functions.
Definition inspector.h:224
auto get(entt::meta_any &result) -> bool
Definition inspector.h:236
std::function< bool(entt::meta_any &)> resolver
Definition inspector.h:260
auto set(meta_any_proxy &proxy, const entt::meta_any &value, uint64_t execution_count) -> bool
Definition inspector.h:241
std::function< bool(meta_any_proxy &proxy, const entt::meta_any &, uint64_t execution_count)> setter
Definition inspector.h:268
std::shared_ptr< meta_any_proxy_impl > parent
Definition inspector.h:229
std::function< bool(entt::meta_any &)> getter
Definition inspector.h:264
Safe deferred property access proxy for arbitrary object properties.
Definition inspector.h:216
std::shared_ptr< meta_any_proxy_impl > impl
Definition inspector.h:274
property_layout_group(const std::string &name)
Definition inspector.cpp:42
Metadata about a variable being inspected.
Definition inspector.h:151
bool is_property
Whether this is a property that can be overridden in prefabs.
Definition inspector.h:155
bool read_only
Whether the variable should be displayed as read-only.
Definition inspector.h:153