diff --git a/misc.cpp b/misc.cpp index 6da5a7a..697fce1 100644 --- a/misc.cpp +++ b/misc.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "misc.h" @@ -31,3 +32,18 @@ void throw_system_error(const char* what) { void throw_system_error(std::string what) { throw_system_error(errno, std::move(what)); } + +void ImGui::TextUnformatted(const std::string& str) { + ImGui::TextUnformatted(str.data(), &str.data()[str.size()]); +} + +bool ImGui::RedButton(const char* label) { + 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)); + + int res = ImGui::Button(label); + + ImGui::PopStyleColor(3); + return res; +} diff --git a/misc.h b/misc.h index e97db12..46e1b8d 100644 --- a/misc.h +++ b/misc.h @@ -1,8 +1,14 @@ #pragma once +#include #include std::string quote(const std::string& str); void throw_system_error(int err, const char* what); void throw_system_error(const char* what); void throw_system_error(std::string what); + +namespace ImGui { + void TextUnformatted(const std::string& str); + bool RedButton(const char* text); +}; // namespace ImGui diff --git a/windows/logs.cpp b/windows/logs.cpp index f77a76b..a39e2ba 100644 --- a/windows/logs.cpp +++ b/windows/logs.cpp @@ -1,6 +1,7 @@ #include #include +#include "../misc.h" #include "../log.h" #include "logs.h" @@ -28,7 +29,7 @@ static inline void render_table(ImFont* monospace_font, bool* autoscrolling) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(time_as_str); - ImGui::TableSetColumnIndex(1); ImGui::TextUnformatted(log_entry->message.data(), &log_entry->message.data()[log_entry->message.size()]); + ImGui::TableSetColumnIndex(1); ImGui::TextUnformatted(log_entry->message); } } clipper.End(); diff --git a/windows/main.cpp b/windows/main.cpp index e0d8690..30e66dd 100644 --- a/windows/main.cpp +++ b/windows/main.cpp @@ -3,6 +3,7 @@ #include #include +#include "../misc.h" #include "../logcat_entry.h" #include "main.h" @@ -34,14 +35,14 @@ static inline void render_table(ImFont* monospace_font, std::vector ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(time_as_str); if (logcat_entry->user) { ImGui::TableSetColumnIndex(1); - ImGui::TextUnformatted(logcat_entry->user->data(), &logcat_entry->user->data()[logcat_entry->user->size()]); + ImGui::TextUnformatted(*logcat_entry->user); } ImGui::TableSetColumnIndex(2); ImGui::Text("%zu", logcat_entry->pid); ImGui::TableSetColumnIndex(3); ImGui::Text("%zu", logcat_entry->tid); ImGui::TableSetColumnIndex(4); ImGui::TextUnformatted(buffer_to(logcat_entry->buffer)); ImGui::TableSetColumnIndex(5); ImGui::TextUnformatted(priority_to(logcat_entry->priority)); - ImGui::TableSetColumnIndex(6); ImGui::TextUnformatted(logcat_entry->tag.data(), &logcat_entry->tag.data()[logcat_entry->tag.size()]); - ImGui::TableSetColumnIndex(7); ImGui::TextUnformatted(logcat_entry->message.data(), &logcat_entry->message.data()[logcat_entry->message.size()]); + ImGui::TableSetColumnIndex(6); ImGui::TextUnformatted(logcat_entry->tag); + ImGui::TableSetColumnIndex(7); ImGui::TextUnformatted(logcat_entry->message); } } clipper.End(); @@ -77,17 +78,15 @@ void main_window(bool latest_log_entries_read, ImFont* monospace_font, } ImGui::SameLine(); + bool open_logs; 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)); + open_logs = ImGui::RedButton("Logs"); + } else { + open_logs = ImGui::Button("Logs"); } - if (ImGui::Button("Logs")) { + if (open_logs) { *show_logs_window = true; } - if (!latest_log_entries_read) { - ImGui::PopStyleColor(3); - } ImGui::Separator(); // copied from imgui/imgui_demo.cpp: [SECTION] Example App: Debug Console / ShowExampleAppConsole()