Add more helpers

This commit is contained in:
blankie 2023-01-29 17:08:27 +07:00
parent 75d62a0031
commit 3f696c0076
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 33 additions and 11 deletions

View File

@ -1,6 +1,7 @@
#include <iomanip>
#include <sstream>
#include <system_error>
#include <imgui.h>
#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;
}

6
misc.h
View File

@ -1,8 +1,14 @@
#pragma once
#include <imgui.h>
#include <string>
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

View File

@ -1,6 +1,7 @@
#include <ctime>
#include <imgui.h>
#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();

View File

@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include "../misc.h"
#include "../logcat_entry.h"
#include "main.h"
@ -34,14 +35,14 @@ static inline void render_table(ImFont* monospace_font, std::vector<LogcatEntry>
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()