mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
fix: Many format string warnings on MacOS and some Linux distros
This commit is contained in:
@@ -244,7 +244,7 @@ namespace hex::plugin::builtin {
|
||||
void drawNode() override {
|
||||
ImGui::PushItemWidth(150);
|
||||
if (this->m_value.has_value())
|
||||
ImGui::Text("0x%llx", this->m_value.value());
|
||||
ImGui::TextFormatted("0x{0:X}", this->m_value.value());
|
||||
else
|
||||
ImGui::TextUnformatted("???");
|
||||
ImGui::PopItemWidth();
|
||||
@@ -270,7 +270,7 @@ namespace hex::plugin::builtin {
|
||||
void drawNode() override {
|
||||
ImGui::PushItemWidth(150);
|
||||
if (this->m_value.has_value())
|
||||
ImGui::Text("%f", this->m_value.value());
|
||||
ImGui::TextFormatted("{0}", this->m_value.value());
|
||||
else
|
||||
ImGui::TextUnformatted("???");
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
@@ -68,18 +68,18 @@ namespace hex::plugin::builtin {
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%02d", i + 32 * tablePart);
|
||||
ImGui::TextFormatted("{0:03d}", i + 32 * tablePart);
|
||||
|
||||
if (asciiTableShowOctal) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0o%02o", i + 32 * tablePart);
|
||||
ImGui::TextFormatted("0o{0:03o}", i + 32 * tablePart);
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%02x", i + 32 * tablePart);
|
||||
ImGui::TextFormatted("0x{0:02X}", i + 32 * tablePart);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", hex::makePrintable(i + 32 * tablePart).c_str());
|
||||
ImGui::TextFormatted("{0}", hex::makePrintable(i + 32 * tablePart));
|
||||
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, ((rowCount % 2) == 0) ? 0xFF101010 : 0xFF303030);
|
||||
|
||||
@@ -295,16 +295,16 @@ namespace hex::plugin::builtin {
|
||||
|
||||
switch (mathDisplayType) {
|
||||
case MathDisplayType::Standard:
|
||||
ImGui::Text("%.3Lf", mathHistory[(mathHistory.size() - 1) - i]);
|
||||
ImGui::TextFormatted("{0:.3Lf}", mathHistory[(mathHistory.size() - 1) - i]);
|
||||
break;
|
||||
case MathDisplayType::Scientific:
|
||||
ImGui::Text("%.6Le", mathHistory[(mathHistory.size() - 1) - i]);
|
||||
ImGui::TextFormatted("{0:.6Le}", mathHistory[(mathHistory.size() - 1) - i]);
|
||||
break;
|
||||
case MathDisplayType::Engineering:
|
||||
ImGui::Text("%s", hex::toEngineeringString(mathHistory[(mathHistory.size() - 1) - i]).c_str());
|
||||
ImGui::TextFormatted("{0}", hex::toEngineeringString(mathHistory[(mathHistory.size() - 1) - i]).c_str());
|
||||
break;
|
||||
case MathDisplayType::Programmer:
|
||||
ImGui::Text("0x%llX (%llu)",
|
||||
ImGui::TextFormatted("0x{0:X} ({1})",
|
||||
u64(mathHistory[(mathHistory.size() - 1) - i]),
|
||||
u64(mathHistory[(mathHistory.size() - 1) - i]));
|
||||
break;
|
||||
@@ -335,16 +335,16 @@ namespace hex::plugin::builtin {
|
||||
ImGui::TableNextColumn();
|
||||
switch (mathDisplayType) {
|
||||
case MathDisplayType::Standard:
|
||||
ImGui::Text("%.3Lf", value);
|
||||
ImGui::TextFormatted("{0:.3Lf}", value);
|
||||
break;
|
||||
case MathDisplayType::Scientific:
|
||||
ImGui::Text("%.6Le", value);
|
||||
ImGui::TextFormatted("{0:.6Le}", value);
|
||||
break;
|
||||
case MathDisplayType::Engineering:
|
||||
ImGui::Text("%s", hex::toEngineeringString(value).c_str());
|
||||
ImGui::TextFormatted("{}", hex::toEngineeringString(value));
|
||||
break;
|
||||
case MathDisplayType::Programmer:
|
||||
ImGui::Text("0x%llX (%llu)", u64(value), u64(value));
|
||||
ImGui::TextFormatted("0x{0:X} ({1})", u64(value), u64(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <codicons_font.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <imgui_imhex_extensions.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace hex::plugin::builtin {
|
||||
framerate = 1.0F / ImGui::GetIO().DeltaTime;
|
||||
}
|
||||
|
||||
ImGui::TextUnformatted(hex::format("FPS {0:2}.{1:02}", u32(framerate), u32(framerate * 100) % 100).c_str());
|
||||
ImGui::TextFormatted("FPS {0:2}.{1:02}", u32(framerate), u32(framerate * 100) % 100);
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace hex::plugin::builtin {
|
||||
if (ImGui::CollapsingHeader((std::string(name.data()) + "###bookmark").c_str())) {
|
||||
ImGui::TextUnformatted("hex.builtin.view.bookmarks.title.info"_lang);
|
||||
ImGui::Separator();
|
||||
ImGui::TextUnformatted(hex::format("hex.builtin.view.bookmarks.address"_lang, region.address, region.address + region.size - 1, region.size).c_str());
|
||||
ImGui::TextFormatted("hex.builtin.view.bookmarks.address"_lang, region.address, region.address + region.size - 1, region.size);
|
||||
|
||||
if (ImGui::BeginChild("hexData", ImVec2(0, ImGui::GetTextLineHeight() * 8), true)) {
|
||||
size_t offset = region.address % 0x10;
|
||||
@@ -105,7 +105,7 @@ namespace hex::plugin::builtin {
|
||||
if (byte < offset)
|
||||
ImGui::TextUnformatted(" ");
|
||||
else
|
||||
ImGui::Text("%02X", bytes[byte]);
|
||||
ImGui::TextFormatted("{0:02X}", bytes[byte]);
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::NewLine();
|
||||
@@ -119,7 +119,7 @@ namespace hex::plugin::builtin {
|
||||
ImHexApi::Provider::get()->read(region.address + i, bytes.data(), byteCount);
|
||||
|
||||
for (size_t byte = 0; byte < byteCount; byte++) {
|
||||
ImGui::Text("%02X", bytes[byte]);
|
||||
ImGui::TextFormatted("{0:02X}", bytes[byte]);
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::NewLine();
|
||||
|
||||
@@ -136,13 +136,13 @@ namespace hex::plugin::builtin {
|
||||
auto &constant = this->m_constants[this->m_filterIndices[i]];
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", constant.category.c_str());
|
||||
ImGui::TextUnformatted(constant.category.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", constant.name.c_str());
|
||||
ImGui::TextUnformatted(constant.name.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", constant.description.c_str());
|
||||
ImGui::TextUnformatted(constant.description.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", constant.value.c_str());
|
||||
ImGui::TextUnformatted(constant.value.c_str());
|
||||
}
|
||||
}
|
||||
clipper.End();
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
auto startY = ImGui::GetCursorPosY();
|
||||
|
||||
ImGui::TextUnformatted(hex::format(this->m_upperCaseHex ? "{:0{}X}:" : "{:0{}x}:", row * this->m_columnCount, addressDigitCount).c_str());
|
||||
ImGui::TextFormatted(this->m_upperCaseHex ? "{:0{}X}:" : "{:0{}x}:", row * this->m_columnCount, addressDigitCount);
|
||||
ImGui::SetCursorPosY(startY);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
@@ -200,7 +200,7 @@ namespace hex::plugin::builtin {
|
||||
auto glyphWidth = ImGui::CalcTextSize("0").x + 1;
|
||||
for (u8 i = 0; i < 2; i++) {
|
||||
for (u8 col = 0; col < this->m_columnCount; col++) {
|
||||
ImGui::TextUnformatted(hex::format(this->m_upperCaseHex ? "{:02X}" : "{:02x}", col).c_str());
|
||||
ImGui::TextFormatted(this->m_upperCaseHex ? "{:02X}" : "{:02x}", col);
|
||||
ImGui::SameLine(0.0F, col % 8 == 7 ? glyphWidth * 1.5F : glyphWidth * 0.75F);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
#include <imgui_imhex_extensions.h>
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
@@ -295,13 +293,13 @@ namespace hex::plugin::builtin {
|
||||
EventManager::post<RequestSelectionChange>(Region { this->m_disassembly[i].offset, this->m_disassembly[i].size });
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("0x%llx", this->m_disassembly[i].address);
|
||||
ImGui::TextFormatted("0x{0:X}", this->m_disassembly[i].address);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%llx", this->m_disassembly[i].offset);
|
||||
ImGui::TextFormatted("0x{0:X}", this->m_disassembly[i].offset);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(this->m_disassembly[i].bytes.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "%s", this->m_disassembly[i].mnemonic.c_str());
|
||||
ImGui::TextFormattedColored(ImColor(0xFFD69C56), "{}", this->m_disassembly[i].mnemonic);
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(this->m_disassembly[i].operators.c_str());
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "content/views/view_help.hpp"
|
||||
#include <hex/helpers/paths.hpp>
|
||||
|
||||
#include <imgui_imhex_extensions.h>
|
||||
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
@@ -21,7 +19,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewHelp::drawAboutMainPage() {
|
||||
ImGui::Text("ImHex Hex Editor v%s by WerWolv - " ICON_FA_CODE_BRANCH, IMHEX_VERSION);
|
||||
ImGui::TextFormatted("ImHex Hex Editor v{} by WerWolv - " ICON_FA_CODE_BRANCH, IMHEX_VERSION);
|
||||
|
||||
#if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH)
|
||||
ImGui::SameLine();
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace hex::plugin::builtin {
|
||||
if (provider->getPageCount() > 1) {
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::TextUnformatted(hex::format("hex.builtin.view.hexeditor.page"_lang, provider->getCurrentPage() + 1, provider->getPageCount()).c_str());
|
||||
ImGui::TextFormatted("hex.builtin.view.hexeditor.page"_lang, provider->getCurrentPage() + 1, provider->getPageCount());
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
#include <hex/helpers/magic.hpp>
|
||||
|
||||
#include <imgui_imhex_extensions.h>
|
||||
#include <implot.h>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@@ -58,15 +58,15 @@ namespace hex::plugin::builtin {
|
||||
this->m_selectedPatch = address;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("0x%08lX", address);
|
||||
ImGui::TextFormatted("0x{0:08X}", address);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
u8 previousValue = 0x00;
|
||||
provider->readRaw(address, &previousValue, sizeof(u8));
|
||||
ImGui::Text("0x%02X", previousValue);
|
||||
ImGui::TextFormatted("0x{0:02X}", previousValue);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%02X", patch);
|
||||
ImGui::TextFormatted("0x{0:02X}", patch);
|
||||
index += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
#include <hex/helpers/magic.hpp>
|
||||
#include <hex/helpers/literals.hpp>
|
||||
|
||||
#include <imgui_imhex_extensions.h>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
@@ -291,11 +289,10 @@ namespace hex::plugin::builtin {
|
||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::TextUnformatted(hex::format("{} / {}",
|
||||
this->m_evaluatorRuntime->getCreatedPatternCount(),
|
||||
this->m_evaluatorRuntime->getMaximumPatternCount()
|
||||
).c_str()
|
||||
);
|
||||
ImGui::TextFormatted("{} / {}",
|
||||
this->m_evaluatorRuntime->getCreatedPatternCount(),
|
||||
this->m_evaluatorRuntime->getMaximumPatternCount()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -540,7 +537,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::Text("%s", static_cast<const char *>("hex.builtin.view.pattern_editor.accept_pattern.question"_lang));
|
||||
ImGui::TextUnformatted("hex.builtin.view.pattern_editor.accept_pattern.question"_lang);
|
||||
|
||||
confirmButtons("hex.common.yes"_lang, "hex.common.no"_lang, [this]{
|
||||
this->loadPatternFile(this->m_possiblePatternFiles[this->m_selectedPatternFile].string());
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <regex>
|
||||
|
||||
#include <llvm/Demangle/Demangle.h>
|
||||
#include <imgui_imhex_extensions.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
else if (this->m_foundStrings.size() > 0) {
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(hex::format("hex.builtin.view.strings.results"_lang, this->m_filterIndices.size()).c_str());
|
||||
ImGui::TextFormatted("hex.builtin.view.strings.results"_lang, this->m_filterIndices.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -211,12 +211,12 @@ namespace hex::plugin::builtin {
|
||||
createStringContextMenu(foundString);
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("0x%08lx : 0x%08lx", foundString.offset, foundString.offset + foundString.size);
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", foundString.offset, foundString.offset + foundString.size);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04lx", foundString.size);
|
||||
ImGui::TextFormatted("0x{0:04X}", foundString.size);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Text("%s", string.c_str());
|
||||
ImGui::TextUnformatted(string.c_str());
|
||||
}
|
||||
}
|
||||
clipper.End();
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
|
||||
#include <imgui_imhex_extensions.h>
|
||||
#include <hex/helpers/paths.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
@@ -98,9 +97,9 @@ namespace hex::plugin::builtin {
|
||||
|
||||
if (!wholeDataMatch) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%llX : 0x%llX", address, address + size - 1);
|
||||
ImGui::TextFormatted("0x{0:X} : 0x{1:X}", address, address + size - 1);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%lX", size);
|
||||
ImGui::TextFormatted("0x{0:X}", size);
|
||||
} else {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F), "%s", static_cast<const char*>("hex.builtin.view.yara.whole_data"_lang));
|
||||
|
||||
@@ -9,7 +9,7 @@ public:
|
||||
|
||||
void drawContent() override {
|
||||
if (ImGui::Begin("Example")) {
|
||||
ImGui::Text("Custom plugin window");
|
||||
ImGui::TextUnformatted("Custom plugin window");
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -134,6 +134,8 @@ set(LIBIMHEX_SOURCES
|
||||
|
||||
source/providers/provider.cpp
|
||||
|
||||
source/ui/imgui_imhex_extensions.cpp
|
||||
|
||||
source/views/view.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -268,27 +268,27 @@ namespace hex::pl {
|
||||
}
|
||||
this->drawCommentTooltip();
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("%s", this->getDisplayName().c_str());
|
||||
ImGui::TextUnformatted(this->getDisplayName().c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFF9BC64D), "%s", this->getFormattedName().c_str());
|
||||
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName());
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (!this->m_formatterFunction.has_value())
|
||||
ImGui::Text("%s", value.c_str());
|
||||
ImGui::TextUnformatted(value.c_str());
|
||||
else {
|
||||
auto result = this->m_formatterFunction->func(this->getEvaluator(), { literal });
|
||||
|
||||
if (result.has_value()) {
|
||||
if (auto displayValue = std::get_if<std::string>(&result.value()); displayValue != nullptr)
|
||||
ImGui::Text("%s", displayValue->c_str());
|
||||
ImGui::TextUnformatted(displayValue->c_str());
|
||||
} else {
|
||||
ImGui::Text("???");
|
||||
ImGui::TextUnformatted("???");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,13 +372,13 @@ namespace hex::pl {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFF9BC64D), "%s", this->getFormattedName().c_str());
|
||||
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("*(0x%llX)", data);
|
||||
ImGui::TextFormatted("*(0x{0})", data);
|
||||
|
||||
if (open) {
|
||||
this->m_pointedAt->createEntry(provider);
|
||||
@@ -769,21 +769,21 @@ namespace hex::pl {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFF9BC64D), "%s", this->m_entries[0]->getTypeName().c_str());
|
||||
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{0}", this->m_entries[0]->getTypeName());
|
||||
ImGui::SameLine(0, 0);
|
||||
|
||||
ImGui::TextUnformatted("[");
|
||||
ImGui::SameLine(0, 0);
|
||||
ImGui::TextColored(ImColor(0xFF00FF00), "%llu", this->m_entries.size());
|
||||
ImGui::TextFormattedColored(ImColor(0xFF00FF00), "{0}", this->m_entries.size());
|
||||
ImGui::SameLine(0, 0);
|
||||
ImGui::TextUnformatted("]");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", "{ ... }");
|
||||
ImGui::TextUnformatted("{ ... }");
|
||||
}
|
||||
|
||||
if (open) {
|
||||
@@ -889,21 +889,21 @@ namespace hex::pl {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFF9BC64D), "%s", this->m_template->getTypeName().c_str());
|
||||
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{0}", this->m_template->getTypeName().c_str());
|
||||
ImGui::SameLine(0, 0);
|
||||
|
||||
ImGui::TextUnformatted("[");
|
||||
ImGui::SameLine(0, 0);
|
||||
ImGui::TextColored(ImColor(0xFF00FF00), "%llu", this->m_entryCount);
|
||||
ImGui::TextFormattedColored(ImColor(0xFF00FF00), "{0}", this->m_entryCount);
|
||||
ImGui::SameLine(0, 0);
|
||||
ImGui::TextUnformatted("]");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", "{ ... }");
|
||||
ImGui::TextUnformatted("{ ... }");
|
||||
}
|
||||
|
||||
if (open) {
|
||||
@@ -1035,13 +1035,13 @@ namespace hex::pl {
|
||||
this->drawCommentTooltip();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1));
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "struct"); ImGui::SameLine(); ImGui::Text("%s", this->getTypeName().c_str());
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "struct"); ImGui::SameLine(); ImGui::TextUnformatted(this->getTypeName().c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", "{ ... }");
|
||||
ImGui::TextUnformatted("{ ... }");
|
||||
}
|
||||
|
||||
if (open) {
|
||||
@@ -1174,14 +1174,14 @@ namespace hex::pl {
|
||||
this->drawCommentTooltip();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), std::max(this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1), u64(0)));
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), std::max(this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1), u64(0)));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "union"); ImGui::SameLine(); ImGui::Text("%s", PatternData::getTypeName().c_str());
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "union"); ImGui::SameLine(); ImGui::TextUnformatted(PatternData::getTypeName().c_str());
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", "{ ... }");
|
||||
ImGui::TextUnformatted("{ ... }");
|
||||
}
|
||||
|
||||
if (open) {
|
||||
@@ -1319,17 +1319,17 @@ namespace hex::pl {
|
||||
EventManager::post<RequestSelectionChange>(Region { this->getOffset(), this->getSize() });
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("%s", this->getDisplayName().c_str());
|
||||
ImGui::TextUnformatted(this->getDisplayName().c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "enum"); ImGui::SameLine(); ImGui::Text("%s", PatternData::getTypeName().c_str());
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "enum"); ImGui::SameLine(); ImGui::TextUnformatted(PatternData::getTypeName().c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", hex::format("{} (0x{:0{}X})", valueString.c_str(), value, this->getSize() * 2).c_str());
|
||||
ImGui::TextFormatted("{} (0x{:0{}X})", valueString.c_str(), value, this->getSize() * 2);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getFormattedName() const override {
|
||||
@@ -1385,19 +1385,19 @@ namespace hex::pl {
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", this->getDisplayName().c_str());
|
||||
ImGui::TextUnformatted(this->getDisplayName().c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
|
||||
ImGui::TableNextColumn();
|
||||
if (this->m_bitSize == 1)
|
||||
ImGui::Text("0x%08llX bit %u", this->getOffset() + this->m_bitOffset / 8, (this->m_bitOffset + (this->m_bitSize - 1)) % 8);
|
||||
ImGui::TextFormatted("0x{0:08X} bit {1}", this->getOffset() + this->m_bitOffset / 8, (this->m_bitOffset + (this->m_bitSize - 1)) % 8);
|
||||
else
|
||||
ImGui::Text("0x%08llX bits %u - %u", this->getOffset() + this->m_bitOffset / 8, this->m_bitOffset % 8, this->m_bitOffset % 8 + (this->m_bitSize - 1) % 8);
|
||||
ImGui::TextFormatted("0x{0:08X} bits {1} - {2}", this->getOffset() + this->m_bitOffset / 8, this->m_bitOffset % 8, this->m_bitOffset % 8 + (this->m_bitSize - 1) % 8);
|
||||
ImGui::TableNextColumn();
|
||||
if (this->m_bitSize == 1)
|
||||
ImGui::Text("%u bit", this->m_bitSize);
|
||||
ImGui::TextFormatted("{0} bit", this->m_bitSize);
|
||||
else
|
||||
ImGui::Text("%u bits", this->m_bitSize);
|
||||
ImGui::TextFormatted("{0} bits", this->m_bitSize);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFF9BC64D), "bits");
|
||||
ImGui::TableNextColumn();
|
||||
@@ -1405,7 +1405,7 @@ namespace hex::pl {
|
||||
u8 numBytes = (this->m_bitSize / 8) + 1;
|
||||
|
||||
u64 extractedValue = hex::extract(this->m_bitOffset + (this->m_bitSize - 1), this->m_bitOffset, value);
|
||||
ImGui::Text("%llu (0x%llX)", extractedValue, extractedValue);
|
||||
ImGui::TextFormatted("{0} (0x{1:X})", extractedValue, extractedValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1470,11 +1470,11 @@ namespace hex::pl {
|
||||
this->drawCommentTooltip();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%08llX : 0x%08llX", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("0x%04llX", this->getSize());
|
||||
ImGui::TextFormatted("0x{0:04X}", this->getSize());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "bitfield"); ImGui::SameLine(); ImGui::Text("%s", PatternData::getTypeName().c_str());
|
||||
ImGui::TextColored(ImColor(0xFFD69C56), "bitfield"); ImGui::SameLine(); ImGui::TextUnformatted(PatternData::getTypeName().c_str());
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
std::string valueString = "{ ";
|
||||
|
||||
100
plugins/libimhex/include/hex/ui/imgui_imhex_extensions.h
Normal file
100
plugins/libimhex/include/hex/ui/imgui_imhex_extensions.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
enum ImGuiCustomCol {
|
||||
ImGuiCustomCol_DescButton,
|
||||
ImGuiCustomCol_DescButtonHovered,
|
||||
ImGuiCustomCol_DescButtonActive,
|
||||
|
||||
ImGuiCustomCol_ToolbarGray,
|
||||
ImGuiCustomCol_ToolbarRed,
|
||||
ImGuiCustomCol_ToolbarYellow,
|
||||
ImGuiCustomCol_ToolbarGreen,
|
||||
ImGuiCustomCol_ToolbarBlue,
|
||||
ImGuiCustomCol_ToolbarPurple,
|
||||
ImGuiCustomCol_ToolbarBrown,
|
||||
|
||||
ImGuiCustomCol_Highlight,
|
||||
|
||||
ImGuiCustomCol_COUNT
|
||||
};
|
||||
|
||||
namespace ImGui {
|
||||
|
||||
struct Texture {
|
||||
ImTextureID textureId;
|
||||
int width, height;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid() const noexcept {
|
||||
return this->textureId != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr operator ImTextureID() {
|
||||
return this->textureId;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
auto size() const noexcept {
|
||||
return ImVec2(this->width, this->height);
|
||||
}
|
||||
};
|
||||
|
||||
int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data);
|
||||
|
||||
bool IconHyperlink(const char *icon, const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
||||
bool Hyperlink(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
||||
bool BulletHyperlink(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
||||
bool DescriptionButton(const char* label, const char* description, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
||||
|
||||
void UnderlinedText(const char* label, ImColor color = ImGui::GetStyleColorVec4(ImGuiCol_Text), const ImVec2& size_arg = ImVec2(0, 0));
|
||||
|
||||
void Disabled(const std::function<void()> &widgets, bool disabled);
|
||||
void TextSpinner(const char* label);
|
||||
|
||||
void Header(const char *label, bool firstEntry = false);
|
||||
void HeaderColored(const char *label, ImColor color, bool firstEntry);
|
||||
|
||||
void InfoTooltip(const char *text);
|
||||
|
||||
bool TitleBarButton(const char* label, ImVec2 size_arg);
|
||||
bool ToolBarButton(const char* symbol, ImVec4 color);
|
||||
bool IconButton(const char* symbol, ImVec4 color, ImVec2 size_arg = ImVec2(0, 0));
|
||||
|
||||
inline bool HasSecondPassed() {
|
||||
return static_cast<ImU32>(ImGui::GetTime() * 100) % 100 <= static_cast<ImU32>(ImGui::GetIO().DeltaTime * 100);
|
||||
}
|
||||
|
||||
Texture LoadImageFromPath(const char *path);
|
||||
Texture LoadImageFromMemory(const ImU8 *buffer, int size);
|
||||
void UnloadImage(Texture &texture);
|
||||
|
||||
void OpenPopupInWindow(const char *window_name, const char *popup_name);
|
||||
|
||||
struct ImHexCustomData {
|
||||
ImVec4 Colors[ImGuiCustomCol_COUNT];
|
||||
};
|
||||
|
||||
ImU32 GetCustomColorU32(ImGuiCustomCol idx, float alpha_mul = 1.0F);
|
||||
ImVec4 GetCustomColorVec4(ImGuiCustomCol idx, float alpha_mul = 1.0F);
|
||||
|
||||
void StyleCustomColorsDark();
|
||||
void StyleCustomColorsLight();
|
||||
void StyleCustomColorsClassic();
|
||||
|
||||
void SmallProgressBar(float fraction, float yOffset = 0.0F);
|
||||
|
||||
void TextFormatted(const std::string &fmt, auto ... args) {
|
||||
ImGui::TextUnformatted(hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
||||
}
|
||||
|
||||
void TextFormattedColored(ImColor color, const std::string &fmt, auto ... args) {
|
||||
ImGui::TextColored(color, "%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <imgui.h>
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include <imgui_internal.h>
|
||||
#include <imgui_imhex_extensions.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
#include <fontawesome_font.h>
|
||||
#include <codicons_font.h>
|
||||
|
||||
518
plugins/libimhex/source/ui/imgui_imhex_extensions.cpp
Normal file
518
plugins/libimhex/source/ui/imgui_imhex_extensions.cpp
Normal file
@@ -0,0 +1,518 @@
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_freetype.h>
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include <imgui_internal.h>
|
||||
#undef IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <imgui_impl_opengl3_loader.h>
|
||||
|
||||
namespace ImGui {
|
||||
|
||||
int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data) {
|
||||
auto &mathInput = *static_cast<std::string*>(data->UserData);
|
||||
|
||||
mathInput.resize(data->BufTextLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool IconHyperlink(const char *icon, const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const ImGuiID id = window->GetID(label);
|
||||
ImVec2 label_size = CalcTextSize(icon, NULL, false);
|
||||
label_size.x += CalcTextSize(" ", NULL, false).x + CalcTextSize(label, NULL, false).x;
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
|
||||
flags |= ImGuiButtonFlags_Repeat;
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||
|
||||
// Render
|
||||
const ImU32 col = hovered ? GetColorU32(ImGuiCol_ButtonHovered) : GetColorU32(ImGuiCol_ButtonActive);
|
||||
PushStyleColor(ImGuiCol_Text, ImU32(col));
|
||||
|
||||
Text("%s %s", icon, label);
|
||||
GetWindowDrawList()->AddLine(ImVec2(pos.x, pos.y + size.y), pos + size, ImU32(col));
|
||||
PopStyleColor();
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool Hyperlink(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const ImGuiID id = window->GetID(label);
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
|
||||
flags |= ImGuiButtonFlags_Repeat;
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||
|
||||
// Render
|
||||
const ImU32 col = hovered ? GetColorU32(ImGuiCol_ButtonHovered) : GetColorU32(ImGuiCol_ButtonActive);
|
||||
PushStyleColor(ImGuiCol_Text, ImU32(col));
|
||||
TextEx(label, NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
|
||||
GetWindowDrawList()->AddLine(ImVec2(pos.x, pos.y + size.y), pos + size, ImU32(col));
|
||||
PopStyleColor();
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool BulletHyperlink(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const ImGuiID id = window->GetID(label);
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y) + ImVec2(g.FontSize + style.FramePadding.x * 2, 0.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
|
||||
flags |= ImGuiButtonFlags_Repeat;
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||
|
||||
// Render
|
||||
const ImU32 col = hovered ? GetColorU32(ImGuiCol_ButtonHovered) : GetColorU32(ImGuiCol_ButtonActive);
|
||||
PushStyleColor(ImGuiCol_Text, ImU32(col));
|
||||
RenderBullet(window->DrawList, bb.Min + ImVec2(style.FramePadding.x + g.FontSize * 0.5f, g.FontSize * 0.5f), col);
|
||||
RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x * 2, 0.0f), label, nullptr, false);
|
||||
GetWindowDrawList()->AddLine(bb.Min + ImVec2(style.FramePadding.x, size.y), pos + size, ImU32(col));
|
||||
ImGui::NewLine();
|
||||
PopStyleColor();
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool DescriptionButton(const char* label, const char* description, const ImVec2& size_arg, ImGuiButtonFlags flags) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const ImGuiID id = window->GetID(label);
|
||||
const ImVec2 text_size = CalcTextSize((std::string(label) + "\n " + std::string(description)).c_str(), NULL, true);
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrLineTextBaseOffset) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag)
|
||||
pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y;
|
||||
ImVec2 size = CalcItemSize(size_arg, text_size.x + style.FramePadding.x * 4.0f, text_size.y + style.FramePadding.y * 4.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ItemSize(size, style.FramePadding.y);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
|
||||
flags |= ImGuiButtonFlags_Repeat;
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0, 0.5));
|
||||
|
||||
// Render
|
||||
const ImU32 col = GetCustomColorU32((held && hovered) ? ImGuiCustomCol_DescButtonActive : hovered ? ImGuiCustomCol_DescButtonHovered : ImGuiCustomCol_DescButton);
|
||||
RenderNavHighlight(bb, id);
|
||||
RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
||||
PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_ButtonActive));
|
||||
RenderTextWrapped(bb.Min + style.FramePadding * 2, label, nullptr, CalcWrapWidthForPos(window->DC.CursorPos, window->DC.TextWrapPos));
|
||||
PopStyleColor();
|
||||
PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_Text));
|
||||
RenderTextClipped(bb.Min + style.FramePadding * 2 + ImVec2(style.FramePadding.x * 2, label_size.y), bb.Max - style.FramePadding, description, NULL, &text_size, style.ButtonTextAlign, &bb);
|
||||
PopStyleColor();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
// Automatically close popups
|
||||
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
|
||||
// CloseCurrentPopup();
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
void UnderlinedText(const char* label, ImColor color, const ImVec2& size_arg) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y);
|
||||
|
||||
PushStyleColor(ImGuiCol_Text, ImU32(color));
|
||||
TextEx(label, NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
|
||||
GetWindowDrawList()->AddLine(ImVec2(pos.x, pos.y + size.y), pos + size, ImU32(color));
|
||||
PopStyleColor();
|
||||
}
|
||||
|
||||
void Disabled(const std::function<void()> &widgets, bool disabled) {
|
||||
if (disabled) {
|
||||
BeginDisabled();
|
||||
widgets();
|
||||
EndDisabled();
|
||||
} else {
|
||||
widgets();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TextSpinner(const char* label) {
|
||||
ImGui::Text("[%c] %s", "|/-\\"[ImU32(ImGui::GetTime() * 20) % 4], label);
|
||||
}
|
||||
|
||||
void Header(const char *label, bool firstEntry) {
|
||||
if (!firstEntry)
|
||||
ImGui::NewLine();
|
||||
ImGui::TextUnformatted(label);
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
void HeaderColored(const char *label, ImColor color, bool firstEntry) {
|
||||
if (!firstEntry)
|
||||
ImGui::NewLine();
|
||||
ImGui::TextColored(color, "%s", label);
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
void InfoTooltip(const char *text) {
|
||||
static double lastMoveTime;
|
||||
static ImGuiID lastHoveredID;
|
||||
|
||||
double currTime = ImGui::GetTime();
|
||||
ImGuiID hoveredID = ImGui::GetHoveredID();
|
||||
|
||||
if (IsItemHovered() && (currTime - lastMoveTime) >= 0.5 && hoveredID == lastHoveredID) {
|
||||
BeginTooltip();
|
||||
TextUnformatted(text);
|
||||
EndTooltip();
|
||||
}
|
||||
|
||||
if (hoveredID != lastHoveredID) {
|
||||
lastMoveTime = currTime;
|
||||
}
|
||||
lastHoveredID = hoveredID;
|
||||
}
|
||||
|
||||
ImU32 GetCustomColorU32(ImGuiCustomCol idx, float alpha_mul) {
|
||||
auto& customData = *static_cast<ImHexCustomData*>(GImGui->IO.UserData);
|
||||
ImVec4 c = customData.Colors[idx];
|
||||
c.w *= GImGui->Style.Alpha * alpha_mul;
|
||||
return ColorConvertFloat4ToU32(c);
|
||||
}
|
||||
|
||||
ImVec4 GetCustomColorVec4(ImGuiCustomCol idx, float alpha_mul) {
|
||||
auto& customData = *static_cast<ImHexCustomData*>(GImGui->IO.UserData);
|
||||
ImVec4 c = customData.Colors[idx];
|
||||
c.w *= GImGui->Style.Alpha * alpha_mul;
|
||||
return c;
|
||||
}
|
||||
|
||||
void StyleCustomColorsDark() {
|
||||
auto &colors = static_cast<ImHexCustomData*>(GImGui->IO.UserData)->Colors;
|
||||
|
||||
colors[ImGuiCustomCol_DescButton] = ImColor(20, 20, 20);
|
||||
colors[ImGuiCustomCol_DescButtonHovered] = ImColor(40, 40, 40);
|
||||
colors[ImGuiCustomCol_DescButtonActive] = ImColor(60, 60, 60);
|
||||
|
||||
colors[ImGuiCustomCol_ToolbarGray] = ImColor(230, 230, 230);
|
||||
colors[ImGuiCustomCol_ToolbarRed] = ImColor(231, 76, 60);
|
||||
colors[ImGuiCustomCol_ToolbarYellow] = ImColor(241, 196, 15);
|
||||
colors[ImGuiCustomCol_ToolbarGreen] = ImColor(56, 139, 66);
|
||||
colors[ImGuiCustomCol_ToolbarBlue] = ImColor(6, 83, 155);
|
||||
colors[ImGuiCustomCol_ToolbarPurple] = ImColor(103, 42, 120);
|
||||
colors[ImGuiCustomCol_ToolbarBrown] = ImColor(219, 179, 119);
|
||||
|
||||
colors[ImGuiCustomCol_Highlight] = ImColor(77, 198, 155);
|
||||
}
|
||||
|
||||
void StyleCustomColorsLight() {
|
||||
auto &colors = static_cast<ImHexCustomData*>(GImGui->IO.UserData)->Colors;
|
||||
|
||||
colors[ImGuiCustomCol_DescButton] = ImColor(230, 230, 230);
|
||||
colors[ImGuiCustomCol_DescButtonHovered] = ImColor(210, 210, 210);
|
||||
colors[ImGuiCustomCol_DescButtonActive] = ImColor(190, 190, 190);
|
||||
|
||||
colors[ImGuiCustomCol_ToolbarGray] = ImColor(25, 25, 25);
|
||||
colors[ImGuiCustomCol_ToolbarRed] = ImColor(231, 76, 60);
|
||||
colors[ImGuiCustomCol_ToolbarYellow] = ImColor(241, 196, 15);
|
||||
colors[ImGuiCustomCol_ToolbarGreen] = ImColor(56, 139, 66);
|
||||
colors[ImGuiCustomCol_ToolbarBlue] = ImColor(6, 83, 155);
|
||||
colors[ImGuiCustomCol_ToolbarPurple] = ImColor(103, 42, 120);
|
||||
colors[ImGuiCustomCol_ToolbarBrown] = ImColor(219, 179, 119);
|
||||
|
||||
colors[ImGuiCustomCol_Highlight] = ImColor(41, 151, 112);
|
||||
}
|
||||
|
||||
void StyleCustomColorsClassic() {
|
||||
auto &colors = static_cast<ImHexCustomData*>(GImGui->IO.UserData)->Colors;
|
||||
|
||||
colors[ImGuiCustomCol_DescButton] = ImColor(40, 40, 80);
|
||||
colors[ImGuiCustomCol_DescButtonHovered] = ImColor(60, 60, 100);
|
||||
colors[ImGuiCustomCol_DescButtonActive] = ImColor(80, 80, 120);
|
||||
|
||||
colors[ImGuiCustomCol_ToolbarGray] = ImColor(230, 230, 230);
|
||||
colors[ImGuiCustomCol_ToolbarRed] = ImColor(231, 76, 60);
|
||||
colors[ImGuiCustomCol_ToolbarYellow] = ImColor(241, 196, 15);
|
||||
colors[ImGuiCustomCol_ToolbarGreen] = ImColor(56, 139, 66);
|
||||
colors[ImGuiCustomCol_ToolbarBlue] = ImColor(6, 83, 155);
|
||||
colors[ImGuiCustomCol_ToolbarPurple] = ImColor(103, 42, 120);
|
||||
colors[ImGuiCustomCol_ToolbarBrown] = ImColor(219, 179, 119);
|
||||
|
||||
colors[ImGuiCustomCol_Highlight] = ImColor(77, 198, 155);
|
||||
}
|
||||
|
||||
Texture LoadImageFromPath(const char *path) {
|
||||
int imageWidth = 0;
|
||||
int imageHeight = 0;
|
||||
|
||||
unsigned char* imageData = stbi_load(path, &imageWidth, &imageHeight, nullptr, 4);
|
||||
if (imageData == nullptr)
|
||||
return { nullptr, -1, -1 };
|
||||
|
||||
|
||||
GLuint texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
#if defined(GL_UNPACK_ROW_LENGTH)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
#endif
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
|
||||
stbi_image_free(imageData);
|
||||
|
||||
return { reinterpret_cast<ImTextureID>(static_cast<intptr_t>(texture)), imageWidth, imageHeight };
|
||||
}
|
||||
|
||||
Texture LoadImageFromMemory(const ImU8 *buffer, int size) {
|
||||
int imageWidth = 0;
|
||||
int imageHeight = 0;
|
||||
|
||||
|
||||
unsigned char* imageData = stbi_load_from_memory(buffer, size, &imageWidth, &imageHeight, nullptr, 4);
|
||||
if (imageData == nullptr)
|
||||
return { nullptr, -1, -1 };
|
||||
|
||||
GLuint texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
#if defined(GL_UNPACK_ROW_LENGTH)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
#endif
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
|
||||
stbi_image_free(imageData);
|
||||
|
||||
return { reinterpret_cast<ImTextureID>(static_cast<intptr_t>(texture)), imageWidth, imageHeight };
|
||||
}
|
||||
|
||||
void UnloadImage(Texture &texture) {
|
||||
if (texture.textureId == nullptr)
|
||||
return;
|
||||
|
||||
auto glTextureId = static_cast<GLuint>(reinterpret_cast<intptr_t>(texture.textureId));
|
||||
glDeleteTextures(1, &glTextureId);
|
||||
|
||||
texture = { nullptr, 0, 0 };
|
||||
}
|
||||
|
||||
void OpenPopupInWindow(const char *window_name, const char *popup_name) {
|
||||
if (ImGui::Begin(window_name)) {
|
||||
ImGui::OpenPopup(popup_name);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
bool TitleBarButton(const char* label, ImVec2 size_arg) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const ImGuiID id = window->GetID(label);
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ItemSize(size, style.FramePadding.y);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
// Render
|
||||
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
|
||||
RenderNavHighlight(bb, id);
|
||||
RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
||||
RenderTextClipped(bb.Min + style.FramePadding * ImVec2(1, 2), bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb);
|
||||
|
||||
// Automatically close popups
|
||||
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
|
||||
// CloseCurrentPopup();
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool ToolBarButton(const char* symbol, ImVec4 color) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
color.w = 1.0F;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const ImGuiID id = window->GetID(symbol);
|
||||
const ImVec2 label_size = CalcTextSize(symbol, NULL, true);
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = CalcItemSize(ImVec2(1, 1) * ImGui::GetCurrentWindow()->MenuBarHeight(), label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ItemSize(size, style.FramePadding.y);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
PushStyleColor(ImGuiCol_Text, color);
|
||||
|
||||
// Render
|
||||
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_MenuBarBg);
|
||||
RenderNavHighlight(bb, id);
|
||||
RenderFrame(bb.Min, bb.Max, col, false, style.FrameRounding);
|
||||
RenderTextClipped(bb.Min + style.FramePadding * ImVec2(1, 2), bb.Max - style.FramePadding, symbol, NULL, &label_size, style.ButtonTextAlign, &bb);
|
||||
|
||||
PopStyleColor();
|
||||
|
||||
// Automatically close popups
|
||||
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
|
||||
// CloseCurrentPopup();
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool IconButton(const char* symbol, ImVec4 color, ImVec2 size_arg) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
color.w = 1.0F;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const ImGuiID id = window->GetID(symbol);
|
||||
const ImVec2 label_size = CalcTextSize(symbol, NULL, true);
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ItemSize(size, style.FramePadding.y);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
PushStyleColor(ImGuiCol_Text, color);
|
||||
|
||||
// Render
|
||||
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
|
||||
RenderNavHighlight(bb, id);
|
||||
RenderFrame(bb.Min, bb.Max, col, false, style.FrameRounding);
|
||||
RenderTextClipped(bb.Min + style.FramePadding * ImVec2(1, 2), bb.Max - style.FramePadding, symbol, NULL, &label_size, style.ButtonTextAlign, &bb);
|
||||
|
||||
PopStyleColor();
|
||||
|
||||
// Automatically close popups
|
||||
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
|
||||
// CloseCurrentPopup();
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
void SmallProgressBar(float fraction, float yOffset) {
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos + ImVec2(0, yOffset);
|
||||
ImVec2 size = CalcItemSize(ImVec2(100, 5), 100, g.FontSize + style.FramePadding.y * 2.0f);
|
||||
ImRect bb(pos, pos + size);
|
||||
ItemSize(size, 0);
|
||||
if (!ItemAdd(bb, 0))
|
||||
return;
|
||||
|
||||
// Render
|
||||
fraction = ImSaturate(fraction);
|
||||
RenderFrame(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
|
||||
bb.Expand(ImVec2(-style.FrameBorderSize, -style.FrameBorderSize));
|
||||
const ImVec2 fill_br = ImVec2(ImLerp(bb.Min.x, bb.Max.x, fraction), bb.Max.y);
|
||||
RenderRectFilledRangeH(window->DrawList, bb, GetColorU32(ImGuiCol_PlotHistogram), 0.0f, fraction, style.FrameRounding);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <psapi.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_imhex_extensions.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
#include <fontawesome_font.h>
|
||||
|
||||
namespace hex::plugin::windows {
|
||||
@@ -71,7 +71,7 @@ namespace hex::plugin::windows {
|
||||
cpuUsage *= 100;
|
||||
}
|
||||
|
||||
ImGui::TextUnformatted(hex::format(ICON_FA_TACHOMETER_ALT " {0:2}.{1:02}", u32(cpuUsage), u32(cpuUsage * 100) % 100).c_str());
|
||||
ImGui::TextFormatted(ICON_FA_TACHOMETER_ALT " {0:2}.{1:02}", u32(cpuUsage), u32(cpuUsage * 100) % 100);
|
||||
});
|
||||
|
||||
ContentRegistry::Interface::addFooterItem([] {
|
||||
@@ -87,7 +87,7 @@ namespace hex::plugin::windows {
|
||||
auto totalMem = memInfo.ullTotalPhys;
|
||||
auto usedMem = pmc.PrivateUsage;
|
||||
|
||||
ImGui::TextUnformatted(hex::format(ICON_FA_MICROCHIP " {0} / {1}", hex::toByteString(usedMem), hex::toByteString(totalMem)).c_str());
|
||||
ImGui::TextFormatted(ICON_FA_MICROCHIP " {0} / {1}", hex::toByteString(usedMem), hex::toByteString(totalMem));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "views/view_tty_console.hpp"
|
||||
|
||||
#include <imgui_imhex_extensions.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
Reference in New Issue
Block a user