添加D3D12 ImGui编辑器UI框架
This commit is contained in:
77
ui/src/panels/ConsolePanel.cpp
Normal file
77
ui/src/panels/ConsolePanel.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "ConsolePanel.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace UI {
|
||||
|
||||
ConsolePanel::ConsolePanel() : Panel("Console") {
|
||||
m_logs.push_back({LogEntry::Level::Info, "Engine initialized successfully"});
|
||||
m_logs.push_back({LogEntry::Level::Info, "Loading default scene..."});
|
||||
m_logs.push_back({LogEntry::Level::Warning, "Missing material on object 'Cube'"});
|
||||
m_logs.push_back({LogEntry::Level::Error, "Failed to load texture: 'Assets/Textures/missing.png'"});
|
||||
m_logs.push_back({LogEntry::Level::Info, "Scene loaded successfully"});
|
||||
}
|
||||
|
||||
void ConsolePanel::Render() {
|
||||
ImGui::Begin(m_name.c_str(), &m_isOpen, ImGuiWindowFlags_None);
|
||||
|
||||
if (ImGui::Button("Clear")) {
|
||||
Clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Info")) {
|
||||
AddLog(LogEntry::Level::Info, "Test info message");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Warn")) {
|
||||
AddLog(LogEntry::Level::Warning, "Test warning message");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Error")) {
|
||||
AddLog(LogEntry::Level::Error, "Test error message");
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::BeginChild("LogScroll", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
|
||||
for (const auto& log : m_logs) {
|
||||
ImVec4 color;
|
||||
const char* prefix;
|
||||
|
||||
switch (log.level) {
|
||||
case LogEntry::Level::Info:
|
||||
color = ImVec4(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
prefix = "[Info] ";
|
||||
break;
|
||||
case LogEntry::Level::Warning:
|
||||
color = ImVec4(1.0f, 0.8f, 0.0f, 1.0f);
|
||||
prefix = "[Warn] ";
|
||||
break;
|
||||
case LogEntry::Level::Error:
|
||||
color = ImVec4(1.0f, 0.3f, 0.3f, 1.0f);
|
||||
prefix = "[Error]";
|
||||
break;
|
||||
}
|
||||
|
||||
ImGui::TextColored(color, "%s%s", prefix, log.message.c_str());
|
||||
}
|
||||
|
||||
if (m_scrollToBottom) {
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
m_scrollToBottom = false;
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ConsolePanel::AddLog(LogEntry::Level level, const std::string& message) {
|
||||
m_logs.push_back({level, message});
|
||||
m_scrollToBottom = true;
|
||||
}
|
||||
|
||||
void ConsolePanel::Clear() {
|
||||
m_logs.clear();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user