mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-15 01:05:06 +00:00
77 lines
2.3 KiB
C++
77 lines
2.3 KiB
C++
#include "gui.h"
|
|
#include "../ta-log.h"
|
|
#include <imgui.h>
|
|
|
|
const char* logLevels[5]={
|
|
"ERROR",
|
|
"warning",
|
|
"info",
|
|
"debug",
|
|
"trace"
|
|
};
|
|
|
|
FurnaceGUIColors logColors[5]={
|
|
GUI_COLOR_LOGLEVEL_ERROR,
|
|
GUI_COLOR_LOGLEVEL_WARNING,
|
|
GUI_COLOR_LOGLEVEL_INFO,
|
|
GUI_COLOR_LOGLEVEL_DEBUG,
|
|
GUI_COLOR_LOGLEVEL_TRACE
|
|
};
|
|
|
|
void FurnaceGUI::drawLog() {
|
|
if (nextWindow==GUI_WINDOW_LOG) {
|
|
logOpen=true;
|
|
ImGui::SetNextWindowFocus();
|
|
nextWindow=GUI_WINDOW_NOTHING;
|
|
}
|
|
if (!logOpen) return;
|
|
if (ImGui::Begin("Log Viewer",&logOpen)) {
|
|
ImGui::Checkbox("Follow",&followLog);
|
|
ImGui::SameLine();
|
|
ImGui::Text("Level");
|
|
ImGui::SameLine();
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
|
ImGui::Combo("##LogLevel",&logLevel,logLevels,5);
|
|
if (ImGui::BeginTable("LogView",3,ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersInnerV)) {
|
|
ImGui::PushFont(patFont);
|
|
|
|
float timeChars=ImGui::CalcTextSize("00:00:00").x;
|
|
float levelChars=ImGui::CalcTextSize("warning").x;
|
|
|
|
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,timeChars);
|
|
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed,levelChars);
|
|
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch);
|
|
|
|
ImGui::TableSetupScrollFreeze(0,1);
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
|
ImGui::TableNextColumn();
|
|
ImGui::TextUnformatted("time");
|
|
ImGui::TableNextColumn();
|
|
ImGui::TextUnformatted("level");
|
|
ImGui::TableNextColumn();
|
|
ImGui::TextUnformatted("message");
|
|
|
|
int pos=logPosition;
|
|
for (int i=0; i<TA_LOG_SIZE; i++) {
|
|
const LogEntry& logEntry=logEntries[(pos+i)&(TA_LOG_SIZE-1)];
|
|
if (!logEntry.ready) continue;
|
|
if (logLevel<logEntry.loglevel) continue;
|
|
ImGui::TableNextRow();
|
|
ImGui::TableNextColumn();
|
|
ImGui::Text("%02d:%02d:%02d",logEntry.time.tm_hour,logEntry.time.tm_min,logEntry.time.tm_sec);
|
|
ImGui::TableNextColumn();
|
|
ImGui::TextColored(uiColors[logColors[logEntry.loglevel]],"%s",logLevels[logEntry.loglevel]);
|
|
ImGui::TableNextColumn();
|
|
ImGui::TextWrapped("%s",logEntry.text.c_str());
|
|
}
|
|
ImGui::PopFont();
|
|
|
|
if (followLog) {
|
|
ImGui::SetScrollY(ImGui::GetScrollMaxY());
|
|
}
|
|
ImGui::EndTable();
|
|
}
|
|
}
|
|
ImGui::End();
|
|
}
|