1
0
mirror of synced 2025-01-31 12:03:46 +01:00

feat: Highlight patterns in hex editor when hovering over pattern data row

Fixes #1742
This commit is contained in:
WerWolv 2024-06-07 19:48:10 +02:00
parent 6fd3fa77ed
commit c0dde570e4
4 changed files with 24 additions and 4 deletions

View File

@ -18,6 +18,7 @@ namespace hex::plugin::builtin {
ui::PatternDrawer::TreeStyle m_treeStyle = ui::PatternDrawer::TreeStyle::Default;
PerProvider<std::unique_ptr<ui::PatternDrawer>> m_patternDrawer;
Region m_hoveredPatternRegion = Region::Invalid();
};
}

View File

@ -37,6 +37,10 @@ namespace hex::plugin::builtin {
(*m_patternDrawer)->jumpToPattern(pattern);
});
ImHexApi::HexEditor::addHoverHighlightProvider([this](const prv::Provider *, u64 address, const u8 *, size_t size) {
return m_hoveredPatternRegion.overlaps(Region { address, size });
});
m_patternDrawer.setOnCreateCallback([this](const prv::Provider *provider, auto &drawer) {
drawer = std::make_unique<ui::PatternDrawer>();
@ -45,6 +49,13 @@ namespace hex::plugin::builtin {
RequestPatternEditorSelectionChange::post(pattern->getLine(), 0);
});
drawer->setHoverCallback([this](const pl::ptrn::Pattern *pattern) {
if (pattern == nullptr)
m_hoveredPatternRegion = Region::Invalid();
else
m_hoveredPatternRegion = { pattern->getOffset(), pattern->getSize() };
});
drawer->setTreeStyle(m_treeStyle);
drawer->enableRowColoring(m_rowColoring);
drawer->enablePatternEditing(provider->isWritable());

View File

@ -32,6 +32,7 @@ namespace hex::ui {
void setTreeStyle(TreeStyle style) { m_treeStyle = style; }
void setSelectionCallback(std::function<void(const pl::ptrn::Pattern *)> callback) { m_selectionCallback = std::move(callback); }
void setHoverCallback(std::function<void(const pl::ptrn::Pattern *)> callback) { m_hoverCallback = std::move(callback); }
void enableRowColoring(bool enabled) { m_rowColoring = enabled; }
void enablePatternEditing(bool enabled) { m_editingEnabled = enabled; }
void reset();
@ -126,6 +127,7 @@ namespace hex::ui {
TaskHolder m_favoritesUpdateTask;
std::function<void(const pl::ptrn::Pattern *)> m_selectionCallback = [](const pl::ptrn::Pattern *) { };
std::function<void(const pl::ptrn::Pattern *)> m_hoverCallback = [](const pl::ptrn::Pattern *) { };
pl::gen::fmt::FormatterArray m_formatters;
};

View File

@ -433,10 +433,14 @@ namespace hex::ui {
}
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && m_editingEnabled) {
m_editingPattern = &pattern;
m_editingPatternOffset = pattern.getOffset();
AchievementManager::unlockAchievement("hex.builtin.achievement.patterns", "hex.builtin.achievement.patterns.modify_data.name");
if (ImGui::IsItemHovered()) {
m_hoverCallback(&pattern);
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && m_editingEnabled) {
m_editingPattern = &pattern;
m_editingPatternOffset = pattern.getOffset();
AchievementManager::unlockAchievement("hex.builtin.achievement.patterns", "hex.builtin.achievement.patterns.modify_data.name");
}
}
ImGui::SameLine(0, 0);
@ -1114,6 +1118,8 @@ namespace hex::ui {
void PatternDrawer::draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, const pl::PatternLanguage *runtime, float height) {
std::scoped_lock lock(s_resetDrawMutex);
m_hoverCallback(nullptr);
const auto treeStyleButton = [this](auto icon, TreeStyle style, const char *tooltip) {
bool pushed = false;