logmeow/windows/debug.cpp

54 lines
1.8 KiB
C++

#include <imgui.cpp>
#include "../myimconfig.h"
#include "../log.h"
#include "../logcat_thread.h"
#include "debug.h"
void debug_window(LogcatThread& logcat_thread) {
static bool show_demo_window = false;
static size_t add_log_entry_presses = 1;
static bool log_entry_every_second = false;
static float log_entry_every_second_delta;
if (show_demo_window) {
ImGui::ShowDemoWindow(&show_demo_window);
}
if (!ImGui::Begin("LogMeow Debug")) {
ImGui::End();
return;
}
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::Checkbox("Show Dear ImGui Demo Window", &show_demo_window);
ImGui::Separator();
if (ImGui::Button("Add Log Entry")) {
log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated via manual button press)");
}
ImGui::SameLine();
// returns true when it's pressed
if (ImGui::Checkbox("Add log entry every second", &log_entry_every_second)) {
log_entry_every_second_delta = 0.0f;
}
if (ImGui::Button("Add Log Entry with Newlines")) {
log("The following should have five spaces: \"\n\n\n\n\n\"");
}
if (ImGui::Button("Test user assert")) {
IM_ASSERT_USER_ERROR(0, "User assert tested");
}
if (ImGui::Button("Request log entry from Logcat thread")) {
logcat_thread.debug_log_request.test_and_set();
}
if (log_entry_every_second) {
log_entry_every_second_delta += ImGui::GetIO().DeltaTime;
if (log_entry_every_second_delta >= 1.0f) {
log_entry_every_second_delta = 0.0f;
log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated by add log entry every second)");
}
}
ImGui::End();
}