|
7 | 7 |
|
8 | 8 | #include <memory> |
9 | 9 | #include <string> |
| 10 | +#include <vector> |
10 | 11 |
|
11 | 12 | #include "Core/DPIHandler.hpp" |
12 | 13 | #include "Core/Debug/Instrumentor.hpp" |
@@ -105,50 +106,77 @@ ExitStatus App::Application::run() { |
105 | 106 | ImGui::NewFrame(); |
106 | 107 |
|
107 | 108 | if (!m_minimized) { |
108 | | - ImGui::DockSpaceOverViewport(); |
109 | | - |
110 | | - if (ImGui::BeginMainMenuBar()) { |
111 | | - if (ImGui::BeginMenu("File")) { |
112 | | - if (ImGui::MenuItem("Exit", "Cmd+Q")) { |
113 | | - stop(); |
114 | | - } |
115 | | - ImGui::EndMenu(); |
116 | | - } |
117 | | - if (ImGui::BeginMenu("View")) { |
118 | | - ImGui::MenuItem("Some Panel", nullptr, &m_show_some_panel); |
119 | | - ImGui::MenuItem("ImGui Demo Panel", nullptr, &m_show_demo_panel); |
120 | | - ImGui::MenuItem("Debug Panels", nullptr, &m_show_debug_panel); |
121 | | - ImGui::EndMenu(); |
122 | | - } |
123 | | - |
124 | | - ImGui::EndMainMenuBar(); |
125 | | - } |
| 109 | + const ImGuiViewport* viewport = ImGui::GetMainViewport(); |
| 110 | + const ImVec2 base_pos = viewport->Pos; |
| 111 | + const ImVec2 base_size = viewport->Size; |
| 112 | + |
| 113 | + // Left Pane (expression) |
| 114 | + { |
| 115 | + ImGui::SetNextWindowPos(base_pos); |
| 116 | + ImGui::SetNextWindowSize(ImVec2(base_size.x * 0.25f, base_size.y)); |
| 117 | + ImGui::Begin("Left Pane", |
| 118 | + nullptr, |
| 119 | + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | |
| 120 | + ImGuiWindowFlags_NoTitleBar); |
| 121 | + |
| 122 | + static char text[1024] = "y = sin(x)"; |
| 123 | + ImGui::InputTextMultiline( |
| 124 | + "##search", text, sizeof(text), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 4)); |
126 | 125 |
|
127 | | - // Whatever GUI to implement here ... |
128 | | - if (m_show_some_panel) { |
129 | | - ImGui::Begin("Some panel", &m_show_some_panel); |
130 | | - ImGui::Text("Hello World"); |
131 | 126 | ImGui::End(); |
132 | 127 | } |
133 | 128 |
|
134 | | - // ImGUI demo panel |
135 | | - if (m_show_demo_panel) { |
136 | | - ImGui::ShowDemoWindow(&m_show_demo_panel); |
137 | | - } |
| 129 | + // Right Pane (Graphing Area) |
| 130 | + { |
| 131 | + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); |
| 132 | + ImGui::SetNextWindowPos(ImVec2(base_pos.x + base_size.x * 0.25f, base_pos.y)); |
| 133 | + ImGui::SetNextWindowSize(ImVec2(base_size.x * 0.75f, base_size.y)); |
| 134 | + ImGui::Begin("Right Pane", |
| 135 | + nullptr, |
| 136 | + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | |
| 137 | + ImGuiWindowFlags_NoTitleBar); |
| 138 | + |
| 139 | + ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
| 140 | + |
| 141 | + // Define the graphing area within the window |
| 142 | + const ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); // Top-left corner of the window |
| 143 | + const ImVec2 canvas_sz = ImGui::GetContentRegionAvail(); // Size of the window |
| 144 | + const auto canvas_p1 = |
| 145 | + ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y); // Bottom-right |
| 146 | + |
| 147 | + // Define your coordinate system origin (e.g., center of the canvas) |
| 148 | + const ImVec2 origin(canvas_p0.x + canvas_sz.x * 0.5f, canvas_p0.y + canvas_sz.y * 0.5f); |
| 149 | + |
| 150 | + float lineThickness = 4.0f; |
| 151 | + |
| 152 | + // 1. Draw Axes |
| 153 | + draw_list->AddLine(ImVec2(canvas_p0.x, origin.y), |
| 154 | + ImVec2(canvas_p1.x, origin.y), |
| 155 | + IM_COL32(0, 0, 0, 255), |
| 156 | + lineThickness); // X-axis |
| 157 | + draw_list->AddLine(ImVec2(origin.x, canvas_p0.y), |
| 158 | + ImVec2(origin.x, canvas_p1.y), |
| 159 | + IM_COL32(0, 0, 0, 255), |
| 160 | + lineThickness); // Y-axis |
| 161 | + |
| 162 | + // 2. Plot a function (e.g., y = sin(x)) |
| 163 | + const float zoom = 100.0f; // Pixels per unit |
| 164 | + std::vector<ImVec2> points; |
| 165 | + for (float x = -canvas_sz.x / (2 * zoom); x < canvas_sz.x / (2 * zoom); x += 0.1f) { |
| 166 | + float y = sin(x); |
| 167 | + |
| 168 | + // Convert graph coordinates to screen coordinates |
| 169 | + // Y is inverted because screen coordinates go down |
| 170 | + ImVec2 screen_pos(origin.x + x * zoom, origin.y - y * zoom); |
| 171 | + points.push_back(screen_pos); |
| 172 | + } |
| 173 | + |
| 174 | + // Draw the function as a polyline |
| 175 | + draw_list->AddPolyline( |
| 176 | + points.data(), points.size(), IM_COL32(255, 0, 0, 255), ImDrawFlags_None, lineThickness); |
138 | 177 |
|
139 | | - // Debug panel |
140 | | - if (m_show_debug_panel) { |
141 | | - ImGui::ShowMetricsWindow(); |
142 | | - ImGui::ShowDebugLogWindow(); |
143 | | - |
144 | | - ImGui::Begin("App debug panel", &m_show_debug_panel); |
145 | | - ImGui::Text("User config path: %s", user_config_path.c_str()); |
146 | | - ImGui::Separator(); |
147 | | - ImGui::Text("Font path: %s", font_path.c_str()); |
148 | | - ImGui::Text("Font size: %f", font_size); |
149 | | - ImGui::Text("Global font scaling %f", io.FontGlobalScale); |
150 | | - ImGui::Text("UI scaling factor: %f", font_scaling_factor); |
151 | 178 | ImGui::End(); |
| 179 | + ImGui::PopStyleColor(); |
152 | 180 | } |
153 | 181 | } |
154 | 182 |
|
|
0 commit comments