Unravel Engine C++ Reference
Loading...
Searching...
No Matches
property_actions.cpp
Go to the documentation of this file.
1#include "property_actions.h"
2
3namespace unravel
4{
5
6
7// Property Action Implementation
8property_action_t::property_action_t(meta_any_proxy inst, const entt::meta_any& old_val, const entt::meta_any& new_val, const entt::meta_custom& custom, const std::function<void()>& on_success)
9 : instance(inst), old_value(old_val), new_value(new_val), custom(custom), on_success(on_success)
10{
11
12 if(!inst.impl->name.empty())
13 {
14 name = inst.impl->name;
15 }
16 else
17 {
18 name = "Property Edit";
19 }
20}
21
23{
24 if(instance.impl->setter(instance, new_value, execution_count))
25 {
26 if(on_success)
27 {
28 on_success();
29 }
30 }
31 // After first execution, switch to resolver-based access.
32 // The original references will go out of scope after this frame.
33 if(execution_count <= 1)
34 {
35 detach();
36 }
37}
38
40{
41 if(instance.impl->setter(instance, old_value, execution_count))
42 {
43 if(on_success)
44 {
45 on_success();
46 }
47 }
48}
49
54
55auto property_action_t::is_mergeable(const editing_action_t& previous) const -> bool
56{
57 const auto& prev = static_cast<const property_action_t&>(previous);
58 entt::meta_any inst;
59 instance.impl->getter(inst);
60 entt::meta_any prev_inst;
61 prev.instance.impl->getter(prev_inst);
62 return inst == prev_inst;
63}
64
66{
67 const auto& prev = static_cast<const property_action_t&>(previous);
68 old_value.assign(prev.old_value);
69}
70
71auto property_action_t::is_valid() const -> bool
72{
73 entt::meta_any inst;
74 instance.impl->getter(inst);
75
76 return !!inst;
77}
78
80{
81 draw_in_inspector_impl(ctx, old_value, new_value, custom);
82}
83
84} // namespace unravel
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
auto is_mergeable(const editing_action_t &previous) const -> bool override
void draw_in_inspector(rtti::context &ctx) override
property_action_t(meta_any_proxy inst, const entt::meta_any &old_val, const entt::meta_any &new_val, const entt::meta_custom &custom={}, const std::function< void()> &on_success={})
void merge_with(const editing_action_t &previous) override
std::function< void()> on_success
auto is_valid() const -> bool override