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

@@ -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;