logmeow/misc.cpp

50 lines
1.3 KiB
C++
Raw Normal View History

2023-01-16 04:05:25 +00:00
#include <iomanip>
#include <sstream>
2023-01-16 08:41:26 +00:00
#include <system_error>
2023-01-29 10:08:27 +00:00
#include <imgui.h>
2023-01-16 04:05:25 +00:00
#include "misc.h"
std::string quote(const std::string& str) {
std::stringstream ss;
ss << std::quoted(str);
return ss.str();
}
2023-01-16 08:41:26 +00:00
2023-01-17 15:35:08 +00:00
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);
2023-01-16 08:41:26 +00:00
}
2023-01-17 15:35:08 +00:00
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));
2023-01-16 08:41:26 +00:00
}
2023-01-17 15:35:08 +00:00
void throw_system_error(const char* what) {
throw_system_error(errno, what);
2023-01-16 08:41:26 +00:00
}
2023-01-17 15:35:08 +00:00
void throw_system_error(std::string what) {
throw_system_error(errno, std::move(what));
2023-01-16 08:41:26 +00:00
}
2023-01-29 10:08:27 +00:00
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;
}