1
0
mirror of synced 2024-12-05 12:37:57 +01:00
ImHex/plugins/builtin/include/ui/widgets.hpp
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

61 lines
2.2 KiB
C++

#pragma once
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
namespace pl::ptrn { class Pattern; }
namespace hex::prv { class Provider; }
namespace hex::plugin::builtin::ui {
enum class RegionType : int {
EntireData,
Selection,
Region
};
inline void regionSelectionPicker(Region *region, prv::Provider *provider, RegionType *type, bool showHeader = true, bool firstEntry = false) {
if (showHeader)
ImGuiExt::Header("hex.builtin.common.range"_lang, firstEntry);
if (ImGui::RadioButton("hex.builtin.common.range.entire_data"_lang, *type == RegionType::EntireData))
*type = RegionType::EntireData;
if (ImGui::RadioButton("hex.builtin.common.range.selection"_lang, *type == RegionType::Selection))
*type = RegionType::Selection;
if (ImGui::RadioButton("hex.builtin.common.region"_lang, *type == RegionType::Region))
*type = RegionType::Region;
switch (*type) {
case RegionType::EntireData:
*region = { provider->getBaseAddress(), provider->getActualSize() };
break;
case RegionType::Selection:
*region = ImHexApi::HexEditor::getSelection().value_or(
ImHexApi::HexEditor::ProviderRegion {
{ 0, 1 },
provider }
).getRegion();
break;
case RegionType::Region:
ImGui::SameLine();
const auto width = ImGui::GetContentRegionAvail().x / 2 - ImGui::CalcTextSize(" - ").x / 2 - ImGui::GetStyle().FramePadding.x * 4;
u64 start = region->getStartAddress(), end = region->getEndAddress();
ImGui::PushItemWidth(width);
ImGuiExt::InputHexadecimal("##start", &start);
ImGui::PopItemWidth();
ImGui::SameLine();
ImGui::TextUnformatted(" - ");
ImGui::SameLine();
ImGui::PushItemWidth(width);
ImGuiExt::InputHexadecimal("##end", &end);
ImGui::PopItemWidth();
*region = { start, (end - start) + 1 };
break;
}
}
}