93 lines
2.8 KiB
C++
93 lines
2.8 KiB
C++
#include <imgui.h>
|
|
#include <imgui_stdlib.h>
|
|
|
|
#include "config.h"
|
|
|
|
static inline void write_config_and_update_structures(const Config& config) {
|
|
try {
|
|
write_config(config);
|
|
} catch (const std::exception& e) {
|
|
// TODO log() when logging exists
|
|
throw;
|
|
}
|
|
}
|
|
|
|
static inline void settings_window(Config& config, float* config_write_timer, bool* show_settings_window) {
|
|
if (!ImGui::Begin("Settings", show_settings_window)) {
|
|
ImGui::End();
|
|
return;
|
|
}
|
|
// TODO actually have process control
|
|
ImGui::Text("Logcat command is only modifiable when logcat is stopped");
|
|
if (ImGui::InputTextWithHint("Logcat command", "adb logcat -Dv 'threadtime UTC epoch usec'", &config.logcat_command)) {
|
|
*config_write_timer = *config_write_timer > 0.0f ? *config_write_timer : 5.0f;
|
|
}
|
|
ImGui::End();
|
|
}
|
|
|
|
static inline void main_window(Config& active_config, bool* show_settings_window, bool* exit_requested_rev) {
|
|
if (!ImGui::Begin("LogMeow", exit_requested_rev)) {
|
|
ImGui::End();
|
|
return;
|
|
}
|
|
if (ImGui::Button("Settings")) {
|
|
*show_settings_window = true;
|
|
}
|
|
ImGui::End();
|
|
}
|
|
|
|
static inline void exit_modal_if_necessary(bool* run_event_loop) {
|
|
if (!ImGui::BeginPopupModal("Exit?", nullptr, ImGuiWindowFlags_NoResize)) {
|
|
return;
|
|
}
|
|
ImGui::Text("Are you sure you want to exit?");
|
|
|
|
if (ImGui::Button("Yes", ImVec2(120, 0))) {
|
|
*run_event_loop = false;
|
|
}
|
|
ImGui::SameLine();
|
|
if (ImGui::Button("No", ImVec2(120, 0))) {
|
|
ImGui::CloseCurrentPopup();
|
|
}
|
|
ImGui::SetItemDefaultFocus();
|
|
ImGui::EndPopup();
|
|
}
|
|
|
|
static inline void debug_window() {
|
|
static bool show_demo_window = false;
|
|
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::End();
|
|
}
|
|
|
|
void event_loop(Config& config, float* config_write_timer, bool* run_event_loop) {
|
|
static bool show_settings_window = false;
|
|
static bool exit_requested_rev = true;
|
|
|
|
if (show_settings_window) {
|
|
settings_window(config, config_write_timer, &show_settings_window);
|
|
}
|
|
if (*config_write_timer > 0.0f) {
|
|
*config_write_timer -= ImGui::GetIO().DeltaTime;
|
|
if (*config_write_timer <= 0.0f) {
|
|
write_config_and_update_structures(config);
|
|
}
|
|
}
|
|
|
|
if (!exit_requested_rev) {
|
|
ImGui::OpenPopup("Exit?");
|
|
exit_requested_rev = true;
|
|
}
|
|
exit_modal_if_necessary(run_event_loop);
|
|
main_window(config, &show_settings_window, &exit_requested_rev);
|
|
debug_window();
|
|
}
|