1
0
mirror of synced 2024-09-24 03:28:24 +02:00

feat: Highlight patterns in pattern data view that are fully selected

Fixes #1741
This commit is contained in:
WerWolv 2024-06-07 19:59:11 +02:00
parent c0dde570e4
commit ea09bfe8ea
2 changed files with 19 additions and 7 deletions

View File

@ -90,7 +90,7 @@
"advanced-encoding-multi": "#F1C40FFF",
"advanced-encoding-unknown": "#E74C3CFF",
"patches": "#E74C3CFF",
"pattern-selected": "#06539BFF"
"pattern-selected": "#3683CBFF"
},
"imnodes": {
"box-selector": "#3D85E01E",

View File

@ -44,7 +44,7 @@ namespace hex::ui {
using namespace ::std::literals::string_literals;
bool isPatternSelected(u64 address, u64 size) {
bool isPatternOverlapSelected(u64 address, u64 size) {
auto currSelection = ImHexApi::HexEditor::getSelection();
if (!currSelection.has_value())
return false;
@ -52,26 +52,38 @@ namespace hex::ui {
return Region{ address, size }.overlaps(*currSelection);
}
bool isPatternFullySelected(u64 address, u64 size) {
auto currSelection = ImHexApi::HexEditor::getSelection();
if (!currSelection.has_value())
return false;
return currSelection->address == address && currSelection->size == size;
}
template<typename T>
auto highlightWhenSelected(u64 address, u64 size, const T &callback) {
constexpr static bool HasReturn = !requires(T t) { { t() } -> std::same_as<void>; };
auto selected = isPatternSelected(address, size);
const auto overlapSelected = isPatternOverlapSelected(address, size);
const auto fullySelected = isPatternFullySelected(address, size);
if (selected)
ImGui::PushStyleColor(ImGuiCol_Text, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_PatternSelected));
const u32 selectionColor = ImColor(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_PatternSelected));
if (overlapSelected)
ImGui::PushStyleColor(ImGuiCol_Text, selectionColor);
if (fullySelected)
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, (selectionColor & 0x00'FF'FF'FF) | 0x30'00'00'00);
if constexpr (HasReturn) {
auto result = callback();
if (selected)
if (overlapSelected)
ImGui::PopStyleColor();
return result;
} else {
callback();
if (selected)
if (overlapSelected)
ImGui::PopStyleColor();
}
}