Add "Add log entry every second"

This commit is contained in:
blankie 2023-01-05 20:53:34 +07:00
parent 11eb08b08f
commit 8a0d2b428e
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 19 additions and 1 deletions

View File

@ -71,6 +71,8 @@ static inline void main_window(Config& active_config, bool* show_settings_window
static inline void debug_window() { static inline void debug_window() {
static bool show_demo_window = false; static bool show_demo_window = false;
static size_t add_log_entry_presses = 1; 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) { if (show_demo_window) {
ImGui::ShowDemoWindow(&show_demo_window); ImGui::ShowDemoWindow(&show_demo_window);
@ -79,13 +81,29 @@ static inline void debug_window() {
ImGui::End(); ImGui::End();
return; return;
} }
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); 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::Checkbox("Show Dear ImGui Demo Window", &show_demo_window);
ImGui::Separator(); ImGui::Separator();
if (ImGui::Button("Add Log Entry")) { if (ImGui::Button("Add Log Entry")) {
std::exception e; std::exception e;
log(std::string("Add log entry button pressed ") + std::to_string(add_log_entry_presses++) + " time(s)", e); log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated via manual button press)", e);
} }
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 (log_entry_every_second) {
log_entry_every_second_delta += ImGui::GetIO().DeltaTime;
if (log_entry_every_second_delta >= 1.0f) {
std::exception e;
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)", e);
}
}
ImGui::End(); ImGui::End();
} }