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} // namespace
51
53{
54 show_request_ = s;
55}
56
58{
59 if(show_request_)
60 {
61 ImGui::OpenPopup(name);
62 show_request_ = false;
63 }
64
65 ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size * 0.5f);
66 bool show = true;
67 if(ImGui::BeginPopupModal(name, &show))
68 {
69 // ImGui::WindowTimeBlock block(ImGui::GetFont(ImGui::Font::Mono));
70
71 draw_ui(ctx);
72
73 ImGui::EndPopup();
74 }
75}
76
77void editor_settings_panel::draw_ui(rtti::context& ctx)
78{
79 auto avail = ImGui::GetContentRegionAvail();
80 if(avail.x < 1.0f || avail.y < 1.0f)
81 {
82 return;
83 }
84
85 static std::vector<setting_entry> categories{{"External Tools", &draw_external_tools_settings},
86 {"Debugger", &draw_debugger_settings}};
87 // Child A: the categories list
88 // We fix the width of this child, so the right child uses the remaining space.
89 ImGui::BeginChild("##LeftSidebar", avail * ImVec2(0.15f, 1.0f), ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeX);
90 {
91 // Display categories
92 for(const auto& category : categories)
93 {
94 // 'Selectable' returns true if clicked
95 if(ImGui::Selectable(category.id.c_str(), (selected_entry_.id == category.id)))
96 {
97 selected_entry_ = category;
98 }
99 }
100 }
101 ImGui::EndChild();
102
103 // On the same line:
104 ImGui::SameLine();
105
106 // Child B: show settings for the selected category
107 ImGui::BeginChild("##RightContent");
108 {
109 if(selected_entry_.callback)
110 {
111 selected_entry_.callback(ctx);
112 }
113 }
114 ImGui::EndChild();
115}
116
117} // 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:27
auto inspect(rtti::context &ctx, T &obj) -> inspect_result
Convenience template function for inspecting objects of known type.
Definition inspectors.h:393
auto get_cached() -> T &
Definition context.hpp:49