logmeow/misc.cpp

50 lines
1.3 KiB
C++

#include <iomanip>
#include <sstream>
#include <system_error>
#include <imgui.h>
#include "misc.h"
std::string quote(const std::string& str) {
std::stringstream ss;
ss << std::quoted(str);
return ss.str();
}
void throw_system_error(int err, const char* what) {
if (err == ENOMEM) {
throw std::bad_alloc();
}
throw std::system_error(err, std::generic_category(), what);
}
void throw_system_error(int err, std::string what) {
if (err == ENOMEM) {
throw std::bad_alloc();
}
throw std::system_error(err, std::generic_category(), std::move(what));
}
void throw_system_error(const char* what) {
throw_system_error(errno, 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;
}