1
0
mirror of synced 2024-12-16 01:31:16 +01:00
ImHex/plugins/builtin/source/content/tools/byte_swapper.cpp
iTrooz 39252dfe48
refactor: Move custom ImGui functions to ImGuiExt namespace (#1427)
Co-authored-by: Nik <werwolv98@gmail.com>
2023-11-16 22:24:06 +01:00

38 lines
1.2 KiB
C++

#include <hex/api/localization.hpp>
#include <hex/ui/view.hpp>
#include <algorithm>
#include <content/tools_entries.hpp>
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
namespace hex::plugin::builtin {
namespace impl {
void drawByteSwapper() {
static std::string input, buffer, output;
if (ImGuiExt::InputTextIcon("hex.builtin.tools.input"_lang, ICON_VS_SYMBOL_NUMERIC, input, ImGuiInputTextFlags_CharsHexadecimal)) {
auto nextAlignedSize = std::max<size_t>(2, std::bit_ceil(input.size()));
buffer.clear();
buffer.resize(nextAlignedSize - input.size(), '0');
buffer += input;
output.clear();
for (u32 i = 0; i < buffer.size(); i += 2) {
output += buffer[buffer.size() - i - 2];
output += buffer[buffer.size() - i - 1];
}
}
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().DisabledAlpha);
ImGuiExt::InputTextIcon("hex.builtin.tools.output"_lang, ICON_VS_SYMBOL_NUMERIC, output, ImGuiInputTextFlags_ReadOnly);
ImGui::PopStyleVar();
}
}
}