#include #include #include "config.h" static inline void settings_window(Config& inactive_config, bool* show_settings_window) { // by default, the settings window is a bit cramped ImGui::SetNextWindowSize(ImVec2(575, 75), ImGuiCond_FirstUseEver); if (!ImGui::Begin("Settings", show_settings_window)) { ImGui::End(); return; } ImGui::Text("Persistence coming soon(tm)"); ImGui::InputTextWithHint("Logcat command", "adb logcat -Dv 'threadtime UTC epoch usec'", &inactive_config.logcat_command); ImGui::End(); } static inline void main_window(Config& active_config, Config& inactive_config, bool* show_demo_window, bool* show_settings_window, bool* save_settings_when_settings_window_closed, bool* exit_requested_rev) { if (!ImGui::Begin("LogMeow", exit_requested_rev)) { ImGui::End(); return; } ImGui::Checkbox("Show Dear ImGui Demo Window", show_demo_window); if (ImGui::Button("Settings")) { if (!*show_settings_window) { inactive_config = active_config; } *show_settings_window = true; *save_settings_when_settings_window_closed = true; } ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::End(); } static inline void exit_modal_if_necessary(bool* run_event_loop) { if (ImGui::BeginPopupModal("Exit?", nullptr, ImGuiWindowFlags_NoResize)) { 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(); } } void event_loop(Config& active_config, bool* run_event_loop) { static bool show_demo_window = false; static bool show_settings_window = false; static bool save_settings_when_settings_window_closed = false; static bool exit_requested_rev = true; static Config inactive_config; if (show_demo_window) { ImGui::ShowDemoWindow(&show_demo_window); } if (show_settings_window) { settings_window(inactive_config, &show_settings_window); } else if (save_settings_when_settings_window_closed) { active_config = inactive_config; } if (!exit_requested_rev) { ImGui::OpenPopup("Exit?"); exit_requested_rev = true; } exit_modal_if_necessary(run_event_loop); main_window(active_config, inactive_config, &show_demo_window, &show_settings_window, &save_settings_when_settings_window_closed, &exit_requested_rev); }