Unravel Engine C++ Reference
Loading...
Searching...
No Matches
editor_settings_panel.cpp
Go to the documentation of this file.
2#include "../panel.h"
3
7
8#include <filedialog/filedialog.h>
9#include <imgui/imgui.h>
10#include <imgui/imgui_internal.h>
11
12namespace unravel
13{
14namespace
15{
16void draw_external_tools_settings(rtti::context& ctx)
17{
18 auto& pm = ctx.get_cached<project_manager>();
19 auto& settings = pm.get_editor_settings();
20
21 ImGui::PushItemWidth(150.0f);
22
23 if(inspect(ctx, settings.external_tools).edit_finished)
24 {
25 pm.save_project_settings(ctx);
26 }
27
28 ImGui::PopItemWidth();
29}
30
31void draw_debugger_settings(rtti::context& ctx)
32{
33 auto& pm = ctx.get_cached<project_manager>();
34 auto& settings = pm.get_editor_settings();
35
36 ImGui::PushItemWidth(150.0f);
37
38 if(inspect(ctx, settings.debugger).edit_finished)
39 {
40 pm.save_project_settings(ctx);
41 }
42
43 ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "%s", "Requires an editor restart to apply changes.");
44
45 ImGui::PopItemWidth();
46}
47
48void draw_scripting_settings(rtti::context& ctx)
49{
50 auto& pm = ctx.get_cached<project_manager>();
51 auto& settings = pm.get_editor_settings();
52
53 ImGui::PushItemWidth(150.0f);
54
55 if(inspect(ctx, settings.scripting).edit_finished)
56 {
57 settings.scripting.reload_app_domain = true;
58 pm.save_editor_settings();
59 }
60
61 ImGui::PopItemWidth();
62}
63} // namespace
67
69{
70 show_request_ = s;
71}
72
74{
75 if(show_request_)
76 {
77 ImGui::OpenPopup(name);
78 show_request_ = false;
79 }
80
81 ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size * 0.5f);
82 bool show = true;
83 if(ImGui::BeginPopupModal(name, &show))
84 {
85 // ImGui::WindowTimeBlock block(ImGui::GetFont(ImGui::Font::Mono));
86
87 draw_ui(ctx);
88
89 ImGui::EndPopup();
90 }
91}
92
93void editor_settings_panel::draw_ui(rtti::context& ctx)
94{
95 auto avail = ImGui::GetContentRegionAvail();
96 if(avail.x < 1.0f || avail.y < 1.0f)
97 {
98 return;
99 }
100
101 static std::vector<setting_entry> categories{
102 {"External Tools", &draw_external_tools_settings},
103 {"Scripting", &draw_scripting_settings},
104#if DOTNETPP_BACKEND_MONO
105 {"Debugger", &draw_debugger_settings},
106#endif
107 };
108 // Child A: the categories list
109 // We fix the width of this child, so the right child uses the remaining space.
110 ImGui::BeginChild("##LeftSidebar", avail * ImVec2(0.15f, 1.0f), ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeX);
111 {
112 // Display categories
113 for(const auto& category : categories)
114 {
115 // 'Selectable' returns true if clicked
116 if(ImGui::Selectable(category.id.c_str(), (selected_entry_.id == category.id)))
117 {
118 selected_entry_ = category;
119 }
120 }
121 }
122 ImGui::EndChild();
123
124 // On the same line:
125 ImGui::SameLine();
126
127 // Child B: show settings for the selected category
128 ImGui::BeginChild("##RightContent");
129 {
130 if(selected_entry_.callback)
131 {
132 selected_entry_.callback(ctx);
133 }
134 }
135 ImGui::EndChild();
136}
137
138} // namespace unravel
editor_settings_panel(imgui_panels *parent)
void on_frame_ui_render(rtti::context &ctx, const char *name)
std::string name
Definition hub.cpp:33
std::vector< size_t > parent_
auto inspect(rtti::context &ctx, T &obj, const std::string &name={}) -> inspect_result
Convenience template function for inspecting objects of known type.
Definition inspectors.h:402
auto get_cached() -> T &
Definition context.hpp:49