Unravel Engine C++ Reference
Loading...
Searching...
No Matches
inspector_alignment.cpp
Go to the documentation of this file.
2#include "imgui/imgui.h"
3#include "inspectors.h"
4
5namespace unravel
6{
7namespace
8{
9struct align_info
10{
11 const char* icon;
12 uint32_t flag;
13 const char* tooltip;
14};
15
16constexpr align_info haligns[] = {
20};
21
22constexpr align_info valigns[] = {
29};
30} // namespace
31
33 entt::meta_any& var,
34 const meta_any_proxy& var_proxy,
35 const var_info& info,
36 const entt::meta_custom& custom) -> inspect_result
37{
38 auto data = var.cast<alignment>();
39
40 // fetch current
41 uint32_t alignment = data.flags;
42
43 // Horizontal row
44 for(auto [icon, flag, tooltip] : haligns)
45 {
46 bool active = (alignment & flag) != 0;
47
48 if(ImGui::Button(icon))
49 {
50 // Clear only the H bits, leave the V bits untouched
52 }
53 if(active)
54 ImGui::RenderFocusFrame(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
55
56 ImGui::SetItemTooltipEx("%s", tooltip);
57 ImGui::SameLine();
58 }
59 ImGui::NewLine();
60
61 // Vertical row
62 for(auto [icon, flag, tooltip] : valigns)
63 {
64 bool active = (alignment & flag) != 0;
65
66 if(ImGui::Button(icon))
67 {
68 // Clear only the V bits, leave the H bits untouched
70 }
71 if(active)
72 ImGui::RenderFocusFrame(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
73
74 ImGui::SetItemTooltipEx("%s", tooltip);
75
76 ImGui::SameLine();
77 }
78
79 inspect_result result{};
80 // write back if changed
81 result.changed = alignment != data.flags;
82
83 if(result.changed)
84 {
85 result.edit_finished |= true;
86
87 data.flags = alignment;
88 var = data;
89 }
90
91 return result;
92}
93
94namespace
95{
96struct style_info
97{
98 const char* icon;
99 uint32_t flag;
100 const char* tooltip;
101};
102
103constexpr style_info style_flags[] = {
109};
110} // namespace
111
112
114 entt::meta_any& var,
115 const meta_any_proxy& var_proxy,
116 const var_info& info,
117 const entt::meta_custom& custom) -> inspect_result
118{
119 auto data = var.cast<text_style_flags>();
120
121 inspect_result result;
122 for(auto [icon, flag, tooltip] : style_flags)
123 {
124 bool active = (data.flags & flag) != 0;
125 if(ImGui::Button(icon))
126 {
127 data.flags ^= flag;
128 result.changed = true;
129 }
130 if(active)
131 ImGui::RenderFocusFrame(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
132 ImGui::SetItemTooltipEx("%s", tooltip);
133 ImGui::SameLine();
134 }
135
136 if(result.changed)
137 {
138 var = data;
139 }
140
141 return result;
142}
143
144void inspector_text_style::before_inspect(const entt::meta_data& prop)
145{
146 layout_ = std::make_unique<property_layout>();
147 layout_->set_data(prop, false);
148 open_ = layout_->push_tree_layout(ImGuiTreeNodeFlags_SpanFullWidth);
149}
150
152 entt::meta_any& var,
153 const meta_any_proxy& var_proxy,
154 const var_info& info,
155 const entt::meta_custom& custom) -> inspect_result
156{
157 if(!open_)
158 {
159 return {};
160 }
161 // Pull out a mutable copy
162 auto result = inspect_var_properties(ctx, var, var_proxy, info, custom);
163
164 return result;
165}
166
167} // namespace unravel
#define ICON_MDI_ALIGN_VERTICAL_BOTTOM
#define ICON_MDI_FORMAT_COLOR_TEXT
#define ICON_MDI_FORMAT_ALIGN_BOTTOM
#define ICON_MDI_FORMAT_ALIGN_RIGHT
#define ICON_MDI_FORMAT_COLOR_FILL
#define ICON_MDI_FORMAT_UNDERLINE
#define ICON_MDI_FORMAT_ALIGN_TOP
#define ICON_MDI_FORMAT_STRIKETHROUGH_VARIANT
#define ICON_MDI_FORMAT_ALIGN_LEFT
#define ICON_MDI_FORMAT_ALIGN_MIDDLE
#define ICON_MDI_ALIGN_VERTICAL_TOP
#define ICON_MDI_FORMAT_ALIGN_CENTER
#define ICON_MDI_ALIGN_VERTICAL_CENTER
#define ICON_MDI_FORMAT_OVERLINE
const char * tooltip
const char * icon
uint32_t flag
@ style_strike_through
@ vertical_text_mask
auto inspect_var_properties(rtti::context &ctx, entt::meta_any &var, const meta_any_proxy &var_proxy, const var_info &info, const entt::meta_custom &custom) -> inspect_result
Inspects all properties of a complex object recursively.
Result of an inspection operation indicating what changes occurred.
Definition inspector.h:146
bool changed
Whether the value was modified during inspection.
Definition inspector.h:148
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
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
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
void before_inspect(const entt::meta_data &prop) override
Safe deferred property access proxy for arbitrary object properties.
Definition inspector.h:198
Metadata about a variable being inspected.
Definition inspector.h:133