7#include <unordered_map>
10#include "absl/strings/str_format.h"
14#include "imgui/imgui.h"
15#include "imgui/misc/cpp/imgui_stdlib.h"
23 std::string result = absl::StrFormat(
"0x%02X",
byte);
26 std::string result = absl::StrFormat(
"%02X",
byte);
30 std::string result = absl::StrFormat(
"0x%04X", word);
34 std::string result = absl::StrFormat(
"0x%06X", dword);
38 std::string result = absl::StrFormat(
"0x%08X", qword);
43 const std::string& to) {
44 size_t start = str.find(from);
45 if (start == std::string::npos)
return false;
47 str.replace(start, from.length(), to);
52 std::ifstream file(filename);
53 if (!file.is_open()) {
55 std::ofstream create_file(filename);
56 if (!create_file.is_open()) {
61 if (!file.is_open()) {
68 while (std::getline(file, line)) {
69 std::istringstream iss(line);
70 std::string type, key, value;
71 if (std::getline(iss, type,
',') && std::getline(iss, key,
',') &&
72 std::getline(iss, value)) {
85 if (!file.is_open()) {
88 for (
const auto& type_pair :
labels_) {
89 for (
const auto& label_pair : type_pair.second) {
90 file << type_pair.first <<
"," << label_pair.first <<
","
91 << label_pair.second << std::endl;
100 ImGui::Text(
"No labels loaded.");
104 if (ImGui::Begin(
"Resource Labels", p_open)) {
105 for (
const auto& type_pair :
labels_) {
106 if (ImGui::TreeNode(type_pair.first.c_str())) {
107 for (
const auto& label_pair : type_pair.second) {
108 std::string label_id = type_pair.first +
"_" + label_pair.first;
109 ImGui::Text(
"%s: %s", label_pair.first.c_str(),
110 label_pair.second.c_str());
116 if (ImGui::Button(
"Update Labels")) {
118 ImGui::Text(
"Labels updated successfully!");
120 ImGui::Text(
"Failed to update labels.");
128 const std::string& key,
129 const std::string& newValue) {
134 bool selected,
const std::string& type,
const std::string& key,
135 const std::string& defaultValue) {
137 ImGui::Selectable(label.c_str(), selected,
138 ImGuiSelectableFlags_AllowDoubleClick);
139 std::string label_id = type +
"_" + key;
140 if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
141 ImGui::OpenPopup(label_id.c_str());
144 if (ImGui::BeginPopupContextItem(label_id.c_str())) {
145 std::string* new_label = &
labels_[type][key];
146 if (ImGui::InputText(
"##Label", new_label,
147 ImGuiInputTextFlags_EnterReturnsTrue)) {
148 labels_[type][key] = *new_label;
151 ImGui::CloseCurrentPopup();
158 const std::string& key) {
163 const std::string& type,
const std::string& key,
164 const std::string& defaultValue) {
166 labels_[type] = std::unordered_map<std::string, std::string>();
169 labels_[type][key] = defaultValue;
std::string UppercaseHexLongLong(uint64_t qword)
bool StringReplace(std::string &str, const std::string &from, const std::string &to)
std::string UppercaseHexWord(uint16_t word)
std::string UppercaseHexLong(uint32_t dword)
std::string UppercaseHexByte(uint8_t byte, bool leading)
std::string GetLabel(const std::string &type, const std::string &key)
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
void DisplayLabels(bool *p_open)
bool LoadLabels(const std::string &filename)
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)