Make logs button red when there are unread log entries

This commit is contained in:
blankie 2023-01-05 21:23:24 +07:00
parent df3ee3366f
commit 21badd1db4
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 22 additions and 4 deletions

View File

@ -27,7 +27,7 @@ static inline void settings_window(Config& config, float* config_write_timer, bo
ImGui::End();
}
static inline void logs_window(bool* show_logs_window) {
static inline void logs_window(bool* latest_log_entries_read, bool* show_logs_window) {
if (!ImGui::Begin("LogMeow Logs", show_logs_window)) {
ImGui::End();
return;
@ -46,6 +46,7 @@ static inline void logs_window(bool* show_logs_window) {
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) {
ImGui::TextUnformatted(log_entries.data(), &log_entries[log_entries.size()]);
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
*latest_log_entries_read = true;
ImGui::SetScrollHereY(1.0f);
}
}
@ -53,18 +54,29 @@ static inline void logs_window(bool* show_logs_window) {
ImGui::End();
}
static inline void main_window(bool* show_settings_window, bool* show_logs_window, bool* run_event_loop) {
static inline void main_window(bool latest_log_entries_read, bool* show_settings_window, bool* show_logs_window, bool* run_event_loop) {
if (!ImGui::Begin("LogMeow", run_event_loop)) {
ImGui::End();
return;
}
if (ImGui::Button("Settings")) {
*show_settings_window = true;
}
ImGui::SameLine();
if (!latest_log_entries_read) {
ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(0.0f, 0.6f, 0.6f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(0.0f, 0.7f, 0.7f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(0.0f, 0.8f, 0.8f));
}
if (ImGui::Button("Logs")) {
*show_logs_window = true;
}
if (!latest_log_entries_read) {
ImGui::PopStyleColor(3);
}
ImGui::End();
}
@ -110,6 +122,7 @@ static inline void debug_window() {
void event_loop(Config& config, float* config_write_timer, bool* run_event_loop) {
static bool show_settings_window = false;
static bool show_logs_window = false;
static size_t log_entries_read = 0;
debug_window();
@ -124,8 +137,13 @@ void event_loop(Config& config, float* config_write_timer, bool* run_event_loop)
}
if (show_logs_window) {
logs_window(&show_logs_window);
bool latest_log_entries_read = false;
logs_window(&latest_log_entries_read, &show_logs_window);
if (latest_log_entries_read) {
log_entries_read = log_entries.size();
}
}
main_window(&show_settings_window, &show_logs_window, run_event_loop);
// log_entries must not be mutated until the show logs button
main_window(log_entries_read == log_entries.size(), &show_settings_window, &show_logs_window, run_event_loop);
}