载入中...
搜索中...
未找到
ImGuiHostPanels.cpp
浏览该文件的文档.
3
4#include <imgui.h>
5
6// Desktop-only host registration: draws the DevTools AI / console ImGui windows.
7// Kept outside EVDevTools (which avoids imgui.h inlines → MSVC 65535 export
8// bloat); compiled into the `eve` host executable, where imgui is linked.
9//
10// The panels are rendered between `ui.beginFrameAndRender()` and
11// `gfx.present()` (load.nut calls eve.dev.ai.draw() / eve.dev.console.draw()).
12
13#if !defined(EVENGINE_ANDROID) && !defined(EVENGINE_IOS) && !defined(EVENGINE_WEBGPU)
14
15namespace eve::dev {
16namespace {
17
18void drawAiWindow(AiPanel& panel) {
19 if (!panel.isVisible()) return;
20 bool visible = panel.isVisible();
21 if (ImGui::Begin("AI / MCP", &visible, ImGuiWindowFlags_AlwaysAutoResize)) {
22 ImGui::TextUnformatted(panel.statusLine().c_str());
23 ImGui::Separator();
24 const auto log = panel.recentLog(64);
25 if (ImGui::BeginChild("ai_log", ImVec2(480, 260), true)) {
26 for (const auto& e : log) {
27 ImGui::TextWrapped("[%s] %s | %s", e.timestamp.c_str(), e.kind.c_str(),
28 e.title.c_str());
29 if (!e.detail.empty()) ImGui::TextWrapped(" %s", e.detail.c_str());
30 }
31 if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
32 ImGui::SetScrollHereY(1.0f);
33 }
34 ImGui::EndChild();
35 if (ImGui::Button("Clear")) panel.clearLog();
36 ImGui::SameLine();
37 if (ImGui::Button("Hide")) panel.setVisible(false);
38 }
39 ImGui::End();
40 if (!visible) panel.setVisible(false);
41}
42
43// Draw the console: scrolling log + Squirrel REPL input line.
44void drawConsoleWindow(ConsolePanel& panel) {
45 if (!panel.isVisible()) return;
46 bool visible = panel.isVisible();
47 if (ImGui::Begin("Console", &visible,
48 ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoScrollbar)) {
49 if (ImGui::BeginMenuBar()) {
50 if (ImGui::BeginMenu("Log")) {
51 if (ImGui::MenuItem("Clear")) panel.clear();
52 if (ImGui::MenuItem("Copy all"))
53 ImGui::SetClipboardText(panel.format(4096).c_str());
54 ImGui::EndMenu();
55 }
56 ImGui::EndMenuBar();
57 }
58
59 ImGui::BeginChild("console_log", ImVec2(0, ImGui::GetContentRegionAvail().y - 30),
60 true);
61 const auto lines = panel.recent(500);
62 for (const auto& l : lines) {
63 ImVec4 color = ImVec4(0.80f, 0.80f, 0.80f, 1.0f);
64 if (l.level == "error")
65 color = ImVec4(1.0f, 0.35f, 0.35f, 1.0f);
66 else if (l.level == "warn")
67 color = ImVec4(1.0f, 0.85f, 0.35f, 1.0f);
68 else if (l.level == "cmd" || l.level == "result")
69 color = ImVec4(0.45f, 0.80f, 1.0f, 1.0f);
70 ImGui::PushStyleColor(ImGuiCol_Text, color);
71 ImGui::TextUnformatted(("[" + l.timestamp + "] " + l.level + " | " + l.text).c_str());
72 ImGui::PopStyleColor();
73 }
74 if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) ImGui::SetScrollHereY(1.0f);
75 ImGui::EndChild();
76
77 static char input[512] = "";
78 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 90);
79 const bool enter = ImGui::InputText("##repl", input, sizeof(input),
80 ImGuiInputTextFlags_EnterReturnsTrue);
81 ImGui::SameLine();
82 if (ImGui::Button("Run") || enter) {
83 std::string expr = input;
84 if (!expr.empty()) {
85 const std::string result = panel.eval(expr);
86 ImGui::SetClipboardText(result.c_str());
87 }
88 input[0] = '\0';
89 }
90 if (ImGui::Button("Hide")) panel.setVisible(false);
91 }
92 ImGui::End();
93 if (!visible) panel.setVisible(false);
94}
95
96struct HostPanels {
97 HostPanels() {
98 AiPanel::setImGuiDrawer(&drawAiWindow);
99 ConsolePanel::setImGuiDrawer(&drawConsoleWindow);
100 }
101};
102
103} // namespace
104} // namespace eve::dev
105
106static eve::dev::HostPanels gHostPanels;
107
108#endif
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
image::ImageData::Colorf color
static void setImGuiDrawer(ImGuiDrawer fn)
Definition AiPanel.cpp:138
static void setImGuiDrawer(ImGuiDrawer fn)